This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Modbus CRC?
#4
It does work, but the byte order is flipped. You just need to swap byteh and bytel when appending CRC to the source message.
Code:
msg = string.char(0x02, 0x03, 0x00, 0xD6, 0x35, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xBC, 0x10, 0x02, 0x00, 0x52, 0xDE)

crc = crc16modbus(msg)

-- split crc into 2 bytes
byteh = bit.rshift(crc, 8)
byteh = bit.band(byteh, 0xFF)
bytel = bit.band(crc, 0xFF)

-- high=B8 low=78
alert(string.format('high=%02X low=%02X', byteh, bytel))
Reply


Messages In This Thread
Modbus CRC? - by zoltan - 25.05.2017, 11:42
RE: Modbus CRC? - by admin - 25.05.2017, 11:52
RE: Modbus CRC? - by zoltan - 25.05.2017, 13:18
RE: Modbus CRC? - by admin - 25.05.2017, 16:38
RE: Modbus CRC? - by zoltan - 25.05.2017, 17:01

Forum Jump: