diff --git a/API_changes.rst b/API_changes.rst index 82e913b9b..50ecc7867 100644 --- a/API_changes.rst +++ b/API_changes.rst @@ -5,6 +5,8 @@ Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes! API changes 3.7.0 ----------------- +- default slave changed to 1 from 0 (which is broadcast). +- broadcast_enable, retry_on_empty, no_resend_on_retry parameters removed. - class method generate_ssl() added to TLS client (sync/async). - removed certfile, keyfile, password from TLS client, please use generate_ssl() - on_reconnect_callback() removed from clients (sync/async). diff --git a/doc/source/client.rst b/doc/source/client.rst index 9b3a6f9c4..cec456a5b 100644 --- a/doc/source/client.rst +++ b/doc/source/client.rst @@ -177,7 +177,8 @@ The physical devices are addressed with the :mod:`slave=` parameter. :mod:`slave=0` is used as broadcast in order to address all devices. However experience shows that modern devices do not allow broadcast, mostly because it is -inheriently dangerous. With :mod:`slave=0` the application can get upto 254 responses on a single request! +inheriently dangerous. With :mod:`slave=0` the application can get upto 254 responses on a single request, +and this is not handled with the normal API calls! The simple request calls (mixin) do NOT support broadcast, if an application wants to use broadcast it must call :mod:`client.execute` and deal with the responses. diff --git a/examples/client_async.py b/examples/client_async.py index 16ed44c8d..281b7792d 100755 --- a/examples/client_async.py +++ b/examples/client_async.py @@ -64,8 +64,6 @@ def setup_async_client(description=None, cmdline=None): retries=3, reconnect_delay=1, reconnect_delay_max=10, - # retry_on_empty=False, - # TCP setup parameters # source_address=("localhost", 0), ) elif args.comm == "udp": @@ -76,7 +74,6 @@ def setup_async_client(description=None, cmdline=None): framer=args.framer, timeout=args.timeout, # retries=3, - # retry_on_empty=False, # UDP setup parameters # source_address=None, ) @@ -87,7 +84,6 @@ def setup_async_client(description=None, cmdline=None): # framer=ModbusRtuFramer, timeout=args.timeout, # retries=3, - # retry_on_empty=False, # Serial setup parameters baudrate=args.baudrate, # bytesize=8, @@ -103,7 +99,6 @@ def setup_async_client(description=None, cmdline=None): framer=args.framer, timeout=args.timeout, # retries=3, - # retry_on_empty=False, # TLS setup parameters sslctx=modbusClient.AsyncModbusTlsClient.generate_ssl( certfile=helper.get_certificate("crt"), diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index b125d02e6..bc44658df 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): + def __init__(self, values=None, slave=1, 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): + def __init__(self, address=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) self.address = address @@ -100,7 +100,7 @@ def execute(self, context): class Read16CoilsRequest(ReadCoilsRequest): """Read 16 coils in one request.""" - def __init__(self, address, count=None, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from diff --git a/examples/client_sync.py b/examples/client_sync.py index 15f5b0ae1..6367306d0 100755 --- a/examples/client_sync.py +++ b/examples/client_sync.py @@ -67,7 +67,6 @@ def setup_sync_client(description=None, cmdline=None): framer=args.framer, timeout=args.timeout, # retries=3, - # retry_on_empty=False,y # TCP setup parameters # source_address=("localhost", 0), ) @@ -79,7 +78,6 @@ def setup_sync_client(description=None, cmdline=None): framer=args.framer, timeout=args.timeout, # retries=3, - # retry_on_empty=False, # UDP setup parameters # source_address=None, ) @@ -90,7 +88,6 @@ def setup_sync_client(description=None, cmdline=None): # framer=ModbusRtuFramer, timeout=args.timeout, # retries=3, - # retry_on_empty=False, # Serial setup parameters baudrate=args.baudrate, # bytesize=8, @@ -106,7 +103,6 @@ def setup_sync_client(description=None, cmdline=None): framer=args.framer, timeout=args.timeout, # retries=3, - # retry_on_empty=False, # TLS setup parameters sslctx=modbusClient.ModbusTlsClient.generate_ssl( certfile=helper.get_certificate("crt"), diff --git a/examples/contrib/solar.py b/examples/contrib/solar.py index 406f978fe..a2e951f96 100755 --- a/examples/contrib/solar.py +++ b/examples/contrib/solar.py @@ -31,7 +31,6 @@ def main(): # Common optional parameters: framer=ModbusSocketFramer, timeout=1, - retry_on_empty=True, ) client.connect() _logger.info("### Client connected") diff --git a/examples/package_test_tool.py b/examples/package_test_tool.py index 142379f17..9e1020c94 100755 --- a/examples/package_test_tool.py +++ b/examples/package_test_tool.py @@ -207,7 +207,7 @@ async def client_calls(client): """Test client API.""" Log.debug("--> Client calls starting.") try: - resp = await client.read_holding_registers(address=124, count=4, slave=0) + resp = await client.read_holding_registers(address=124, count=4, slave=1) except ModbusException as exc: txt = f"ERROR: exception in pymodbus {exc}" Log.error(txt) diff --git a/examples/simple_async_client.py b/examples/simple_async_client.py index 24c95beaa..ba377c27d 100755 --- a/examples/simple_async_client.py +++ b/examples/simple_async_client.py @@ -33,7 +33,6 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET): framer=framer, # timeout=10, # retries=3, - # retry_on_empty=False, # source_address=("localhost", 0), ) elif comm == "udp": @@ -43,7 +42,6 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET): framer=framer, # timeout=10, # retries=3, - # retry_on_empty=False, # source_address=None, ) elif comm == "serial": @@ -52,7 +50,6 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET): framer=framer, # timeout=10, # retries=3, - # retry_on_empty=False, baudrate=9600, bytesize=8, parity="N", diff --git a/examples/simple_sync_client.py b/examples/simple_sync_client.py index d2519d864..43dabd0c5 100755 --- a/examples/simple_sync_client.py +++ b/examples/simple_sync_client.py @@ -35,7 +35,6 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET): framer=framer, # timeout=10, # retries=3, - # retry_on_empty=False,y # source_address=("localhost", 0), ) elif comm == "udp": @@ -45,7 +44,6 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET): framer=framer, # timeout=10, # retries=3, - # retry_on_empty=False, # source_address=None, ) elif comm == "serial": @@ -54,7 +52,6 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET): framer=framer, # timeout=10, # retries=3, - # retry_on_empty=False, baudrate=9600, bytesize=8, parity="N", diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 0e8d5e9fa..26d7871b8 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -29,9 +29,6 @@ def __init__( self, framer: FramerType, retries: int, - retry_on_empty: bool, - broadcast_enable: bool, - no_resend_on_retry: bool, on_connect_callback: Callable[[bool], None] | None, comm_params: CommParams | None = None, ) -> None: @@ -40,14 +37,11 @@ def __init__( if comm_params: self.comm_params = comm_params self.retries = retries - self.retry_on_empty = retry_on_empty self.ctx = ModbusClientProtocol( framer, self.comm_params, on_connect_callback, ) - self.no_resend_on_retry = no_resend_on_retry - self.broadcast_enable = broadcast_enable # Common variables. self.use_udp = False @@ -119,10 +113,9 @@ async def async_execute(self, request) -> ModbusResponse: while count <= self.retries: async with self._lock: req = self.build_response(request) - if not count or not self.no_resend_on_retry: - self.ctx.framer.resetFrame() - self.ctx.send(packet) - if self.broadcast_enable and not request.slave_id: + self.ctx.framer.resetFrame() + self.ctx.send(packet) + if not request.slave_id: resp = None break try: @@ -184,9 +177,6 @@ def __init__( self, framer: FramerType, retries: int, - retry_on_empty: bool, - broadcast_enable: bool, - no_resend_on_retry: bool, comm_params: CommParams | None = None, ) -> None: """Initialize a client instance.""" @@ -194,9 +184,6 @@ def __init__( if comm_params: self.comm_params = comm_params self.retries = retries - self.broadcast_enable = bool(broadcast_enable) - self.retry_on_empty = retry_on_empty - self.no_resend_on_retry = no_resend_on_retry self.slaves: list[int] = [] # Common variables. @@ -205,7 +192,6 @@ def __init__( )(ClientDecoder(), self) self.transaction = SyncModbusTransactionManager( self, - retry_on_empty, self.retries, ) self.reconnect_delay_current = self.comm_params.reconnect_delay or 0 diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py index 7f0d710a6..e7e5c137b 100644 --- a/pymodbus/client/mixin.py +++ b/pymodbus/client/mixin.py @@ -61,7 +61,7 @@ def execute(self, _request: ModbusRequest) -> T: """ raise NotImplementedError("execute of ModbusClientMixin needs to be overridden") - def read_coils(self, address: int, count: int = 1, slave: int = 0) -> T: + def read_coils(self, address: int, count: int = 1, slave: int = 1) -> T: """Read coils (code 0x01). :param address: Start address to read from @@ -71,7 +71,7 @@ def read_coils(self, address: int, count: int = 1, slave: int = 0) -> T: """ return self.execute(pdu_bit_read.ReadCoilsRequest(address, count, slave=slave)) - def read_discrete_inputs(self, address: int, count: int = 1, slave: int = 0) -> T: + def read_discrete_inputs(self, address: int, count: int = 1, slave: int = 1) -> T: """Read discrete inputs (code 0x02). :param address: Start address to read from @@ -81,7 +81,7 @@ def read_discrete_inputs(self, address: int, count: int = 1, slave: int = 0) -> """ return self.execute(pdu_bit_read.ReadDiscreteInputsRequest(address, count, slave=slave)) - def read_holding_registers(self, address: int, count: int = 1, slave: int = 0) -> T: + def read_holding_registers(self, address: int, count: int = 1, slave: int = 1) -> T: """Read holding registers (code 0x03). :param address: Start address to read from @@ -91,7 +91,7 @@ def read_holding_registers(self, address: int, count: int = 1, slave: int = 0) - """ return self.execute(pdu_reg_read.ReadHoldingRegistersRequest(address, count, slave=slave)) - def read_input_registers(self, address: int, count: int = 1, slave: int = 0) -> T: + def read_input_registers(self, address: int, count: int = 1, slave: int = 1) -> T: """Read input registers (code 0x04). :param address: Start address to read from @@ -101,7 +101,7 @@ def read_input_registers(self, address: int, count: int = 1, slave: int = 0) -> """ return self.execute(pdu_reg_read.ReadInputRegistersRequest(address, count, slave=slave)) - def write_coil(self, address: int, value: bool, slave: int = 0) -> T: + def write_coil(self, address: int, value: bool, slave: int = 1) -> T: """Write single coil (code 0x05). :param address: Address to write to @@ -111,7 +111,7 @@ def write_coil(self, address: int, value: bool, slave: int = 0) -> T: """ return self.execute(pdu_bit_write.WriteSingleCoilRequest(address, value, slave=slave)) - def write_register(self, address: int, value: int, slave: int = 0) -> T: + def write_register(self, address: int, value: int, slave: int = 1) -> T: """Write register (code 0x06). :param address: Address to write to @@ -121,7 +121,7 @@ def write_register(self, address: int, value: int, slave: int = 0) -> T: """ return self.execute(pdu_req_write.WriteSingleRegisterRequest(address, value, slave=slave)) - def read_exception_status(self, slave: int = 0) -> T: + def read_exception_status(self, slave: int = 1) -> T: """Read Exception Status (code 0x07). :param slave: (optional) Modbus slave ID @@ -131,7 +131,7 @@ def read_exception_status(self, slave: int = 0) -> T: def diag_query_data( - self, msg: bytes, slave: int = 0) -> T: + self, msg: bytes, slave: int = 1) -> T: """Diagnose query data (code 0x08 sub 0x00). :param msg: Message to be returned @@ -141,7 +141,7 @@ def diag_query_data( return self.execute(pdu_diag.ReturnQueryDataRequest(msg, slave=slave)) def diag_restart_communication( - self, toggle: bool, slave: int = 0) -> T: + self, toggle: bool, slave: int = 1) -> T: """Diagnose restart communication (code 0x08 sub 0x01). :param toggle: True if toggled. @@ -152,7 +152,7 @@ def diag_restart_communication( pdu_diag.RestartCommunicationsOptionRequest(toggle, slave=slave) ) - def diag_read_diagnostic_register(self, slave: int = 0) -> T: + def diag_read_diagnostic_register(self, slave: int = 1) -> T: """Diagnose read diagnostic register (code 0x08 sub 0x02). :param slave: (optional) Modbus slave ID @@ -162,7 +162,7 @@ def diag_read_diagnostic_register(self, slave: int = 0) -> T: pdu_diag.ReturnDiagnosticRegisterRequest(slave=slave) ) - def diag_change_ascii_input_delimeter(self, slave: int = 0) -> T: + def diag_change_ascii_input_delimeter(self, slave: int = 1) -> T: """Diagnose change ASCII input delimiter (code 0x08 sub 0x03). :param slave: (optional) Modbus slave ID @@ -172,7 +172,7 @@ def diag_change_ascii_input_delimeter(self, slave: int = 0) -> T: pdu_diag.ChangeAsciiInputDelimiterRequest(slave=slave) ) - def diag_force_listen_only(self, slave: int = 0) -> T: + def diag_force_listen_only(self, slave: int = 1) -> T: """Diagnose force listen only (code 0x08 sub 0x04). :param slave: (optional) Modbus slave ID @@ -180,7 +180,7 @@ def diag_force_listen_only(self, slave: int = 0) -> T: """ return self.execute(pdu_diag.ForceListenOnlyModeRequest(slave=slave)) - def diag_clear_counters(self, slave: int = 0) -> T: + def diag_clear_counters(self, slave: int = 1) -> T: """Diagnose clear counters (code 0x08 sub 0x0A). :param slave: (optional) Modbus slave ID @@ -188,7 +188,7 @@ def diag_clear_counters(self, slave: int = 0) -> T: """ return self.execute(pdu_diag.ClearCountersRequest(slave=slave)) - def diag_read_bus_message_count(self, slave: int = 0) -> T: + def diag_read_bus_message_count(self, slave: int = 1) -> T: """Diagnose read bus message count (code 0x08 sub 0x0B). :param slave: (optional) Modbus slave ID @@ -198,7 +198,7 @@ def diag_read_bus_message_count(self, slave: int = 0) -> T: pdu_diag.ReturnBusMessageCountRequest(slave=slave) ) - def diag_read_bus_comm_error_count(self, slave: int = 0) -> T: + def diag_read_bus_comm_error_count(self, slave: int = 1) -> T: """Diagnose read Bus Communication Error Count (code 0x08 sub 0x0C). :param slave: (optional) Modbus slave ID @@ -208,7 +208,7 @@ def diag_read_bus_comm_error_count(self, slave: int = 0) -> T: pdu_diag.ReturnBusCommunicationErrorCountRequest(slave=slave) ) - def diag_read_bus_exception_error_count(self, slave: int = 0) -> T: + def diag_read_bus_exception_error_count(self, slave: int = 1) -> T: """Diagnose read Bus Exception Error Count (code 0x08 sub 0x0D). :param slave: (optional) Modbus slave ID @@ -218,7 +218,7 @@ def diag_read_bus_exception_error_count(self, slave: int = 0) -> T: pdu_diag.ReturnBusExceptionErrorCountRequest(slave=slave) ) - def diag_read_slave_message_count(self, slave: int = 0) -> T: + def diag_read_slave_message_count(self, slave: int = 1) -> T: """Diagnose read Slave Message Count (code 0x08 sub 0x0E). :param slave: (optional) Modbus slave ID @@ -228,7 +228,7 @@ def diag_read_slave_message_count(self, slave: int = 0) -> T: pdu_diag.ReturnSlaveMessageCountRequest(slave=slave) ) - def diag_read_slave_no_response_count(self, slave: int = 0) -> T: + def diag_read_slave_no_response_count(self, slave: int = 1) -> T: """Diagnose read Slave No Response Count (code 0x08 sub 0x0F). :param slave: (optional) Modbus slave ID @@ -238,7 +238,7 @@ def diag_read_slave_no_response_count(self, slave: int = 0) -> T: pdu_diag.ReturnSlaveNoResponseCountRequest(slave=slave) ) - def diag_read_slave_nak_count(self, slave: int = 0) -> T: + def diag_read_slave_nak_count(self, slave: int = 1) -> T: """Diagnose read Slave NAK Count (code 0x08 sub 0x10). :param slave: (optional) Modbus slave ID @@ -246,7 +246,7 @@ def diag_read_slave_nak_count(self, slave: int = 0) -> T: """ return self.execute(pdu_diag.ReturnSlaveNAKCountRequest(slave=slave)) - def diag_read_slave_busy_count(self, slave: int = 0) -> T: + def diag_read_slave_busy_count(self, slave: int = 1) -> T: """Diagnose read Slave Busy Count (code 0x08 sub 0x11). :param slave: (optional) Modbus slave ID @@ -254,7 +254,7 @@ def diag_read_slave_busy_count(self, slave: int = 0) -> T: """ return self.execute(pdu_diag.ReturnSlaveBusyCountRequest(slave=slave)) - def diag_read_bus_char_overrun_count(self, slave: int = 0) -> T: + def diag_read_bus_char_overrun_count(self, slave: int = 1) -> T: """Diagnose read Bus Character Overrun Count (code 0x08 sub 0x12). :param slave: (optional) Modbus slave ID @@ -264,7 +264,7 @@ def diag_read_bus_char_overrun_count(self, slave: int = 0) -> T: pdu_diag.ReturnSlaveBusCharacterOverrunCountRequest(slave=slave) ) - def diag_read_iop_overrun_count(self, slave: int = 0) -> T: + def diag_read_iop_overrun_count(self, slave: int = 1) -> T: """Diagnose read Iop overrun count (code 0x08 sub 0x13). :param slave: (optional) Modbus slave ID @@ -274,7 +274,7 @@ def diag_read_iop_overrun_count(self, slave: int = 0) -> T: pdu_diag.ReturnIopOverrunCountRequest(slave=slave) ) - def diag_clear_overrun_counter(self, slave: int = 0) -> T: + def diag_clear_overrun_counter(self, slave: int = 1) -> T: """Diagnose Clear Overrun Counter and Flag (code 0x08 sub 0x14). :param slave: (optional) Modbus slave ID @@ -282,7 +282,7 @@ def diag_clear_overrun_counter(self, slave: int = 0) -> T: """ return self.execute(pdu_diag.ClearOverrunCountRequest(slave=slave)) - def diag_getclear_modbus_response(self, slave: int = 0) -> T: + def diag_getclear_modbus_response(self, slave: int = 1) -> T: """Diagnose Get/Clear modbus plus (code 0x08 sub 0x15). :param slave: (optional) Modbus slave ID @@ -290,14 +290,14 @@ def diag_getclear_modbus_response(self, slave: int = 0) -> T: """ return self.execute(pdu_diag.GetClearModbusPlusRequest(slave=slave)) - def diag_get_comm_event_counter(self, slave: int = 0) -> T: + def diag_get_comm_event_counter(self, slave: int = 1) -> T: """Diagnose get event counter (code 0x0B). :raises ModbusException: """ return self.execute(pdu_other_msg.GetCommEventCounterRequest(slave=slave)) - def diag_get_comm_event_log(self, slave: int = 0) -> T: + def diag_get_comm_event_log(self, slave: int = 1) -> T: """Diagnose get event counter (code 0x0C). :raises ModbusException: @@ -308,7 +308,7 @@ def write_coils( self, address: int, values: list[bool] | bool, - slave: int = 0, + slave: int = 1, ) -> T: """Write coils (code 0x0F). @@ -322,7 +322,7 @@ def write_coils( ) def write_registers( - self, address: int, values: list[int] | int, slave: int = 0, skip_encode: bool = False) -> T: + self, address: int, values: list[int] | int, slave: int = 1, skip_encode: bool = False) -> T: """Write registers (code 0x10). :param address: Start address to write to @@ -335,7 +335,7 @@ def write_registers( pdu_req_write.WriteMultipleRegistersRequest(address, values, slave=slave, skip_encode=skip_encode) ) - def report_slave_id(self, slave: int = 0) -> T: + def report_slave_id(self, slave: int = 1) -> T: """Report slave ID (code 0x11). :param slave: (optional) Modbus slave ID @@ -343,7 +343,7 @@ def report_slave_id(self, slave: int = 0) -> T: """ return self.execute(pdu_other_msg.ReportSlaveIdRequest(slave=slave)) - def read_file_record(self, records: list[tuple], slave: int = 0) -> T: + def read_file_record(self, records: list[tuple], slave: int = 1) -> T: """Read file record (code 0x14). :param records: List of (Reference type, File number, Record Number, Record Length) @@ -352,7 +352,7 @@ def read_file_record(self, records: list[tuple], slave: int = 0) -> T: """ return self.execute(pdu_file_msg.ReadFileRecordRequest(records, slave=slave)) - def write_file_record(self, records: list[tuple], slave: int = 0) -> T: + def write_file_record(self, records: list[tuple], slave: int = 1) -> T: """Write file record (code 0x15). :param records: List of (Reference type, File number, Record Number, Record Length) @@ -366,7 +366,7 @@ def mask_write_register( address: int = 0x0000, and_mask: int = 0xFFFF, or_mask: int = 0x0000, - slave: int = 0, + slave: int = 1, ) -> T: """Mask write register (code 0x16). @@ -387,7 +387,7 @@ def readwrite_registers( write_address: int = 0, address: int | None = None, values: list[int] | int = 0, - slave: int = 0, + slave: int = 1, ) -> T: """Read/Write registers (code 0x17). @@ -412,7 +412,7 @@ def readwrite_registers( ) ) - def read_fifo_queue(self, address: int = 0x0000, slave: int = 0) -> T: + def read_fifo_queue(self, address: int = 0x0000, slave: int = 1) -> T: """Read FIFO queue (code 0x18). :param address: The address to start reading from @@ -424,7 +424,7 @@ def read_fifo_queue(self, address: int = 0x0000, slave: int = 0) -> T: # code 0x2B sub 0x0D: CANopen General Reference Request and Response, NOT IMPLEMENTED def read_device_information( - self, read_code: int | None = None, object_id: int = 0x00, slave: int = 0) -> T: + self, read_code: int | None = None, object_id: int = 0x00, slave: int = 1) -> T: """Read FIFO queue (code 0x2B sub 0x0E). :param read_code: The device information read code diff --git a/pymodbus/client/modbusclientprotocol.py b/pymodbus/client/modbusclientprotocol.py index 4412462fa..fffe822e2 100644 --- a/pymodbus/client/modbusclientprotocol.py +++ b/pymodbus/client/modbusclientprotocol.py @@ -14,14 +14,6 @@ class ModbusClientProtocol(ModbusProtocol): """**ModbusClientProtocol**. - Fixed parameters: - - :param framer: Framer enum name - :param params: Comm parameters for transport - :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param on_connect_callback: Will be called when connected/disconnected (bool parameter) - :mod:`ModbusClientProtocol` is normally not referenced outside :mod:`pymodbus`. """ @@ -76,7 +68,7 @@ def callback_data(self, data: bytes, addr: tuple | None = None) -> int: returns number of bytes consumed """ - self.framer.processIncomingPacket(data, self._handle_response, slave=0) + self.framer.processIncomingPacket(data, self._handle_response, 0) return len(data) def __str__(self): diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index a53fa305c..833c7fd41 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -44,9 +44,6 @@ class AsyncModbusSerialClient(ModbusBaseClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. :param on_reconnect_callback: Function that will be called just before a reconnection attempt. .. tip:: @@ -82,9 +79,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, on_connect_callback: Callable[[bool], None] | None = None, ) -> None: """Initialize Asyncio Modbus Serial Client.""" @@ -110,9 +104,6 @@ def __init__( # pylint: disable=too-many-arguments self, framer, retries, - retry_on_empty, - broadcast_enable, - no_resend_on_retry, on_connect_callback, ) @@ -141,9 +132,6 @@ class ModbusSerialClient(ModbusBaseSyncClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. .. tip:: **reconnect_delay** doubles automatically with each unsuccessful connect, from @@ -184,9 +172,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, ) -> None: """Initialize Modbus Serial Client.""" self.comm_params = CommParams( @@ -205,9 +190,6 @@ def __init__( # pylint: disable=too-many-arguments super().__init__( framer, retries, - retry_on_empty, - broadcast_enable, - no_resend_on_retry, ) self.socket: serial.Serial | None = None self.last_frame_end = None diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 8fcba4396..ca40ae92a 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -30,9 +30,6 @@ class AsyncModbusTcpClient(ModbusBaseClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. :param on_reconnect_callback: Function that will be called just before a reconnection attempt. .. tip:: @@ -67,9 +64,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, on_connect_callback: Callable[[bool], None] | None = None, ) -> None: """Initialize Asyncio Modbus TCP Client.""" @@ -88,9 +82,6 @@ def __init__( # pylint: disable=too-many-arguments self, framer, retries, - retry_on_empty, - broadcast_enable, - no_resend_on_retry, on_connect_callback, ) @@ -116,9 +107,6 @@ class ModbusTcpClient(ModbusBaseSyncClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. .. tip:: **reconnect_delay** doubles automatically with each unsuccessful connect, from @@ -143,7 +131,7 @@ async def run(): socket: socket.socket | None - def __init__( # pylint: disable=too-many-arguments + def __init__( self, host: str, framer: FramerType = FramerType.SOCKET, @@ -154,9 +142,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, ) -> None: """Initialize Modbus TCP Client.""" if not hasattr(self,"comm_params"): @@ -170,13 +155,7 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max=reconnect_delay_max, timeout_connect=timeout, ) - super().__init__( - framer, - retries, - retry_on_empty, - broadcast_enable, - no_resend_on_retry, - ) + super().__init__(framer, retries) self.socket = None @property diff --git a/pymodbus/client/tls.py b/pymodbus/client/tls.py index 4fac9fae7..deddd6bc2 100644 --- a/pymodbus/client/tls.py +++ b/pymodbus/client/tls.py @@ -29,9 +29,6 @@ class AsyncModbusTlsClient(AsyncModbusTcpClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. :param on_reconnect_callback: Function that will be called just before a reconnection attempt. .. tip:: @@ -65,9 +62,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, on_connect_callback: Callable[[bool], None] | None = None, ): """Initialize Asyncio Modbus TLS Client.""" @@ -87,9 +81,6 @@ def __init__( # pylint: disable=too-many-arguments "", framer=framer, retries=retries, - retry_on_empty=retry_on_empty, - broadcast_enable=broadcast_enable, - no_resend_on_retry=no_resend_on_retry, on_connect_callback=on_connect_callback, ) @@ -133,9 +124,6 @@ class ModbusTlsClient(ModbusTcpClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. .. tip:: **reconnect_delay** doubles automatically with each unsuccessful connect, from @@ -170,9 +158,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, ): """Initialize Modbus TLS Client.""" self.comm_params = CommParams( @@ -190,9 +175,6 @@ def __init__( # pylint: disable=too-many-arguments "", framer=framer, retries=retries, - retry_on_empty=retry_on_empty, - broadcast_enable=broadcast_enable, - no_resend_on_retry=no_resend_on_retry, ) @classmethod diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index 3b19708c0..48b71edab 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -31,9 +31,6 @@ class AsyncModbusUdpClient(ModbusBaseClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. :param on_reconnect_callback: Function that will be called just before a reconnection attempt. .. tip:: @@ -66,9 +63,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, on_connect_callback: Callable[[bool], None] | None = None, ) -> None: """Initialize Asyncio Modbus UDP Client.""" @@ -85,11 +79,8 @@ def __init__( # pylint: disable=too-many-arguments ModbusBaseClient.__init__( self, framer, - retries=retries, - retry_on_empty=retry_on_empty, - broadcast_enable=broadcast_enable, - no_resend_on_retry=no_resend_on_retry, - on_connect_callback=on_connect_callback, + retries, + on_connect_callback, ) self.source_address = source_address @@ -116,9 +107,6 @@ class ModbusUdpClient(ModbusBaseSyncClient): :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting. :param timeout: Timeout for a connection request, in seconds. :param retries: Max number of retries per request. - :param retry_on_empty: Retry on empty response. - :param broadcast_enable: True to treat id 0 as broadcast address. - :param no_resend_on_retry: Do not resend request when retrying due to missing response. .. tip:: **reconnect_delay** doubles automatically with each unsuccessful connect, from @@ -143,7 +131,7 @@ async def run(): socket: socket.socket | None - def __init__( # pylint: disable=too-many-arguments + def __init__( self, host: str, framer: FramerType = FramerType.SOCKET, @@ -154,9 +142,6 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - retry_on_empty: bool = False, - broadcast_enable: bool = False, - no_resend_on_retry: bool = False, ) -> None: """Initialize Modbus UDP Client.""" self.comm_params = CommParams( @@ -169,13 +154,7 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max=reconnect_delay_max, timeout_connect=timeout, ) - super().__init__( - framer, - retries=retries, - retry_on_empty=retry_on_empty, - broadcast_enable=broadcast_enable, - no_resend_on_retry=no_resend_on_retry, - ) + super().__init__(framer, retries) self.socket = None @property diff --git a/pymodbus/pdu/bit_read_message.py b/pymodbus/pdu/bit_read_message.py index 3e22de6e9..4a116dc42 100644 --- a/pymodbus/pdu/bit_read_message.py +++ b/pymodbus/pdu/bit_read_message.py @@ -138,7 +138,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): + def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from @@ -185,7 +185,7 @@ class ReadCoilsResponse(ReadBitsResponseBase): function_code = 1 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The request values to respond with @@ -206,7 +206,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): + def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start reading from @@ -253,7 +253,7 @@ class ReadDiscreteInputsResponse(ReadBitsResponseBase): function_code = 2 - def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values=None, slave=1, 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 7a7e04522..9b531d92c 100644 --- a/pymodbus/pdu/bit_write_message.py +++ b/pymodbus/pdu/bit_write_message.py @@ -113,7 +113,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): + def __init__(self, address=None, value=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The variable address written to @@ -250,7 +250,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): + def __init__(self, address=None, count=None, slave=1, 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 1966fc85b..de78c2def 100644 --- a/pymodbus/pdu/diag_message.py +++ b/pymodbus/pdu/diag_message.py @@ -31,7 +31,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): + def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a diagnostic request.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) self.message = None @@ -93,7 +93,7 @@ class DiagnosticStatusResponse(ModbusResponse): function_code = 0x08 _rtu_frame_size = 8 - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a diagnostic response.""" ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode) self.message = None @@ -150,7 +150,7 @@ class DiagnosticStatusSimpleRequest(DiagnosticStatusRequest): the execute method """ - def __init__(self, data=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a simple diagnostic request. The data defaults to 0x0000 if not provided as over half @@ -175,7 +175,7 @@ class DiagnosticStatusSimpleResponse(DiagnosticStatusResponse): 2 bytes of data. """ - def __init__(self, data=0x0000, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, data=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): """Return a simple diagnostic response. :param data: The resulting data to return to the client @@ -197,7 +197,7 @@ class ReturnQueryDataRequest(DiagnosticStatusRequest): sub_function_code = 0x0000 - def __init__(self, message=b"\x00\x00", slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, message=b"\x00\x00", slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance of the request. :param message: The message to send to loopback @@ -225,7 +225,7 @@ class ReturnQueryDataResponse(DiagnosticStatusResponse): sub_function_code = 0x0000 - def __init__(self, message=b"\x00\x00", slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, message=b"\x00\x00", slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance of the response. :param message: The message to loopback @@ -252,7 +252,7 @@ class RestartCommunicationsOptionRequest(DiagnosticStatusRequest): sub_function_code = 0x0001 - def __init__(self, toggle=False, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, toggle=False, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new request. :param toggle: Set to True to toggle, False otherwise @@ -285,7 +285,7 @@ class RestartCommunicationsOptionResponse(DiagnosticStatusResponse): sub_function_code = 0x0001 - def __init__(self, toggle=False, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, toggle=False, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new response. :param toggle: Set to True if we toggled, False otherwise @@ -396,7 +396,7 @@ class ForceListenOnlyModeResponse(DiagnosticStatusResponse): sub_function_code = 0x0004 should_respond = False - def __init__(self, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize to block a return response.""" DiagnosticStatusResponse.__init__(self, slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) self.message = [] @@ -778,7 +778,7 @@ class GetClearModbusPlusRequest(DiagnosticStatusSimpleRequest): sub_function_code = 0x0015 - def __init__(self, data=0, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, data=0, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize.""" super().__init__(slave=slave, transaction=transaction, protocol=protocol, skip_encode=skip_encode) self.message=data diff --git a/pymodbus/pdu/file_message.py b/pymodbus/pdu/file_message.py index 70f40e43c..37adbd5b6 100644 --- a/pymodbus/pdu/file_message.py +++ b/pymodbus/pdu/file_message.py @@ -89,7 +89,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): + def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read @@ -154,7 +154,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): + def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The requested file records @@ -207,7 +207,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): + def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read @@ -271,7 +271,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): + def __init__(self, records=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param records: The file record requests to be read @@ -336,7 +336,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): + def __init__(self, address=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The fifo pointer address (0x0000 to 0xffff) @@ -397,7 +397,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): + def __init__(self, values=None, slave=1, 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 60eb28435..71396bbc8 100644 --- a/pymodbus/pdu/mei_message.py +++ b/pymodbus/pdu/mei_message.py @@ -52,7 +52,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): + def __init__(self, read_code=None, object_id=0x00, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param read_code: The device information read code @@ -130,7 +130,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): + def __init__(self, read_code=None, information=None, slave=1, 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 60e55b7f1..408fb0042 100644 --- a/pymodbus/pdu/other_message.py +++ b/pymodbus/pdu/other_message.py @@ -72,7 +72,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): + def __init__(self, status=0x00, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param status: The status response to report @@ -135,7 +135,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): + def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) @@ -178,7 +178,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): + def __init__(self, count=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param count: The current event counter value @@ -246,7 +246,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): + def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance.""" ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode) @@ -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=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, status=True, message_count=0, event_count=0, events=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param status: The status response to report @@ -367,7 +367,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): + def __init__(self, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param slave: Modbus slave slave ID @@ -426,7 +426,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): + def __init__(self, identifier=b"\x00", status=True, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param identifier: The identifier of the slave diff --git a/pymodbus/pdu/pdu.py b/pymodbus/pdu/pdu.py index 47c15c8b9..67f486839 100644 --- a/pymodbus/pdu/pdu.py +++ b/pymodbus/pdu/pdu.py @@ -184,7 +184,7 @@ class ExceptionResponse(ModbusResponse): ExceptionOffset = 0x80 _rtu_frame_size = 5 - def __init__(self, function_code, exception_code=None, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, function_code, exception_code=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize the modbus exception response. :param function_code: The function to build an exception response for diff --git a/pymodbus/pdu/register_read_message.py b/pymodbus/pdu/register_read_message.py index a4280379a..ee1fd0e1a 100644 --- a/pymodbus/pdu/register_read_message.py +++ b/pymodbus/pdu/register_read_message.py @@ -14,7 +14,7 @@ class ReadRegistersRequestBase(ModbusRequest): _rtu_frame_size = 8 - def __init__(self, address, count, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, address, count, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start the read from @@ -62,7 +62,7 @@ class ReadRegistersResponseBase(ModbusResponse): _rtu_byte_count_pos = 2 - def __init__(self, values, slave=0, transaction=0, protocol=0, skip_encode=False): + def __init__(self, values, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param values: The values to write to @@ -124,7 +124,7 @@ class ReadHoldingRegistersRequest(ReadRegistersRequestBase): function_code = 3 function_code_name = "read_holding_registers" - def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance of the request. :param address: The starting address to read from @@ -184,7 +184,7 @@ class ReadInputRegistersRequest(ReadRegistersRequestBase): function_code = 4 function_code_name = "read_input_registers" - def __init__(self, address=None, count=None, slave=0, transaction=0, protocol=0, skip_encode=0): + def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=0): """Initialize a new instance of the request. :param address: The starting address to read from @@ -251,7 +251,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=0, 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, protocol=0, skip_encode=False): """Initialize a new request message. :param read_address: The address to start reading from diff --git a/pymodbus/pdu/register_write_message.py b/pymodbus/pdu/register_write_message.py index b0b67d5ea..5ee9a1c40 100644 --- a/pymodbus/pdu/register_write_message.py +++ b/pymodbus/pdu/register_write_message.py @@ -91,7 +91,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): + def __init__(self, address=None, value=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start writing add @@ -239,7 +239,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): + def __init__(self, address=None, count=None, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The address to start writing to @@ -287,7 +287,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): + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize a new instance. :param address: The mask pointer address (0x0000 to 0xffff) @@ -342,7 +342,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): + def __init__(self, address=0x0000, and_mask=0xFFFF, or_mask=0x0000, slave=1, transaction=0, protocol=0, skip_encode=False): """Initialize new instance. :param address: The mask pointer address (0x0000 to 0xffff) diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index b64c17932..ce8048604 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -133,16 +133,10 @@ class SyncModbusTransactionManager(ModbusTransactionManager): Results are keyed based on the supplied transaction id. """ - def __init__(self, client: ModbusBaseSyncClient, retry_on_empty, retries): - """Initialize an instance of the ModbusTransactionManager. - - :param client: The client socket wrapper - :param retry_on_empty: Should the client retry on empty - :param retries: The number of retries to allow - """ + def __init__(self, client: ModbusBaseSyncClient, retries): + """Initialize an instance of the ModbusTransactionManager.""" super().__init__() self.client: ModbusBaseSyncClient = client - self.retry_on_empty = retry_on_empty self.retries = retries self._transaction_lock = RLock() self._no_response_devices: list[int] = [] @@ -220,9 +214,7 @@ def execute(self, request: ModbusRequest): # noqa: C901 ): Log.debug("Clearing current Frame: - {}", _buffer) self.client.framer.resetFrame() - if broadcast := ( - self.client.broadcast_enable and not request.slave_id - ): + if broadcast := not request.slave_id: self._transact(request, None, broadcast=True) response = b"Broadcast write sent - no response expected" else: @@ -270,22 +262,8 @@ def execute(self, request: ModbusRequest): # noqa: C901 if not response: if request.slave_id not in self._no_response_devices: self._no_response_devices.append(request.slave_id) - if self.retry_on_empty: - response, last_exception = self._retry_transaction( - retries, - "empty", - request, - expected_response_length, - full=full, - ) - retries -= 1 - else: - # No response received and retries not enabled - break - else: - break - # full = False - Log.debug("Retry getting response: - {}", _buffer) + # No response received and retries not enabled + break self.client.framer.processIncomingPacket( response, self.addTransaction, diff --git a/test/framers/test_old_framers.py b/test/framers/test_old_framers.py index 165f7fc6b..56758bcb3 100644 --- a/test/framers/test_old_framers.py +++ b/test/framers/test_old_framers.py @@ -328,9 +328,6 @@ async def test_send_packet(self, rtu_framer): client = ModbusBaseClient( FramerType.ASCII, 3, - False, - False, - False, None, comm_params=CommParams( comm_type=CommType.TCP, @@ -423,9 +420,9 @@ def _handle_response(_reply): response_ok = False framer = ModbusSocketFramer(ClientDecoder()) if i: - framer.processIncomingPacket(part1, _handle_response, slave=0) + framer.processIncomingPacket(part1, _handle_response, 0) assert not response_ok, "Response should not be accepted" - framer.processIncomingPacket(part2, _handle_response, slave=0) + framer.processIncomingPacket(part2, _handle_response, 0) assert response_ok, "Response is valid, but not accepted" @@ -441,13 +438,13 @@ def _handle_response(_reply): message = bytearray(b"\x00\x02\x00\x00\x00\x03\x01\x84\x02") response_ok = False framer = ModbusSocketFramer(ClientDecoder()) - framer.processIncomingPacket(message, _handle_response, slave=0) + framer.processIncomingPacket(message, _handle_response, 0) assert response_ok, "Response is valid, but not accepted" message = bytearray(b"\x00\x01\x00\x00\x00\x0b\x01\x03\x08\x00\xb5\x12\x2f\x37\x21\x00\x03") response_ok = False framer = ModbusSocketFramer(ClientDecoder()) - framer.processIncomingPacket(message, _handle_response, slave=0) + framer.processIncomingPacket(message, _handle_response, 0) assert response_ok, "Response is valid, but not accepted" def test_recv_socket_exception_faulty(self): @@ -462,16 +459,16 @@ def _handle_response(_reply): message = bytearray(b"\x00\x02\x00\x00\x00\x02\x01\x84\x02") response_ok = False framer = ModbusSocketFramer(ClientDecoder()) - framer.processIncomingPacket(message, _handle_response, slave=0) + framer.processIncomingPacket(message, _handle_response, 0) assert response_ok, "Response is valid, but not accepted" # ---- 100% coverage @pytest.mark.parametrize( ("framer", "message"), [ - (ModbusAsciiFramer, b':00010001000AF4\r\n',), - (ModbusRtuFramer, b"\x00\x01\x00\x01\x00\n\xec\x1c",), - (ModbusSocketFramer, b'\x00\x00\x00\x00\x00\x06\x00\x01\x00\x01\x00\n',), + (ModbusAsciiFramer, b':01010001000AF3\r\n',), + (ModbusRtuFramer, b"\x01\x01\x00\x01\x00\n\xed\xcd",), + (ModbusSocketFramer, b'\x00\x00\x00\x00\x00\x06\x01\x01\x00\x01\x00\n',), ] ) def test_build_packet(self, framer, message): diff --git a/test/framers/test_tbc_transaction.py b/test/framers/test_tbc_transaction.py index 90f93c8d5..eb918727a 100755 --- a/test/framers/test_tbc_transaction.py +++ b/test/framers/test_tbc_transaction.py @@ -41,7 +41,7 @@ def setup_method(self): self._tls = ModbusTlsFramer(decoder=self.decoder, client=None) self._rtu = ModbusRtuFramer(decoder=self.decoder, client=None) self._ascii = ModbusAsciiFramer(decoder=self.decoder, client=None) - self._manager = SyncModbusTransactionManager(self.client, False, 3) + self._manager = SyncModbusTransactionManager(self.client, 3) # ----------------------------------------------------------------------- # # Modbus transaction manager @@ -109,12 +109,11 @@ def test_execute(self): request.get_response_pdu_size.return_value = 10 request.slave_id = 1 request.function_code = 222 - trans = SyncModbusTransactionManager(client, False, 3) + trans = SyncModbusTransactionManager(client, 3) trans._recv = mock.MagicMock( # pylint: disable=protected-access return_value=b"abcdef" ) assert trans.retries == 3 - assert not trans.retry_on_empty trans.getTransaction = mock.MagicMock() trans.getTransaction.return_value = "response" @@ -131,7 +130,6 @@ def test_execute(self): assert isinstance(response, ModbusIOException) # No response with retries - trans.retry_on_empty = True trans._recv = mock.MagicMock( # pylint: disable=protected-access side_effect=iter([b"", b"abcdef"]) ) @@ -143,7 +141,6 @@ def test_execute(self): side_effect=iter([b"abcdef", b"deadbe", b"123456"]) ) client.comm_params.handle_local_echo = True - trans.retry_on_empty = False assert trans.execute(request).message == "[Input/Output] Wrong local echo" client.comm_params.handle_local_echo = False @@ -164,14 +161,12 @@ def test_execute(self): assert isinstance(trans.execute(request), ModbusIOException) # Broadcast - client.params.broadcast_enable = True request.slave_id = 0 response = trans.execute(request) assert response == b"Broadcast write sent - no response expected" # Broadcast w/ Local echo client.comm_params.handle_local_echo = True - client.params.broadcast_enable = True recv = mock.MagicMock(return_value=b"deadbeef") trans._recv = recv # pylint: disable=protected-access request.slave_id = 0 diff --git a/test/sub_client/test_client.py b/test/sub_client/test_client.py index 48a042964..6111dfb59 100755 --- a/test/sub_client/test_client.py +++ b/test/sub_client/test_client.py @@ -122,16 +122,12 @@ def fake_execute(_self, request): "opt_args": { "timeout": 3 + 2, "retries": 3 + 2, - "retry_on_empty": True, - "broadcast_enable": not False, "reconnect_delay": 117, "reconnect_delay_max": 250, }, "defaults": { "timeout": 3, "retries": 3, - "retry_on_empty": False, - "broadcast_enable": False, "reconnect_delay": 100, "reconnect_delay_max": 1000 * 60 * 5, }, @@ -264,9 +260,6 @@ async def test_client_modbusbaseclient(): client = ModbusBaseClient( FramerType.ASCII, 3, - False, - False, - False, None, comm_params=CommParams( host="localhost", @@ -306,9 +299,6 @@ async def test_client_base_async(): async with ModbusBaseClient( FramerType.ASCII, 3, - False, - False, - False, None, comm_params=CommParams( host="localhost", @@ -329,9 +319,6 @@ async def test_client_protocol_receiver(): base = ModbusBaseClient( FramerType.SOCKET, 3, - False, - False, - False, None, comm_params=CommParams(), ) @@ -359,9 +346,6 @@ async def test_client_protocol_response(): base = ModbusBaseClient( FramerType.SOCKET, 3, - False, - False, - False, None, comm_params=CommParams(), ) @@ -380,9 +364,6 @@ async def test_client_protocol_handler(): base = ModbusBaseClient( FramerType.ASCII, 3, - False, - False, - False, None, comm_params=CommParams( host="localhost", @@ -439,9 +420,6 @@ async def test_client_protocol_execute(): base = ModbusBaseClient( FramerType.SOCKET, 3, - False, - False, - False, None, comm_params=CommParams( host="127.0.0.1", @@ -461,29 +439,23 @@ async def test_client_execute_broadcast(): base = ModbusBaseClient( FramerType.SOCKET, 3, - False, - False, - False, None, comm_params=CommParams( host="127.0.0.1", ), ) - base.broadcast_enable = True request = pdu_bit_read.ReadCoilsRequest(1, 1) transport = MockTransport(base, request) base.ctx.connection_made(transport=transport) - assert not await base.async_execute(request) + with pytest.raises(ModbusIOException): + assert not await base.async_execute(request) async def test_client_protocol_retry(): """Test the client protocol execute method with retries.""" base = ModbusBaseClient( FramerType.SOCKET, 3, - False, - False, - False, None, comm_params=CommParams( host="127.0.0.1", @@ -505,9 +477,6 @@ async def test_client_protocol_timeout(): base = ModbusBaseClient( FramerType.SOCKET, 2, - False, - False, - False, None, comm_params=CommParams( host="127.0.0.1", @@ -716,9 +685,6 @@ async def test_client_build_response(): client = ModbusBaseClient( FramerType.RTU, 3, - False, - False, - False, None, comm_params=CommParams(), ) diff --git a/test/sub_function_codes/test_all_messages.py b/test/sub_function_codes/test_all_messages.py index 9e20ea5ed..3454cf191 100644 --- a/test/sub_function_codes/test_all_messages.py +++ b/test/sub_function_codes/test_all_messages.py @@ -84,12 +84,12 @@ 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=0x12, transaction=0x12, protocol=0x12) + request = ReadCoilsRequest(1, 5, slave=18, transaction=0x12, protocol=0x12) assert request.slave_id == 0x12 assert request.transaction_id == 0x12 assert request.protocol_id == 0x12 request = ReadCoilsRequest(1, 5) - assert not request.slave_id + assert request.slave_id == 1 assert not request.transaction_id assert not request.protocol_id diff --git a/test/test_transaction.py b/test/test_transaction.py index 404e87fa6..e7cdc23f2 100755 --- a/test/test_transaction.py +++ b/test/test_transaction.py @@ -42,7 +42,7 @@ def setup_method(self): self._tls = ModbusTlsFramer(decoder=self.decoder, client=None) self._rtu = ModbusRtuFramer(decoder=self.decoder, client=None) self._ascii = ModbusAsciiFramer(decoder=self.decoder, client=None) - self._manager = SyncModbusTransactionManager(self.client, False, 3) + self._manager = SyncModbusTransactionManager(self.client, 3) # ----------------------------------------------------------------------- # # Modbus transaction manager @@ -112,12 +112,11 @@ def test_execute(self, mock_get_transaction, mock_recv): request.get_response_pdu_size.return_value = 10 request.slave_id = 1 request.function_code = 222 - trans = SyncModbusTransactionManager(client, False, 3) + trans = SyncModbusTransactionManager(client, 3) mock_recv.reset_mock( return_value=b"abcdef" ) assert trans.retries == 3 - assert not trans.retry_on_empty mock_get_transaction.return_value = b"response" response = trans.execute(request) @@ -132,7 +131,6 @@ def test_execute(self, mock_get_transaction, mock_recv): assert isinstance(response, ModbusIOException) # No response with retries - trans.retry_on_empty = True mock_recv.reset_mock( side_effect=iter([b"", b"abcdef"]) ) @@ -144,7 +142,6 @@ def test_execute(self, mock_get_transaction, mock_recv): side_effect=iter([b"abcdef", b"deadbe", b"123456"]) ) client.comm_params.handle_local_echo = True - trans.retry_on_empty = False assert trans.execute(request).message == "[Input/Output] Wrong local echo" client.comm_params.handle_local_echo = False @@ -165,14 +162,12 @@ def test_execute(self, mock_get_transaction, mock_recv): assert isinstance(trans.execute(request), ModbusIOException) # Broadcast - client.params.broadcast_enable = True request.slave_id = 0 response = trans.execute(request) assert response == b"Broadcast write sent - no response expected" # Broadcast w/ Local echo client.comm_params.handle_local_echo = True - client.params.broadcast_enable = True mock_recv.reset_mock(return_value=b"deadbeef") request.slave_id = 0 response = trans.execute(request)