Public Shared Function ComputeChecksum(ByVal bytes As Byte()) As UShort
Dim crc As UShort = &HFFFFUS ' The calculation start with 0xFFFF
For i As Integer = 0 To bytes.Length - 1
Dim index As Byte = CByte(((crc) And &HFF) Xor bytes(i))
crc = CUShort((crc >> 8) Xor table(index))
Next
Return crc
End Function
This appears to work - I tested it against a few MODBUS messages to compare CRCs - But I needed to swap Hi/Lo byte order of the CRC to get it to match the message order