La funzione funzione esegue il calcolo del pattern di controllo su di un’area dati. Il calcolo è effettuato secondo l’algoritmo indicato nel parametro Type.
Occorre passare alla funzione l’indirizzo del buffer di memoria Buf ed il numero di bytes ByteNr su cui eseguire il calcolo. Occorre anche indicare un valore di inizializzazione del calcolo Init che cambia in funzione del tipo di algoritmo di calcolo definito.
Descrizione
Buf (@BYTE) Indirizzo dell’area di memoria su cui eseguire il calcolo.
ByteNr (UDINT) Numero di bytes su cui eseguire il calcolo a partire dall’indirizzo definito in Buf.
Init (UDINT) Valore di inizializzazione del calcolo.
Type (CHECK_FRAME_TYPE) Definizione algoritmo di calcolo da eseguire (Vedi tabella).
La funzione ritorna una variabile (UDINT) con il valore di pattern calcolato.

Esempi
Come utilizzare gli esempi.
Viene calcolato il CRC di un frame Modbus RTU per il comando di lettura registri Read holding registers. Il valore del CRC calcolato è 17466
LogicLab (Ptp116, ST_SysGetCheck)
PROGRAM ST_SysGetCheck
VAR
NrOfRegs : USINT; (* Number of registers *)
RegsAddress : UINT; (* Registers address *)
CRCValue : UDINT; (* CRC value *)
Frame : ARRAY[0..9] OF USINT; (* Frame array *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysGetCheck"
// *****************************************************************************
// This program calculates the CRC of a Modbus RTU frame for the command 'Read
// holding registers'. Here is the command frame.
// +--+--+--+--+--+--+-+-+
// |Nd|03|Addr |Regs |CRC|
// +--+--+--+--+--+--+-+-+
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// CRC CALCULATION
// -------------------------------------------------------------------------
// Define the registers address and the number of registers to be read.
RegsAddress:=16#0120; // Registers address
NrOfRegs:=8; // Number of registers
// Prepare the command frame.
Frame[0]:=1; //Node address
Frame[1]:=3; //Function code (16#03)
Frame[2]:=TO_USINT(RegsAddress/256); //MSB registers address
Frame[3]:=TO_USINT(RegsAddress&255); //LSB registers address
Frame[4]:=0; //MSB number of registers to read
Frame[5]:=NrOfRegs; //LSB number of registers to read
// Calculate the frame CRC.
CRCValue:=SysGetCheck(Buf:=ADR(Frame[0]), ByteNr:=6, Init:=16#FFFF, Type:=CRC_16_MODBUS);
Frame[6]:=TO_USINT(CRCValue/256); //MSB of CRC value
Frame[7]:=TO_USINT(CRCValue&255); //LSB of CRC value
// [End of file]