SysGetCheck, gets the check

List

Questa pagina fa parte del Manuale Programmazione IEC 61131-3. Vai all indice.

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.

Function
CODESYS: Non disponibile
LogicLab: eLLabXUnified12Lib

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 (16#443A).

LogicLab (Ptp116)
PROGRAM ST_SysGetCheck
VAR
    RegsAddress : UINT; (* Registers address *)
    NrOfRegs : USINT; (* Number of registers *)
    CRCValue : UDINT; (* CRC value *)
    Frame : ARRAY[0..9] OF USINT; (* Frame array *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_SysGetCheck"
// *****************************************************************************
// This program calculate CRC of a modbus RTU frame for command "Read holding
// registers". Here the command frame.
// +--+--+--+--+--+--+-+-+
// |Nd|03|Addr |Regs |CRC|
// +--+--+--+--+--+--+-+-+
// -----------------------------------------------------------------------------

    // -------------------------------------------------------------------------
    // CRC CALCULATION
    // -------------------------------------------------------------------------
    // Define the registers address and the number of registers to 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]
Was this article helpful?