From 552c56e8ded17f384737981df81ba6247a538b57 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 19 Jul 2024 15:35:19 +0200 Subject: [PATCH] remove kwargs PDU messagees. (#2240) --- examples/client_async_calls.py | 2 +- examples/client_calls.py | 2 +- examples/client_custom_msg.py | 13 ++++----- pymodbus/client/mixin.py | 21 ++++++--------- pymodbus/pdu/bit_read_message.py | 12 ++++----- pymodbus/pdu/bit_write_message.py | 8 +++--- pymodbus/pdu/diag_message.py | 37 +++++++++++++------------- pymodbus/pdu/file_message.py | 26 +++++++++--------- pymodbus/pdu/mei_message.py | 4 +-- pymodbus/pdu/other_message.py | 24 ++++++++--------- pymodbus/pdu/register_read_message.py | 32 +++++++++++----------- pymodbus/pdu/register_write_message.py | 12 ++++----- 12 files changed, 95 insertions(+), 98 deletions(-) diff --git a/examples/client_async_calls.py b/examples/client_async_calls.py index 482a9ec40..bf4d66b43 100755 --- a/examples/client_async_calls.py +++ b/examples/client_async_calls.py @@ -137,7 +137,7 @@ async def async_handle_holding_registers(client): assert not rr.isError() # test that call was OK assert rr.registers == [10] * 8 - _logger.info("### write read holding registers, using **kwargs") + _logger.info("### write read holding registers") arguments = { "read_address": 1, "read_count": 8, diff --git a/examples/client_calls.py b/examples/client_calls.py index 50a58bc3d..c1de95f93 100755 --- a/examples/client_calls.py +++ b/examples/client_calls.py @@ -138,7 +138,7 @@ def handle_holding_registers(client): assert not rr.isError() # test that call was OK assert rr.registers == [10] * 8 - _logger.info("### write read holding registers, using **kwargs") + _logger.info("### write read holding registers") arguments = { "read_address": 1, "read_count": 8, diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index 17b643c64..8fb6cb3a5 100755 --- a/examples/client_custom_msg.py +++ b/examples/client_custom_msg.py @@ -36,7 +36,7 @@ class CustomModbusResponse(ModbusResponse): function_code = 55 _rtu_byte_count_pos = 2 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize.""" ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) self.values = values or [] @@ -68,7 +68,7 @@ class CustomModbusRequest(ModbusRequest): function_code = 55 _rtu_frame_size = 8 - def __init__(self, address=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) self.address = address @@ -100,12 +100,12 @@ def execute(self, context): class Read16CoilsRequest(ReadCoilsRequest): """Read 16 coils in one request.""" - def __init__(self, address, **kwargs): + def __init__(self, address, count=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from """ - ReadCoilsRequest.__init__(self, address, 16, **kwargs) + ReadCoilsRequest.__init__(self, address, count=16, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) # --------------------------------------------------------------------------- # @@ -126,12 +126,13 @@ async def main(host="localhost", port=5020): # new modbus function code. client.register(CustomModbusResponse) - request = CustomModbusRequest(32, slave=1) + slave=1 + request = CustomModbusRequest(32, slave=slave) result = await client.execute(request) print(result) # inherited request - request = Read16CoilsRequest(32, slave=1) + request = Read16CoilsRequest(32, slave) result = await client.execute(request) print(result) diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py index bb5346d25..40391de61 100644 --- a/pymodbus/client/mixin.py +++ b/pymodbus/client/mixin.py @@ -64,48 +64,42 @@ def execute(self, _request: ModbusRequest) -> T: ) def read_coils( - self, address: int, count: int = 1, slave: int = 0, **kwargs: Any - ) -> T: + self, address: int, count: int = 1, slave: int = 0) -> T: """Read coils (code 0x01). :param address: Start address to read from :param count: (optional) Number of coils to read :param slave: (optional) Modbus slave ID - :param kwargs: (optional) Experimental parameters. :raises ModbusException: """ return self.execute( - pdu_bit_read.ReadCoilsRequest(address, count, slave, **kwargs) + pdu_bit_read.ReadCoilsRequest(address, count, slave) ) def read_discrete_inputs( - self, address: int, count: int = 1, slave: int = 0, **kwargs: Any - ) -> T: + self, address: int, count: int = 1, slave: int = 0) -> T: """Read discrete inputs (code 0x02). :param address: Start address to read from :param count: (optional) Number of coils to read :param slave: (optional) Modbus slave ID - :param kwargs: (optional) Experimental parameters. :raises ModbusException: """ return self.execute( - pdu_bit_read.ReadDiscreteInputsRequest(address, count, slave, **kwargs) + pdu_bit_read.ReadDiscreteInputsRequest(address, count, slave) ) def read_holding_registers( - self, address: int, count: int = 1, slave: int = 0, **kwargs: Any - ) -> T: + self, address: int, count: int = 1, slave: int = 0) -> T: """Read holding registers (code 0x03). :param address: Start address to read from :param count: (optional) Number of coils to read :param slave: (optional) Modbus slave ID - :param kwargs: (optional) Experimental parameters. :raises ModbusException: """ return self.execute( - pdu_reg_read.ReadHoldingRegistersRequest(address, count, slave, **kwargs) + pdu_reg_read.ReadHoldingRegistersRequest(address, count, slave) ) def read_input_registers( @@ -457,6 +451,7 @@ def readwrite_registers( :param kwargs: :raises ModbusException: """ + read_address = kwargs.pop("address", read_address) return self.execute( pdu_reg_read.ReadWriteMultipleRegistersRequest( read_address=read_address, @@ -464,7 +459,7 @@ def readwrite_registers( write_address=write_address, write_registers=values, slave=slave, - **kwargs, + **kwargs ) ) diff --git a/pymodbus/pdu/bit_read_message.py b/pymodbus/pdu/bit_read_message.py index c7a54e679..a7a8877a5 100644 --- a/pymodbus/pdu/bit_read_message.py +++ b/pymodbus/pdu/bit_read_message.py @@ -21,7 +21,7 @@ class ReadBitsRequestBase(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize the read request data. :param address: The start address to read from @@ -75,7 +75,7 @@ class ReadBitsResponseBase(ModbusResponse): _rtu_byte_count_pos = 2 - def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The requested values to be returned @@ -146,7 +146,7 @@ class ReadCoilsRequest(ReadBitsRequestBase): function_code = 1 function_code_name = "read_coils" - def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from @@ -193,7 +193,7 @@ class ReadCoilsResponse(ReadBitsResponseBase): function_code = 1 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The request values to respond with @@ -214,7 +214,7 @@ class ReadDiscreteInputsRequest(ReadBitsRequestBase): function_code = 2 function_code_name = "read_discrete_input" - def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from @@ -261,7 +261,7 @@ class ReadDiscreteInputsResponse(ReadBitsResponseBase): function_code = 2 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The request values to respond with diff --git a/pymodbus/pdu/bit_write_message.py b/pymodbus/pdu/bit_write_message.py index 3297299d0..04c2d5c6a 100644 --- a/pymodbus/pdu/bit_write_message.py +++ b/pymodbus/pdu/bit_write_message.py @@ -49,7 +49,7 @@ class WriteSingleCoilRequest(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0, **_kwargs): + def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance. :param address: The variable address to write @@ -119,7 +119,7 @@ class WriteSingleCoilResponse(ModbusResponse): function_code = 5 _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, value=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The variable address written to @@ -173,7 +173,7 @@ 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, **_kwargs): + def __init__(self, address=None, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance. :param address: The starting request address @@ -256,7 +256,7 @@ class WriteMultipleCoilsResponse(ModbusResponse): function_code = 15 _rtu_frame_size = 8 - def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The starting variable address written to diff --git a/pymodbus/pdu/diag_message.py b/pymodbus/pdu/diag_message.py index 8d507068c..68f5ee0d4 100644 --- a/pymodbus/pdu/diag_message.py +++ b/pymodbus/pdu/diag_message.py @@ -69,7 +69,7 @@ class DiagnosticStatusRequest(ModbusRequest): function_code_name = "diagnostic_status" _rtu_frame_size = 8 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a diagnostic request.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) self.message = None @@ -131,7 +131,7 @@ class DiagnosticStatusResponse(ModbusResponse): function_code = 0x08 _rtu_frame_size = 8 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a diagnostic response.""" ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) self.message = None @@ -188,7 +188,7 @@ class DiagnosticStatusSimpleRequest(DiagnosticStatusRequest): the execute method """ - def __init__(self, data=0x0000, **kwargs): + def __init__(self, data=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a simple diagnostic request. The data defaults to 0x0000 if not provided as over half @@ -196,7 +196,7 @@ def __init__(self, data=0x0000, **kwargs): :param data: The data to send along with the request """ - DiagnosticStatusRequest.__init__(self, **kwargs) + DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) self.message = data async def execute(self, *args): @@ -213,12 +213,12 @@ class DiagnosticStatusSimpleResponse(DiagnosticStatusResponse): 2 bytes of data. """ - def __init__(self, data=0x0000, **kwargs): + def __init__(self, data=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): """Return a simple diagnostic response. :param data: The resulting data to return to the client """ - DiagnosticStatusResponse.__init__(self, **kwargs) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) self.message = data @@ -235,12 +235,12 @@ class ReturnQueryDataRequest(DiagnosticStatusRequest): sub_function_code = 0x0000 - def __init__(self, message=b"\x00\x00", slave=None, **kwargs): + def __init__(self, message=b"\x00\x00", slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance of the request. :param message: The message to send to loopback """ - DiagnosticStatusRequest.__init__(self, slave=slave, **kwargs) + DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) if not isinstance(message, bytes): raise ModbusException(f"message({type(message)}) must be bytes") self.message = message @@ -263,12 +263,12 @@ class ReturnQueryDataResponse(DiagnosticStatusResponse): sub_function_code = 0x0000 - def __init__(self, message=b"\x00\x00", **kwargs): + def __init__(self, message=b"\x00\x00", slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance of the response. :param message: The message to loopback """ - DiagnosticStatusResponse.__init__(self, **kwargs) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) if not isinstance(message, bytes): raise ModbusException(f"message({type(message)}) must be bytes") self.message = message @@ -290,12 +290,12 @@ class RestartCommunicationsOptionRequest(DiagnosticStatusRequest): sub_function_code = 0x0001 - def __init__(self, toggle=False, slave=None, **kwargs): + def __init__(self, toggle=False, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new request. :param toggle: Set to True to toggle, False otherwise """ - DiagnosticStatusRequest.__init__(self, slave=slave, **kwargs) + DiagnosticStatusRequest.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) if toggle: self.message = [ModbusStatus.ON] else: @@ -323,12 +323,12 @@ class RestartCommunicationsOptionResponse(DiagnosticStatusResponse): sub_function_code = 0x0001 - def __init__(self, toggle=False, **kwargs): + def __init__(self, toggle=False, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new response. :param toggle: Set to True if we toggled, False otherwise """ - DiagnosticStatusResponse.__init__(self, **kwargs) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) if toggle: self.message = [ModbusStatus.ON] else: @@ -434,9 +434,9 @@ class ForceListenOnlyModeResponse(DiagnosticStatusResponse): sub_function_code = 0x0004 should_respond = False - def __init__(self, **kwargs): + def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize to block a return response.""" - DiagnosticStatusResponse.__init__(self, **kwargs) + DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) self.message = [] @@ -816,9 +816,10 @@ class GetClearModbusPlusRequest(DiagnosticStatusSimpleRequest): sub_function_code = 0x0015 - def __init__(self, slave=None, **kwargs): + def __init__(self, data=0, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize.""" - super().__init__(slave=slave, **kwargs) + super().__init__(slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) + self.message=data def get_response_pdu_size(self): """Return a series of 54 16-bit words (108 bytes) in the data field of the response. diff --git a/pymodbus/pdu/file_message.py b/pymodbus/pdu/file_message.py index 51b4ecf50..43a94afb1 100644 --- a/pymodbus/pdu/file_message.py +++ b/pymodbus/pdu/file_message.py @@ -28,7 +28,7 @@ class FileRecord: # pylint: disable=eq-without-hash """Represents a file record and its relevant data.""" - def __init__(self, **kwargs): + def __init__(self, reference_type=0x06, file_number=0x00, record_number=0x00, record_data="", record_length=None, response_length=None): """Initialize a new instance. :params reference_type: must be 0x06 @@ -38,13 +38,13 @@ def __init__(self, **kwargs): :params record_length: The length in registers of the record :params response_length: The length in bytes of the record """ - self.reference_type = kwargs.get("reference_type", 0x06) - self.file_number = kwargs.get("file_number", 0x00) - self.record_number = kwargs.get("record_number", 0x00) - self.record_data = kwargs.get("record_data", "") + self.reference_type = reference_type + self.file_number = file_number + self.record_number = record_number + self.record_data = record_data - self.record_length = kwargs.get("record_length", len(self.record_data) // 2) - self.response_length = kwargs.get("response_length", len(self.record_data) + 1) + self.record_length = record_length if record_length else len(self.record_data) // 2 + self.response_length = response_length if response_length else len(self.record_data) + 1 def __eq__(self, relf): """Compare the left object to the right.""" @@ -100,7 +100,7 @@ class ReadFileRecordRequest(ModbusRequest): function_code_name = "read_file_record" _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read @@ -165,7 +165,7 @@ class ReadFileRecordResponse(ModbusResponse): function_code = 0x14 _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The requested file records @@ -218,7 +218,7 @@ class WriteFileRecordRequest(ModbusRequest): function_code_name = "write_file_record" _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read @@ -282,7 +282,7 @@ class WriteFileRecordResponse(ModbusResponse): function_code = 0x15 _rtu_byte_count_pos = 2 - def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, records=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read @@ -347,7 +347,7 @@ class ReadFifoQueueRequest(ModbusRequest): function_code_name = "read_fifo_queue" _rtu_frame_size = 6 - def __init__(self, address=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The fifo pointer address (0x0000 to 0xffff) @@ -408,7 +408,7 @@ def calculateRtuFrameSize(cls, buffer): lo_byte = int(buffer[3]) return (hi_byte << 16) + lo_byte + 6 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The list of values of the fifo to return diff --git a/pymodbus/pdu/mei_message.py b/pymodbus/pdu/mei_message.py index c1aeac445..aaedea198 100644 --- a/pymodbus/pdu/mei_message.py +++ b/pymodbus/pdu/mei_message.py @@ -56,7 +56,7 @@ class ReadDeviceInformationRequest(ModbusRequest): function_code_name = "read_device_information" _rtu_frame_size = 7 - def __init__(self, read_code=None, object_id=0x00, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, read_code=None, object_id=0x00, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param read_code: The device information read code @@ -134,7 +134,7 @@ def calculateRtuFrameSize(cls, buffer): except struct.error as exc: raise IndexError from exc - def __init__(self, read_code=None, information=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, read_code=None, information=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param read_code: The device information read code diff --git a/pymodbus/pdu/other_message.py b/pymodbus/pdu/other_message.py index a6b51a793..0b251f467 100644 --- a/pymodbus/pdu/other_message.py +++ b/pymodbus/pdu/other_message.py @@ -40,7 +40,7 @@ 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, **_kwargs): + def __init__(self, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) @@ -82,7 +82,7 @@ class ReadExceptionStatusResponse(ModbusResponse): function_code = 0x07 _rtu_frame_size = 5 - def __init__(self, status=0x00, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, status=0x00, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param status: The status response to report @@ -145,7 +145,7 @@ class GetCommEventCounterRequest(ModbusRequest): function_code_name = "get_event_counter" _rtu_frame_size = 4 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) @@ -188,7 +188,7 @@ class GetCommEventCounterResponse(ModbusResponse): function_code = 0x0B _rtu_frame_size = 8 - def __init__(self, count=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, count=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param count: The current event counter value @@ -256,7 +256,7 @@ class GetCommEventLogRequest(ModbusRequest): function_code_name = "get_event_log" _rtu_frame_size = 4 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) @@ -303,7 +303,7 @@ class GetCommEventLogResponse(ModbusResponse): function_code = 0x0C _rtu_byte_count_pos = 2 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **kwargs): + def __init__(self, status=True, message_count=0, event_count=0, events=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param status: The status response to report @@ -312,10 +312,10 @@ def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **kwar :param events: The collection of events to send """ ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) - self.status = kwargs.get("status", True) - self.message_count = kwargs.get("message_count", 0) - self.event_count = kwargs.get("event_count", 0) - self.events = kwargs.get("events", []) + self.status = status + self.message_count = message_count + self.event_count = event_count + self.events = events if events else [] def encode(self): """Encode the response. @@ -377,7 +377,7 @@ class ReportSlaveIdRequest(ModbusRequest): function_code_name = "report_slave_id" _rtu_frame_size = 4 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param slave: Modbus slave slave ID @@ -436,7 +436,7 @@ class ReportSlaveIdResponse(ModbusResponse): function_code = 0x11 _rtu_byte_count_pos = 2 - def __init__(self, identifier=b"\x00", status=True, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, identifier=b"\x00", status=True, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param identifier: The identifier of the slave diff --git a/pymodbus/pdu/register_read_message.py b/pymodbus/pdu/register_read_message.py index 58d8f9b71..c03877f94 100644 --- a/pymodbus/pdu/register_read_message.py +++ b/pymodbus/pdu/register_read_message.py @@ -22,7 +22,7 @@ class ReadRegistersRequestBase(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start the read from @@ -70,7 +70,7 @@ class ReadRegistersResponseBase(ModbusResponse): _rtu_byte_count_pos = 2 - def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The values to write to @@ -130,14 +130,14 @@ class ReadHoldingRegistersRequest(ReadRegistersRequestBase): function_code = 3 function_code_name = "read_holding_registers" - def __init__(self, address=None, count=None, slave=0, **kwargs): + def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=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, **kwargs) + super().__init__(address, count, slave, transaction, protocol, skip_encode) async def execute(self, context): """Run a read holding request against a datastore. @@ -169,12 +169,12 @@ class ReadHoldingRegistersResponse(ReadRegistersResponseBase): function_code = 3 - def __init__(self, values=None, **kwargs): + def __init__(self, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new response instance. :param values: The resulting register values """ - super().__init__(values, **kwargs) + super().__init__(values, slave, transaction, protocol, skip_encode) class ReadInputRegistersRequest(ReadRegistersRequestBase): @@ -190,14 +190,14 @@ class ReadInputRegistersRequest(ReadRegistersRequestBase): function_code = 4 function_code_name = "read_input_registers" - def __init__(self, address=None, count=None, slave=0, **kwargs): + def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=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, **kwargs) + super().__init__(address, count, slave, transaction, protocol, skip_encode) async def execute(self, context): """Run a read input request against a datastore. @@ -229,12 +229,12 @@ class ReadInputRegistersResponse(ReadRegistersResponseBase): function_code = 4 - def __init__(self, values=None, **kwargs): + def __init__(self, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new response instance. :param values: The resulting register values """ - super().__init__(values, **kwargs) + super().__init__(values, slave, transaction, protocol, skip_encode) class ReadWriteMultipleRegistersRequest(ModbusRequest): @@ -257,7 +257,7 @@ class ReadWriteMultipleRegistersRequest(ModbusRequest): function_code_name = "read_write_multiple_registers" _rtu_byte_count_pos = 10 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **kwargs): + def __init__(self, read_address=0x00, read_count=0, write_address=0x00, write_registers=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new request message. :param read_address: The address to start reading from @@ -266,10 +266,10 @@ def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False, **kwar :param write_registers: The registers to write to the specified address """ super().__init__(slave, transaction, protocol, skip_encode) - self.read_address = kwargs.get("read_address", 0x00) - self.read_count = kwargs.get("read_count", 0) - self.write_address = kwargs.get("write_address", 0x00) - self.write_registers = kwargs.get("write_registers", None) + self.read_address = read_address + self.read_count = read_count + self.write_address = write_address + self.write_registers = write_registers if not hasattr(self.write_registers, "__iter__"): self.write_registers = [self.write_registers] self.write_count = len(self.write_registers) @@ -373,7 +373,7 @@ class ReadWriteMultipleRegistersResponse(ModbusResponse): function_code = 23 _rtu_byte_count_pos = 2 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The register values to write diff --git a/pymodbus/pdu/register_write_message.py b/pymodbus/pdu/register_write_message.py index 32521acc7..18b12a51b 100644 --- a/pymodbus/pdu/register_write_message.py +++ b/pymodbus/pdu/register_write_message.py @@ -28,7 +28,7 @@ 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, **_kwargs): + def __init__(self, address=None, value=None, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance. :param address: The address to start writing add @@ -99,7 +99,7 @@ class WriteSingleRegisterResponse(ModbusResponse): function_code = 6 _rtu_frame_size = 8 - def __init__(self, address=None, value=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, value=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start writing add @@ -160,7 +160,7 @@ 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, **_kwargs): + def __init__(self, address=None, values=None, slave=None, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance. :param address: The address to start writing to @@ -247,7 +247,7 @@ class WriteMultipleRegistersResponse(ModbusResponse): function_code = 16 _rtu_frame_size = 8 - def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start writing to @@ -295,7 +295,7 @@ 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=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The mask pointer address (0x0000 to 0xffff) @@ -350,7 +350,7 @@ class MaskWriteRegisterResponse(ModbusResponse): function_code = 0x16 _rtu_frame_size = 10 - def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False, **_kwargs): + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): """Initialize new instance. :param address: The mask pointer address (0x0000 to 0xffff)