diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index bc44658df..67f39cce0 100755 --- a/examples/client_custom_msg.py +++ b/examples/client_custom_msg.py @@ -36,9 +36,9 @@ class CustomModbusResponse(ModbusResponse): function_code = 55 _rtu_byte_count_pos = 2 - def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values=None, slave=1, transaction=0, skip_encode=False): """Initialize.""" - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.values = values or [] def encode(self): @@ -68,9 +68,9 @@ class CustomModbusRequest(ModbusRequest): function_code = 55 _rtu_frame_size = 8 - def __init__(self, address=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, slave=1, transaction=0, skip_encode=False): """Initialize.""" - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.address = address self.count = 16 @@ -100,12 +100,12 @@ def execute(self, context): class Read16CoilsRequest(ReadCoilsRequest): """Read 16 coils in one request.""" - def __init__(self, address, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address, count=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from """ - ReadCoilsRequest.__init__(self, address, count=16, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + ReadCoilsRequest.__init__(self, address, count=16, slave=slave, transaction=transaction, skip_encode=skip_encode) # --------------------------------------------------------------------------- # diff --git a/pymodbus/factory.py b/pymodbus/factory.py index 1e4b04a06..ea5fff7a5 100644 --- a/pymodbus/factory.py +++ b/pymodbus/factory.py @@ -120,7 +120,7 @@ def _helper(self, data: str): function_code = int(data[0]) if not (request := self.lookup.get(function_code, lambda: None)()): Log.debug("Factory Request[{}]", function_code) - request = pdu.IllegalFunctionRequest(function_code, 0, 0, 0, False) + request = pdu.IllegalFunctionRequest(function_code, 0, 0, False) else: fc_string = "{}: {}".format( # pylint: disable=consider-using-f-string str(self.lookup[function_code]) # pylint: disable=use-maxsplit-arg diff --git a/pymodbus/framer/old_framer_base.py b/pymodbus/framer/old_framer_base.py index 20eec5c14..8c357f26d 100644 --- a/pymodbus/framer/old_framer_base.py +++ b/pymodbus/framer/old_framer_base.py @@ -107,7 +107,6 @@ def populateResult(self, result): """ result.slave_id = self.dev_id result.transaction_id = self.tid - result.protocol_id = 0 def processIncomingPacket(self, data: bytes, callback, slave, single=False, tid=None): """Process new packet pattern. diff --git a/pymodbus/pdu/bit_read_message.py b/pymodbus/pdu/bit_read_message.py index 4a116dc42..a277a10eb 100644 --- a/pymodbus/pdu/bit_read_message.py +++ b/pymodbus/pdu/bit_read_message.py @@ -13,14 +13,14 @@ class ReadBitsRequestBase(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address, count, slave, transaction, protocol, skip_encode): + def __init__(self, address, count, slave, transaction, skip_encode): """Initialize the read request data. :param address: The start address to read from :param count: The number of bits after "address" to read :param slave: Modbus slave slave ID """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.address = address self.count = count @@ -67,13 +67,13 @@ class ReadBitsResponseBase(ModbusResponse): _rtu_byte_count_pos = 2 - def __init__(self, values, slave, transaction, protocol, skip_encode): + def __init__(self, values, slave, transaction, skip_encode): """Initialize a new instance. :param values: The requested values to be returned :param slave: Modbus slave slave ID """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) #: A list of booleans representing bit values self.bits = values or [] @@ -138,14 +138,14 @@ class ReadCoilsRequest(ReadBitsRequestBase): function_code = 1 function_code_name = "read_coils" - def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from :param count: The number of bits to read :param slave: Modbus slave slave ID """ - ReadBitsRequestBase.__init__(self, address, count, slave, transaction, protocol, skip_encode) + ReadBitsRequestBase.__init__(self, address, count, slave, transaction, skip_encode) async def execute(self, context): """Run a read coils request against a datastore. @@ -185,13 +185,13 @@ class ReadCoilsResponse(ReadBitsResponseBase): function_code = 1 - def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param values: The request values to respond with :param slave: Modbus slave slave ID """ - ReadBitsResponseBase.__init__(self, values, slave, transaction, protocol, skip_encode) + ReadBitsResponseBase.__init__(self, values, slave, transaction, skip_encode) class ReadDiscreteInputsRequest(ReadBitsRequestBase): @@ -206,14 +206,14 @@ class ReadDiscreteInputsRequest(ReadBitsRequestBase): function_code = 2 function_code_name = "read_discrete_input" - def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from :param count: The number of bits to read :param slave: Modbus slave slave ID """ - ReadBitsRequestBase.__init__(self, address, count, slave, transaction, protocol, skip_encode) + ReadBitsRequestBase.__init__(self, address, count, slave, transaction, skip_encode) async def execute(self, context): """Run a read discrete input request against a datastore. @@ -253,10 +253,10 @@ class ReadDiscreteInputsResponse(ReadBitsResponseBase): function_code = 2 - def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param values: The request values to respond with :param slave: Modbus slave slave ID """ - ReadBitsResponseBase.__init__(self, values, slave, transaction, protocol, skip_encode) + ReadBitsResponseBase.__init__(self, values, slave, transaction, skip_encode) diff --git a/pymodbus/pdu/bit_write_message.py b/pymodbus/pdu/bit_write_message.py index 9b531d92c..627e7abe5 100644 --- a/pymodbus/pdu/bit_write_message.py +++ b/pymodbus/pdu/bit_write_message.py @@ -43,13 +43,13 @@ class WriteSingleCoilRequest(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, value=None, slave=None, transaction=0, skip_encode=0): """Initialize a new instance. :param address: The variable address to write :param value: The value to write at address """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.address = address self.value = bool(value) @@ -113,13 +113,13 @@ class WriteSingleCoilResponse(ModbusResponse): function_code = 5 _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, value=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The variable address written to :param value: The value written at address """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.address = address self.value = value @@ -167,13 +167,13 @@ class WriteMultipleCoilsRequest(ModbusRequest): function_code_name = "write_coils" _rtu_byte_count_pos = 6 - def __init__(self, address=None, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, values=None, slave=None, transaction=0, skip_encode=0): """Initialize a new instance. :param address: The starting request address :param values: The values to write """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.address = address if values is None: values = [] @@ -250,13 +250,13 @@ class WriteMultipleCoilsResponse(ModbusResponse): function_code = 15 _rtu_frame_size = 8 - def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The starting variable address written to :param count: The number of values written """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.address = address self.count = count diff --git a/pymodbus/pdu/diag_message.py b/pymodbus/pdu/diag_message.py index e23b56a68..22e735e32 100644 --- a/pymodbus/pdu/diag_message.py +++ b/pymodbus/pdu/diag_message.py @@ -31,9 +31,9 @@ class DiagnosticStatusRequest(ModbusRequest): function_code_name = "diagnostic_status" _rtu_frame_size = 8 - def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a diagnostic request.""" - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.message = None def encode(self): @@ -93,9 +93,9 @@ class DiagnosticStatusResponse(ModbusResponse): function_code = 0x08 _rtu_frame_size = 8 - def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a diagnostic response.""" - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.message = None def encode(self): @@ -150,7 +150,7 @@ class DiagnosticStatusSimpleRequest(DiagnosticStatusRequest): the execute method """ - def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, data=0x0000, slave=1, transaction=0, skip_encode=False): """Initialize a simple diagnostic request. The data defaults to 0x0000 if not provided as over half @@ -158,7 +158,7 @@ def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode= :param data: The data to send along with the request """ - DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) self.message = data async def execute(self, *args): @@ -175,12 +175,12 @@ class DiagnosticStatusSimpleResponse(DiagnosticStatusResponse): 2 bytes of data. """ - def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, data=0x0000, slave=1, transaction=0, skip_encode=False): """Return a simple diagnostic response. :param data: The resulting data to return to the client """ - DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) self.message = data @@ -197,12 +197,12 @@ class ReturnQueryDataRequest(DiagnosticStatusRequest): sub_function_code = 0x0000 - def __init__(self, message=b"\x00\x00", slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, message=b"\x00\x00", slave=1, transaction=0, skip_encode=False): """Initialize a new instance of the request. :param message: The message to send to loopback """ - DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) if not isinstance(message, bytes): raise ModbusException(f"message({type(message)}) must be bytes") self.message = message @@ -225,12 +225,12 @@ class ReturnQueryDataResponse(DiagnosticStatusResponse): sub_function_code = 0x0000 - def __init__(self, message=b"\x00\x00", slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, message=b"\x00\x00", slave=1, transaction=0, skip_encode=False): """Initialize a new instance of the response. :param message: The message to loopback """ - DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) if not isinstance(message, bytes): raise ModbusException(f"message({type(message)}) must be bytes") self.message = message @@ -252,12 +252,12 @@ class RestartCommunicationsOptionRequest(DiagnosticStatusRequest): sub_function_code = 0x0001 - def __init__(self, toggle=False, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, toggle=False, slave=1, transaction=0, skip_encode=False): """Initialize a new request. :param toggle: Set to True to toggle, False otherwise """ - DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) if toggle: self.message = [ModbusStatus.ON] else: @@ -285,12 +285,12 @@ class RestartCommunicationsOptionResponse(DiagnosticStatusResponse): sub_function_code = 0x0001 - def __init__(self, toggle=False, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, toggle=False, slave=1, transaction=0, skip_encode=False): """Initialize a new response. :param toggle: Set to True if we toggled, False otherwise """ - DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) if toggle: self.message = [ModbusStatus.ON] else: @@ -396,9 +396,9 @@ class ForceListenOnlyModeResponse(DiagnosticStatusResponse): sub_function_code = 0x0004 should_respond = False - def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize to block a return response.""" - DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, skip_encode=skip_encode) self.message = [] @@ -778,9 +778,9 @@ class GetClearModbusPlusRequest(DiagnosticStatusSimpleRequest): sub_function_code = 0x0015 - def __init__(self, data=0, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, data=0, slave=1, transaction=0, skip_encode=False): """Initialize.""" - super().__init__(slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + super().__init__(slave=slave, transaction=transaction, skip_encode=skip_encode) self.message=data def get_response_pdu_size(self): diff --git a/pymodbus/pdu/file_message.py b/pymodbus/pdu/file_message.py index 954b4e89f..3c3a01b31 100644 --- a/pymodbus/pdu/file_message.py +++ b/pymodbus/pdu/file_message.py @@ -89,12 +89,12 @@ class ReadFileRecordRequest(ModbusRequest): function_code_name = "read_file_record" _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -154,12 +154,12 @@ class ReadFileRecordResponse(ModbusResponse): function_code = 0x14 _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param records: The requested file records """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -210,12 +210,12 @@ class WriteFileRecordRequest(ModbusRequest): function_code_name = "write_file_record" _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -274,12 +274,12 @@ class WriteFileRecordResponse(ModbusResponse): function_code = 0x15 _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, records=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.records = records or [] def encode(self): @@ -339,12 +339,12 @@ class ReadFifoQueueRequest(ModbusRequest): function_code_name = "read_fifo_queue" _rtu_frame_size = 6 - def __init__(self, address=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=0x0000, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The fifo pointer address (0x0000 to 0xffff) """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.address = address self.values = [] # this should be added to the context @@ -400,12 +400,12 @@ def calculateRtuFrameSize(cls, buffer): lo_byte = int(buffer[3]) return (hi_byte << 16) + lo_byte + 6 - def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param values: The list of values of the fifo to return """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.values = values or [] def encode(self): diff --git a/pymodbus/pdu/mei_message.py b/pymodbus/pdu/mei_message.py index 71396bbc8..0fc327520 100644 --- a/pymodbus/pdu/mei_message.py +++ b/pymodbus/pdu/mei_message.py @@ -52,13 +52,13 @@ class ReadDeviceInformationRequest(ModbusRequest): function_code_name = "read_device_information" _rtu_frame_size = 7 - def __init__(self, read_code=None, object_id=0x00, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, read_code=None, object_id=0x00, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param read_code: The device information read code :param object_id: The object to read from """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) self.read_code = read_code or DeviceInformation.BASIC self.object_id = object_id @@ -130,13 +130,13 @@ def calculateRtuFrameSize(cls, buffer): except struct.error as exc: raise IndexError from exc - def __init__(self, read_code=None, information=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, read_code=None, information=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param read_code: The device information read code :param information: The requested information request """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.read_code = read_code or DeviceInformation.BASIC self.information = information or {} self.number_of_objects = 0 diff --git a/pymodbus/pdu/other_message.py b/pymodbus/pdu/other_message.py index 408fb0042..18423c8a4 100644 --- a/pymodbus/pdu/other_message.py +++ b/pymodbus/pdu/other_message.py @@ -30,9 +30,9 @@ class ReadExceptionStatusRequest(ModbusRequest): function_code_name = "read_exception_status" _rtu_frame_size = 4 - def __init__(self, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, slave=None, transaction=0, skip_encode=0): """Initialize a new instance.""" - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -72,12 +72,12 @@ class ReadExceptionStatusResponse(ModbusResponse): function_code = 0x07 _rtu_frame_size = 5 - def __init__(self, status=0x00, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, status=0x00, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param status: The status response to report """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.status = status if status < 256 else 255 def encode(self): @@ -135,9 +135,9 @@ class GetCommEventCounterRequest(ModbusRequest): function_code_name = "get_event_counter" _rtu_frame_size = 4 - def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a new instance.""" - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -178,12 +178,12 @@ class GetCommEventCounterResponse(ModbusResponse): function_code = 0x0B _rtu_frame_size = 8 - def __init__(self, count=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, count=0x0000, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param count: The current event counter value """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.count = count self.status = True # this means we are ready, not waiting @@ -246,9 +246,9 @@ class GetCommEventLogRequest(ModbusRequest): function_code_name = "get_event_log" _rtu_frame_size = 4 - def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a new instance.""" - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -293,7 +293,7 @@ class GetCommEventLogResponse(ModbusResponse): function_code = 0x0C _rtu_byte_count_pos = 2 - def __init__(self, status=True, message_count=0, event_count=0, events=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, status=True, message_count=0, event_count=0, events=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param status: The status response to report @@ -301,7 +301,7 @@ def __init__(self, status=True, message_count=0, event_count=0, events=None, sla :param event_count: The current event count :param events: The collection of events to send """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.status = status self.message_count = message_count self.event_count = event_count @@ -367,13 +367,13 @@ class ReportSlaveIdRequest(ModbusRequest): function_code_name = "report_slave_id" _rtu_frame_size = 4 - def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param slave: Modbus slave slave ID """ - ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) + ModbusRequest.__init__(self, slave, transaction, skip_encode) def encode(self): """Encode the message.""" @@ -426,13 +426,13 @@ class ReportSlaveIdResponse(ModbusResponse): function_code = 0x11 _rtu_byte_count_pos = 2 - def __init__(self, identifier=b"\x00", status=True, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, identifier=b"\x00", status=True, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param identifier: The identifier of the slave :param status: The status response to report """ - ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) + ModbusResponse.__init__(self, slave, transaction, skip_encode) self.identifier = identifier self.status = status self.byte_count = None diff --git a/pymodbus/pdu/pdu.py b/pymodbus/pdu/pdu.py index 67f486839..8bf5781a7 100644 --- a/pymodbus/pdu/pdu.py +++ b/pymodbus/pdu/pdu.py @@ -20,11 +20,6 @@ class ModbusPDU: This value is used to uniquely identify a request response pair. It can be implemented as a simple counter - .. attribute:: protocol_id - - This is a constant set at 0 to indicate Modbus. It is - put here for ease of expansion. - .. attribute:: slave_id This is used to route the request to the correct child. In @@ -46,14 +41,13 @@ class ModbusPDU: of encoding it again. """ - def __init__(self, slave, transaction, protocol, skip_encode): + def __init__(self, slave, transaction, skip_encode): """Initialize the base data for a modbus request. :param slave: Modbus slave slave ID """ self.transaction_id = transaction - self.protocol_id = protocol self.slave_id = slave self.skip_encode = skip_encode self.check = 0x0000 @@ -95,12 +89,12 @@ class ModbusRequest(ModbusPDU): function_code = -1 - def __init__(self, slave, transaction, protocol, skip_encode): + def __init__(self, slave, transaction, skip_encode): """Proxy to the lower level initializer. :param slave: Modbus slave slave ID """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.fut = None def doException(self, exception): @@ -131,13 +125,13 @@ class ModbusResponse(ModbusPDU): should_respond = True function_code = 0x00 - def __init__(self, slave, transaction, protocol, skip_encode): + def __init__(self, slave, transaction, skip_encode): """Proxy the lower level initializer. :param slave: Modbus slave slave ID """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.bits = [] self.registers = [] self.request = None @@ -184,13 +178,13 @@ class ExceptionResponse(ModbusResponse): ExceptionOffset = 0x80 _rtu_frame_size = 5 - def __init__(self, function_code, exception_code=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, function_code, exception_code=None, slave=1, transaction=0, skip_encode=False): """Initialize the modbus exception response. :param function_code: The function to build an exception response for :param exception_code: The specific modbus exception to return """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.original_code = function_code self.function_code = function_code | self.ExceptionOffset self.exception_code = exception_code @@ -233,12 +227,12 @@ class IllegalFunctionRequest(ModbusRequest): ErrorCode = 1 - def __init__(self, function_code, xslave, xtransaction, xprotocol, xskip_encode): + def __init__(self, function_code, slave, transaction, xskip_encode): """Initialize a IllegalFunctionRequest. :param function_code: The function we are erroring on """ - super().__init__(xslave, xtransaction, xprotocol, xskip_encode) + super().__init__(slave, transaction, xskip_encode) self.function_code = function_code def decode(self, _data): diff --git a/pymodbus/pdu/register_read_message.py b/pymodbus/pdu/register_read_message.py index 7d05e6ed2..f8a3c465b 100644 --- a/pymodbus/pdu/register_read_message.py +++ b/pymodbus/pdu/register_read_message.py @@ -14,14 +14,14 @@ class ReadRegistersRequestBase(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address, count, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address, count, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The address to start the read from :param count: The number of registers to read :param slave: Modbus slave slave ID """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address self.count = count @@ -62,13 +62,13 @@ class ReadRegistersResponseBase(ModbusResponse): _rtu_byte_count_pos = 2 - def __init__(self, values, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param values: The values to write to :param slave: Modbus slave slave ID """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) #: A list of register values self.registers = values or [] @@ -124,14 +124,14 @@ class ReadHoldingRegistersRequest(ReadRegistersRequestBase): function_code = 3 function_code_name = "read_holding_registers" - def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=0): """Initialize a new instance of the request. :param address: The starting address to read from :param count: The number of registers to read from address :param slave: Modbus slave slave ID """ - super().__init__(address, count, slave, transaction, protocol, skip_encode) + super().__init__(address, count, slave, transaction, skip_encode) async def execute(self, context): """Run a read holding request against a datastore. @@ -165,12 +165,12 @@ class ReadHoldingRegistersResponse(ReadRegistersResponseBase): function_code = 3 - def __init__(self, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, values=None, slave=None, transaction=0, skip_encode=0): """Initialize a new response instance. :param values: The resulting register values """ - super().__init__(values, slave, transaction, protocol, skip_encode) + super().__init__(values, slave, transaction, skip_encode) class ReadInputRegistersRequest(ReadRegistersRequestBase): @@ -186,14 +186,14 @@ class ReadInputRegistersRequest(ReadRegistersRequestBase): function_code = 4 function_code_name = "read_input_registers" - def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=0): """Initialize a new instance of the request. :param address: The starting address to read from :param count: The number of registers to read from address :param slave: Modbus slave slave ID """ - super().__init__(address, count, slave, transaction, protocol, skip_encode) + super().__init__(address, count, slave, transaction, skip_encode) async def execute(self, context): """Run a read input request against a datastore. @@ -227,12 +227,12 @@ class ReadInputRegistersResponse(ReadRegistersResponseBase): function_code = 4 - def __init__(self, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, values=None, slave=None, transaction=0, skip_encode=0): """Initialize a new response instance. :param values: The resulting register values """ - super().__init__(values, slave, transaction, protocol, skip_encode) + super().__init__(values, slave, transaction, skip_encode) class ReadWriteMultipleRegistersRequest(ModbusRequest): @@ -255,7 +255,7 @@ class ReadWriteMultipleRegistersRequest(ModbusRequest): function_code_name = "read_write_multiple_registers" _rtu_byte_count_pos = 10 - def __init__(self, read_address=0x00, read_count=0, write_address=0x00, write_registers=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, read_address=0x00, read_count=0, write_address=0x00, write_registers=None, slave=1, transaction=0, skip_encode=False): """Initialize a new request message. :param read_address: The address to start reading from @@ -263,7 +263,7 @@ def __init__(self, read_address=0x00, read_count=0, write_address=0x00, write_re :param write_address: The address to start writing to :param write_registers: The registers to write to the specified address """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.read_address = read_address self.read_count = read_count self.write_address = write_address diff --git a/pymodbus/pdu/register_write_message.py b/pymodbus/pdu/register_write_message.py index 5ee9a1c40..6a1abb3aa 100644 --- a/pymodbus/pdu/register_write_message.py +++ b/pymodbus/pdu/register_write_message.py @@ -20,13 +20,13 @@ class WriteSingleRegisterRequest(ModbusRequest): function_code_name = "write_register" _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, value=None, slave=None, transaction=0, skip_encode=0): """Initialize a new instance. :param address: The address to start writing add :param value: The values to write """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address self.value = value @@ -91,13 +91,13 @@ class WriteSingleRegisterResponse(ModbusResponse): function_code = 6 _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, value=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The address to start writing add :param value: The values to write """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address self.value = value @@ -152,13 +152,13 @@ class WriteMultipleRegistersRequest(ModbusRequest): _rtu_byte_count_pos = 6 _pdu_length = 5 # func + adress1 + adress2 + outputQuant1 + outputQuant2 - def __init__(self, address=None, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, values=None, slave=None, transaction=0, skip_encode=0): """Initialize a new instance. :param address: The address to start writing to :param values: The values to write """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address if values is None: values = [] @@ -239,13 +239,13 @@ class WriteMultipleRegistersResponse(ModbusResponse): function_code = 16 _rtu_frame_size = 8 - def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=None, count=None, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The address to start writing to :param count: The number of registers to write to """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address self.count = count @@ -287,14 +287,14 @@ class MaskWriteRegisterRequest(ModbusRequest): function_code_name = "mask_write_register" _rtu_frame_size = 10 - def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, transaction=0, skip_encode=False): """Initialize a new instance. :param address: The mask pointer address (0x0000 to 0xffff) :param and_mask: The and bitmask to apply to the register address :param or_mask: The or bitmask to apply to the register address """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address self.and_mask = and_mask self.or_mask = or_mask @@ -342,14 +342,14 @@ class MaskWriteRegisterResponse(ModbusResponse): function_code = 0x16 _rtu_frame_size = 10 - def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, transaction=0, skip_encode=False): """Initialize new instance. :param address: The mask pointer address (0x0000 to 0xffff) :param and_mask: The and bitmask applied to the register address :param or_mask: The or bitmask applied to the register address """ - super().__init__(slave, transaction, protocol, skip_encode) + super().__init__(slave, transaction, skip_encode) self.address = address self.and_mask = and_mask self.or_mask = or_mask diff --git a/test/framers/test_tbc_transaction.py b/test/framers/test_tbc_transaction.py index 411eb3784..66b74d592 100755 --- a/test/framers/test_tbc_transaction.py +++ b/test/framers/test_tbc_transaction.py @@ -315,9 +315,8 @@ def callback(data): count += 1 result = data - expected = ModbusRequest(0, 0, 0, False) + expected = ModbusRequest(0, 0, False) expected.transaction_id = 0x0001 - expected.protocol_id = 0x1234 expected.slave_id = 0xFF msg = b"\x00\x01\x12\x34\x00\x06\xff\x02\x12\x34\x01\x02" self._tcp.processIncomingPacket(msg, callback, [0, 1]) @@ -331,9 +330,8 @@ def test_tcp_framer_packet(self): """Test a tcp frame packet build.""" old_encode = ModbusRequest.encode ModbusRequest.encode = lambda self: b"" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.transaction_id = 0x0001 - message.protocol_id = 0x0000 message.slave_id = 0xFF message.function_code = 0x01 expected = b"\x00\x01\x00\x00\x00\x02\xff\x01" @@ -486,7 +484,7 @@ def test_framer_tls_framer_packet(self): """Test a tls frame packet build.""" old_encode = ModbusRequest.encode ModbusRequest.encode = lambda self: b"" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.function_code = 0x01 expected = b"\x01" actual = self._tls.buildPacket(message) @@ -560,7 +558,7 @@ def test_rtu_framer_packet(self): """Test a rtu frame packet build.""" old_encode = ModbusRequest.encode ModbusRequest.encode = lambda self: b"" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.slave_id = 0xFF message.function_code = 0x01 expected = b"\xff\x01\x81\x80" # only header + CRC - no data @@ -661,7 +659,7 @@ def callback(data): def test_ascii_framer_populate(self): """Test a ascii frame packet build.""" - request = ModbusRequest(0, 0, 0, False) + request = ModbusRequest(0, 0, False) self._ascii.populateResult(request) assert not request.slave_id @@ -669,7 +667,7 @@ def test_ascii_framer_packet(self): """Test a ascii frame packet build.""" old_encode = ModbusRequest.encode ModbusRequest.encode = lambda self: b"" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.slave_id = 0xFF message.function_code = 0x01 expected = b":FF0100\r\n" diff --git a/test/sub_client/test_client.py b/test/sub_client/test_client.py index b59d9149b..d82ce2c5b 100755 --- a/test/sub_client/test_client.py +++ b/test/sub_client/test_client.py @@ -243,7 +243,7 @@ async def test_client_instanciate( client.connect = lambda: False client.transport = None with pytest.raises(ConnectionException): - client.execute(ModbusRequest(0, 0, 0, False)) + client.execute(ModbusRequest(0, 0, False)) async def test_client_modbusbaseclient(): """Test modbus base client class.""" @@ -679,13 +679,13 @@ async def test_client_build_response(): comm_params=CommParams(), ) with pytest.raises(ConnectionException): - await client.build_response(ModbusRequest(0, 0, 0, False)) + await client.build_response(ModbusRequest(0, 0, False)) async def test_client_mixin_execute(): """Test dummy execute for both sync and async.""" client = ModbusClientMixin() with pytest.raises(NotImplementedError): - client.execute(ModbusRequest(0, 0, 0, False)) + client.execute(ModbusRequest(0, 0, False)) with pytest.raises(NotImplementedError): - await client.execute(ModbusRequest(0, 0, 0, False)) + await client.execute(ModbusRequest(0, 0, False)) diff --git a/test/sub_current/test_pdu.py b/test/sub_current/test_pdu.py index aa18b2d6c..5c17b4088 100644 --- a/test/sub_current/test_pdu.py +++ b/test/sub_current/test_pdu.py @@ -15,11 +15,11 @@ class TestPdu: """Unittest for the pymod.pdu module.""" bad_requests = ( - ModbusRequest(0, 0, 0, False), - ModbusResponse(0, 0, 0, False), + ModbusRequest(0, 0, False), + ModbusResponse(0, 0, False), ) - illegal = IllegalFunctionRequest(1, 0, 0, 0, False) - exception = ExceptionResponse(1, 1, 0, 0, 0, False) + illegal = IllegalFunctionRequest(1, 0, 0, False) + exception = ExceptionResponse(1, 1, 0, 0, False) def test_not_impelmented(self): """Test a base classes for not implemented functions.""" @@ -43,7 +43,7 @@ async def test_error_methods(self): def test_request_exception_factory(self): """Test all error methods.""" - request = ModbusRequest(0, 0, 0, False) + request = ModbusRequest(0, 0, False) request.function_code = 1 errors = {ModbusExceptions.decode(c): c for c in range(1, 20)} for error, code in iter(errors.items()): diff --git a/test/sub_current/test_transaction.py b/test/sub_current/test_transaction.py index 741002d80..e7cb2b821 100755 --- a/test/sub_current/test_transaction.py +++ b/test/sub_current/test_transaction.py @@ -172,7 +172,7 @@ def test_get_transaction_manager_transaction(self): """Test the getting a transaction from the transaction manager.""" self._manager.reset() handle = ModbusRequest( - 0, self._manager.getNextTID(), 0, False + 0, self._manager.getNextTID(), False ) self._manager.addTransaction(handle) result = self._manager.getTransaction(handle.transaction_id) @@ -182,7 +182,7 @@ def test_delete_transaction_manager_transaction(self): """Test deleting a transaction from the dict transaction manager.""" self._manager.reset() handle = ModbusRequest( - 0, self._manager.getNextTID(), 0, False + 0, self._manager.getNextTID(), False ) self._manager.addTransaction(handle) self._manager.delTransaction(handle.transaction_id) @@ -303,9 +303,8 @@ def callback(data): count += 1 result = data - expected = ModbusRequest(0, 0, 0, False) + expected = ModbusRequest(0, 0, False) expected.transaction_id = 0x0001 - expected.protocol_id = 0x1234 expected.slave_id = 0xFF msg = b"\x00\x01\x12\x34\x00\x06\xff\x02\x12\x34\x01\x02" self._tcp.processIncomingPacket(msg, callback, [0, 1]) @@ -318,9 +317,8 @@ def callback(data): @mock.patch.object(ModbusRequest, "encode") def test_tcp_framer_packet(self, mock_encode): """Test a tcp frame packet build.""" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.transaction_id = 0x0001 - message.protocol_id = 0x0000 message.slave_id = 0xFF message.function_code = 0x01 expected = b"\x00\x01\x00\x00\x00\x02\xff\x01" @@ -472,7 +470,7 @@ def callback(data): @mock.patch.object(ModbusRequest, "encode") def test_framer_tls_framer_packet(self, mock_encode): """Test a tls frame packet build.""" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.function_code = 0x01 expected = b"\x01" mock_encode.return_value = b"" @@ -545,7 +543,7 @@ def callback(data): @mock.patch.object(ModbusRequest, "encode") def test_rtu_framer_packet(self, mock_encode): """Test a rtu frame packet build.""" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.slave_id = 0xFF message.function_code = 0x01 expected = b"\xff\x01\x81\x80" # only header + CRC - no data @@ -646,14 +644,14 @@ def callback(data): def test_ascii_framer_populate(self): """Test a ascii frame packet build.""" - request = ModbusRequest(0, 0, 0, False) + request = ModbusRequest(0, 0, False) self._ascii.populateResult(request) assert not request.slave_id @mock.patch.object(ModbusRequest, "encode") def test_ascii_framer_packet(self, mock_encode): """Test a ascii frame packet build.""" - message = ModbusRequest(0, 0, 0, False) + message = ModbusRequest(0, 0, False) message.slave_id = 0xFF message.function_code = 0x01 expected = b":FF0100\r\n" diff --git a/test/sub_function_codes/test_all_messages.py b/test/sub_function_codes/test_all_messages.py index 3454cf191..e2581e9d4 100644 --- a/test/sub_function_codes/test_all_messages.py +++ b/test/sub_function_codes/test_all_messages.py @@ -84,12 +84,10 @@ def test_initializing_slave_address_response(self): def test_forwarding_to_pdu(self): """Test that parameters are forwarded to the pdu correctly.""" - request = ReadCoilsRequest(1, 5, slave=18, transaction=0x12, protocol=0x12) + request = ReadCoilsRequest(1, 5, slave=18, transaction=0x12,) assert request.slave_id == 0x12 assert request.transaction_id == 0x12 - assert request.protocol_id == 0x12 request = ReadCoilsRequest(1, 5) assert request.slave_id == 1 assert not request.transaction_id - assert not request.protocol_id diff --git a/test/sub_function_codes/test_bit_read_messages.py b/test/sub_function_codes/test_bit_read_messages.py index 99c095560..85f807e37 100644 --- a/test/sub_function_codes/test_bit_read_messages.py +++ b/test/sub_function_codes/test_bit_read_messages.py @@ -40,17 +40,17 @@ def tearDown(self): def test_read_bit_base_class_methods(self): """Test basic bit message encoding/decoding.""" - handle = ReadBitsRequestBase(1, 1, 0, 0, 0, False) + handle = ReadBitsRequestBase(1, 1, 0, 0, False) msg = "ReadBitRequest(1,1)" assert msg == str(handle) - handle = ReadBitsResponseBase([1, 1], 0, 0, 0, False) + handle = ReadBitsResponseBase([1, 1], 0, 0, False) msg = "ReadBitsResponseBase(2)" assert msg == str(handle) def test_bit_read_base_request_encoding(self): """Test basic bit message encoding/decoding.""" for i in range(20): - handle = ReadBitsRequestBase(i, i, 0, 0, 0, False) + handle = ReadBitsRequestBase(i, i, 0, 0, False) result = struct.pack(">HH", i, i) assert handle.encode() == result handle.decode(result) @@ -60,7 +60,7 @@ def test_bit_read_base_response_encoding(self): """Test basic bit message encoding/decoding.""" for i in range(20): data = [True] * i - handle = ReadBitsResponseBase(data, 0, 0, 0, False) + handle = ReadBitsResponseBase(data, 0, 0, False) result = handle.encode() handle.decode(result) assert handle.bits[:i] == data @@ -68,7 +68,7 @@ def test_bit_read_base_response_encoding(self): def test_bit_read_base_response_helper_methods(self): """Test the extra methods on a ReadBitsResponseBase.""" data = [False] * 8 - handle = ReadBitsResponseBase(data, 0, 0, 0, False) + handle = ReadBitsResponseBase(data, 0, 0, False) for i in (1, 3, 5): handle.setBit(i, True) for i in (1, 3, 5): @@ -79,8 +79,8 @@ def test_bit_read_base_response_helper_methods(self): def test_bit_read_base_requests(self): """Test bit read request encoding.""" messages = { - ReadBitsRequestBase(12, 14, 0, 0, 0, False): b"\x00\x0c\x00\x0e", - ReadBitsResponseBase([1, 0, 1, 1, 0], 0, 0, 0, False): b"\x01\x0d", + ReadBitsRequestBase(12, 14, 0, 0, False): b"\x00\x0c\x00\x0e", + ReadBitsResponseBase([1, 0, 1, 1, 0], 0, 0, False): b"\x01\x0d", } for request, expected in iter(messages.items()): assert request.encode() == expected @@ -89,8 +89,8 @@ async def test_bit_read_message_execute_value_errors(self): """Test bit read request encoding.""" context = MockContext() requests = [ - ReadCoilsRequest(1, 0x800, 0, 0, 0, False), - ReadDiscreteInputsRequest(1, 0x800, 0, 0, 0, False), + ReadCoilsRequest(1, 0x800, 0, 0, False), + ReadDiscreteInputsRequest(1, 0x800, 0, 0, False), ] for request in requests: result = await request.execute(context) @@ -100,8 +100,8 @@ async def test_bit_read_message_execute_address_errors(self): """Test bit read request encoding.""" context = MockContext() requests = [ - ReadCoilsRequest(1, 5, 0, 0, 0, False), - ReadDiscreteInputsRequest(1, 5, 0, 0, 0, False), + ReadCoilsRequest(1, 5, 0, 0, False), + ReadDiscreteInputsRequest(1, 5, 0, 0, False), ] for request in requests: result = await request.execute(context) @@ -112,8 +112,8 @@ async def test_bit_read_message_execute_success(self): context = MockContext() context.validate = lambda a, b, c: True requests = [ - ReadCoilsRequest(1, 5, 0, 0, 0, False), - ReadDiscreteInputsRequest(1, 5, 0, 0, 0, False), + ReadCoilsRequest(1, 5, 0, 0, False), + ReadDiscreteInputsRequest(1, 5, 0, False), ] for request in requests: result = await request.execute(context) @@ -122,12 +122,12 @@ async def test_bit_read_message_execute_success(self): def test_bit_read_message_get_response_pdu(self): """Test bit read message get response pdu.""" requests = { - ReadCoilsRequest(1, 5, 0, 0, 0, False): 3, - ReadCoilsRequest(1, 8, 0, 0, 0, False): 3, - ReadCoilsRequest(0, 16, 0, 0, 0, False): 4, - ReadDiscreteInputsRequest(1, 21, 0, 0, 0, False): 5, - ReadDiscreteInputsRequest(1, 24, 0, 0, 0, False): 5, - ReadDiscreteInputsRequest(1, 1900, 0, 0, 0, False): 240, + ReadCoilsRequest(1, 5, 0, 0, False): 3, + ReadCoilsRequest(1, 8, 0, 0, False): 3, + ReadCoilsRequest(0, 16, 0, 0, False): 4, + ReadDiscreteInputsRequest(1, 21, 0, 0, False): 5, + ReadDiscreteInputsRequest(1, 24, 0, 0, False): 5, + ReadDiscreteInputsRequest(1, 1900, 0, 0, False): 240, } for request, expected in iter(requests.items()): pdu_len = request.get_response_pdu_size()