User Tools

Site Tools




GetCrc variable, arrayName, byteLength

variable String variable to store results (Integer type)
arrayName Array with data(Must be a Byte array)
byteLength number of bytes to calculate CRC

GetCrc calculates a Circular Redundancy Check (CRC) when using MODBUS RTU Master Mode. GetCrc will return a 16-bit integer CRC value of the specified array, arrayName. You can set the number of bytes to use for the CRC calculation from the the array starting at 0.

 Const Device = CB280
 OpenCom 1,115200,3,80,20
 Set Modbus 1,9
 Dim A(20) As Byte
 Dim B As Integer
 UsePin 0,Out
 UsePin 9,Out
 Set Ladder On
 A(0) = 9
 A(1) = 2
 A(2) = 3
 A(3) = 0
 A(4) = 10
 A(5) = 23
 GetCrc B,A,6 ' Store in variable B the CRC for 6 bytes of array A
 Debug Hex B,Cr

NOTE: Please use byte arrays when using this function.

Go CUBLOC home

cubloc/getcrc/index.txt · Last modified: 2016/04/14 11:07 (external edit)