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.


Creates a string out of an array of bits

Parameters:bits – A bit array


bits   = [False, True, False, True]
result = pack_bitstring(bits)

Creates bit array out of a string

Parameters:string – The modbus data packet to decode


bytes  = 'bytes to decode'
result = unpack_bitstring(bytes)

Generates a crc16 lookup table


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

Checks if the data matches the passed in CRC

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

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

Checks if the passed in data matches the LRC

  • data – The data to calculate
  • check – The LRC to validate

True if matched, False otherwise

Table Of Contents

Previous topic

transaction — Transaction Controllers for Pymodbus

This Page