modbus.crc16
modbus.crc16
Function
Calculate Modbus RTU CRC16.
Syntax
modbus.crc16(data)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| data | Bytes/Array/String | Yes | None | Bytes involved in CRC calculation, excluding frame tail CRC. |
Return value
| Type | Description |
|---|---|
| Int | CRC16 value. Low byte first when writing RTU frames. |
Code Example
value = modbus.crc16(bytes('01030000000a', 'hex')) // Output: 52677 print value
Notes
-
crc16()only returns a numerical value; when building an RTU request, please usertu_request()first to automatically write the CRC.