Skip to content

Commit

Permalink
Improve docs for Read*ResponseBase and subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
camtarn authored and Andy Walker committed Dec 6, 2021
1 parent c5772b3 commit 245c21a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 9 additions & 3 deletions pymodbus/bit_read_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __str__(self):


class ReadBitsResponseBase(ModbusResponse):
''' Base class for Messages responding to bit-reading values '''
''' Base class for Messages responding to bit-reading values. The requested bits can be found in the .bits list. '''

_rtu_byte_count_pos = 2

Expand All @@ -71,6 +71,8 @@ def __init__(self, values, **kwargs):
:param values: The requested values to be returned
'''
ModbusResponse.__init__(self, **kwargs)

#: A list of booleans representing bit values
self.bits = values or []

def encode(self):
Expand Down Expand Up @@ -147,7 +149,7 @@ def execute(self, context):
request is valid against the current datastore.
:param context: The datastore to request from
:returns: The initializes response message, exception message otherwise
:returns: An initialized :py:class:`~pymodbus.register_read_message.ReadCoilsResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred
'''
if not (1 <= self.count <= 0x7d0):
return self.doException(merror.IllegalValue)
Expand All @@ -169,6 +171,8 @@ class ReadCoilsResponse(ReadBitsResponseBase):
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.
The requested coils can be found in boolean form in the .bits list.
'''
function_code = 1

Expand Down Expand Up @@ -206,7 +210,7 @@ def execute(self, context):
request is valid against the current datastore.
:param context: The datastore to request from
:returns: The initializes response message, exception message otherwise
:returns: An initialized :py:class:`~pymodbus.register_read_message.ReadDiscreteInputsResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred
'''
if not (1 <= self.count <= 0x7d0):
return self.doException(merror.IllegalValue)
Expand All @@ -228,6 +232,8 @@ class ReadDiscreteInputsResponse(ReadBitsResponseBase):
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.
The requested coils can be found in boolean form in the .bits list.
'''
function_code = 2

Expand Down
18 changes: 14 additions & 4 deletions pymodbus/register_read_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def __str__(self):

class ReadRegistersResponseBase(ModbusResponse):
'''
Base class for responsing to a modbus register read
Base class for responding to a modbus register read.
The requested registers can be found in the .registers list.
'''

_rtu_byte_count_pos = 2
Expand All @@ -67,6 +69,8 @@ def __init__(self, values, **kwargs):
:param values: The values to write to
'''
ModbusResponse.__init__(self, **kwargs)

#: A list of register values
self.registers = values or []

def encode(self):
Expand Down Expand Up @@ -127,7 +131,7 @@ def execute(self, context):
''' Run a read holding request against a datastore
:param context: The datastore to request from
:returns: An initialized response, exception message otherwise
:returns: An initialized :py:class:`~pymodbus.register_read_message.ReadHoldingRegistersResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred
'''
if not (1 <= self.count <= 0x7d):
return self.doException(merror.IllegalValue)
Expand All @@ -144,6 +148,8 @@ class ReadHoldingRegistersResponse(ReadRegistersResponseBase):
starting register address and the number of registers. In the PDU
Registers are addressed starting at zero. Therefore registers numbered
1-16 are addressed as 0-15.
The requested registers can be found in the .registers list.
'''
function_code = 3

Expand Down Expand Up @@ -177,7 +183,7 @@ def execute(self, context):
''' Run a read input request against a datastore
:param context: The datastore to request from
:returns: An initialized response, exception message otherwise
:returns: An initialized :py:class:`~pymodbus.register_read_message.ReadInputRegistersResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred
'''
if not (1 <= self.count <= 0x7d):
return self.doException(merror.IllegalValue)
Expand All @@ -194,6 +200,8 @@ class ReadInputRegistersResponse(ReadRegistersResponseBase):
starting register address and the number of registers. In the PDU
Registers are addressed starting at zero. Therefore input registers
numbered 1-16 are addressed as 0-15.
The requested registers can be found in the .registers list.
'''
function_code = 4

Expand Down Expand Up @@ -269,7 +277,7 @@ def execute(self, context):
''' Run a write single register request against a datastore
:param context: The datastore to request from
:returns: An initialized response, exception message otherwise
:returns: An initialized :py:class:`~pymodbus.register_read_message.ReadWriteMultipleRegistersResponse`, or an :py:class:`~pymodbus.pdu.ExceptionResponse` if an error occurred
'''
if not (1 <= self.read_count <= 0x07d):
return self.doException(merror.IllegalValue)
Expand Down Expand Up @@ -311,6 +319,8 @@ class ReadWriteMultipleRegistersResponse(ModbusResponse):
The normal response contains the data from the group of registers that
were read. The byte count field specifies the quantity of bytes to
follow in the read data field.
The requested registers can be found in the .registers list.
'''
function_code = 23
_rtu_byte_count_pos = 2
Expand Down

0 comments on commit 245c21a

Please sign in to comment.