Module author: Galen Collins <bashwork@gmail.com>
Section author: Galen Collins <bashwork@gmail.com>
A collection of utilities for packing data, unpacking data computing checksums, and decode checksums.
Creates a string out of an array of bits
Parameters: | bits – A bit array |
---|
example:
bits = [False, True, False, True]
result = pack_bitstring(bits)
Creates bit array out of a string
Parameters: | string – The modbus data packet to decode |
---|
example:
bytes = 'bytes to decode'
result = unpack_bitstring(bytes)
Generates a crc16 lookup table
Note
This will only be generated once
Computes a crc16 on the passed in string. For modbus, this is only used on the binary serial protocols (in this case RTU).
The difference between modbus’s crc16 and a normal crc16 is that modbus starts the crc value out at 0xffff.
Parameters: | data – The data to create a crc16 of |
---|---|
Returns: | The calculated CRC |
Checks if the data matches the passed in CRC
Parameters: |
|
---|---|
Returns: | True if matched, False otherwise |
Used to compute the longitudinal redundancy check against a string. This is only used on the serial ASCII modbus protocol. A full description of this implementation can be found in appendex B of the serial line modbus description.
Parameters: | data – The data to apply a lrc to |
---|---|
Returns: | The calculated LRC |
Checks if the passed in data matches the LRC
Parameters: |
|
---|---|
Returns: | True if matched, False otherwise |