Skip to main content

Module crc

Module crc 

Source
Expand description

Modbus CRC-16 and LRC checksum functions.

  • CRC-16/MODBUS: Used by Modbus RTU frames. Polynomial 0xA001 (reflected), init 0xFFFF, no final XOR.
  • LRC: Longitudinal Redundancy Check used by Modbus ASCII frames. Two’s complement of the sum of all bytes (mod 256).

Functions§

modbus_crc16
Compute the Modbus CRC-16 checksum.
modbus_lrc
Compute the Modbus LRC (Longitudinal Redundancy Check).
verify_crc16
Verify the CRC-16 of a complete Modbus RTU frame (data + 2-byte CRC).
verify_lrc
Verify the LRC of a data slice where the last byte is the LRC.