bit_read_message — Bit Read Modbus Messages

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

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

API Documentation

Bit Reading Request/Response messages

class pymodbus.bit_read_message.ReadBitsRequestBase(address, count)

Base class for Messages Requesting bit values

decode(data)

Decodes a request pdu

Parameters:data – The packet data to decode
encode()

Encodes a request pdu

Returns:The encoded pdu
class pymodbus.bit_read_message.ReadBitsResponseBase(values)

Base class for Messages responding to bit-reading values

decode(data)

Decodes response pdu

Parameters:data – The packet data to decode
encode()

Encodes response pdu

Returns:The encoded packet message
getBit(address)

Helper function to get the specified bit’s value

Parameters:address – The bit to query
Returns:The value of the requested bit
resetBit(address)

Helper function to set the specified bit to 0

Parameters:address – The bit to reset
setBit(address, value=1)

Helper function to set the specified bit

Parameters:
  • address – The bit to set
  • value – The value to set the bit to
class pymodbus.bit_read_message.ReadCoilsRequest(address=None, count=None)

This function code is used to read from 1 to 2000(0x7d0) contiguous status of coils in a remote device. The Request PDU specifies the starting address, ie the address of the first coil specified, and the number of coils. In the PDU Coils are addressed starting at zero. Therefore coils numbered 1-16 are addressed as 0-15.

execute(context)

Run a read coils request against a datastore

Before running the request, we make sure that the request is in the max valid range (0x001-0x7d0). Next we make sure that the request is valid against the current datastore.

Parameters:context – The datastore to request from
Returns:The initializes response message, exception message otherwise
class pymodbus.bit_read_message.ReadCoilsResponse(values=None)

The coils in the response message are packed as one coil per bit of the data field. Status is indicated as 1= ON and 0= OFF. The LSB of the first data byte contains the output addressed in the query. The other coils follow toward the high order end of this byte, and from low order to high order in subsequent bytes.

If the returned output quantity is not a multiple of eight, the remaining bits in the final data byte will be padded with zeros (toward the high order end of the byte). The Byte Count field specifies the quantity of complete bytes of data.

class pymodbus.bit_read_message.ReadDiscreteInputsRequest(address=None, count=None)

This function code is used to read from 1 to 2000(0x7d0) contiguous status of discrete inputs in a remote device. The Request PDU specifies the starting address, ie the address of the first input specified, and the number of inputs. In the PDU Discrete Inputs are addressed starting at zero. Therefore Discrete inputs numbered 1-16 are addressed as 0-15.

execute(context)

Run a read discrete input request against a datastore

Before running the request, we make sure that the request is in the max valid range (0x001-0x7d0). Next we make sure that the request is valid against the current datastore.

Parameters:context – The datastore to request from
Returns:The initializes response message, exception message otherwise
class pymodbus.bit_read_message.ReadDiscreteInputsResponse(values=None)

The discrete inputs in the response message are packed as one input per bit of the data field. Status is indicated as 1= ON; 0= OFF. The LSB of the first data byte contains the input addressed in the query. The other inputs follow toward the high order end of this byte, and from low order to high order in subsequent bytes.

If the returned input quantity is not a multiple of eight, the remaining bits in the final data byte will be padded with zeros (toward the high order end of the byte). The Byte Count field specifies the quantity of complete bytes of data.