utilities — Extra Modbus Helpers

Module author: Galen Collins <bashwork@gmail.com>

Section author: Galen Collins <bashwork@gmail.com>

API Documentation

Modbus Utilities

A collection of utilities for packing data, unpacking data computing checksums, and decode checksums.

pymodbus.utilities.pack_bitstring(bits)

Creates a string out of an array of bits

Parameters:bits – A bit array

example:

bits   = [False, True, False, True]
result = pack_bitstring(bits)
pymodbus.utilities.unpack_bitstring(string)

Creates bit array out of a string

Parameters:string – The modbus data packet to decode

example:

bytes  = 'bytes to decode'
result = unpack_bitstring(bytes)
pymodbus.utilities.__generate_crc16_table()

Generates a crc16 lookup table

Note

This will only be generated once

pymodbus.utilities.computeCRC(data)

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
pymodbus.utilities.checkCRC(data, check)

Checks if the data matches the passed in CRC

Parameters:
  • data – The data to create a crc16 of
  • check – The CRC to validate
Returns:

True if matched, False otherwise

pymodbus.utilities.computeLRC(data)

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
pymodbus.utilities.checkLRC(data, check)

Checks if the passed in data matches the LRC

Parameters:
  • data – The data to calculate
  • check – The LRC to validate
Returns:

True if matched, False otherwise

Table Of Contents

Previous topic

transaction — Transaction Controllers for Pymodbus

This Page