diff --git a/API_changes.rst b/API_changes.rst index 403dd1836..0c00e1d4e 100644 --- a/API_changes.rst +++ b/API_changes.rst @@ -5,6 +5,7 @@ Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes! API changes 3.12.0 ------------------ - when using no_response_expected=, the call returns None +- remove idle_time() from sync client since it is void API changes 3.11.0 ------------------ diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 099a9d956..8a28a212e 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -160,8 +160,6 @@ def __init__( ) self.reconnect_delay_current = self.comm_params.reconnect_delay or 0 self.use_udp = False - self.last_frame_end: float | None = 0 - self.silent_interval: float = 0 # ----------------------------------------------------------------------- # # Client external interface @@ -177,16 +175,6 @@ def register(self, custom_response_class: type[ModbusPDU]) -> None: """ self.framer.decoder.register(custom_response_class) - def idle_time(self) -> float: - """Time before initiating next transaction (call **sync**). - - Applications can call message functions without checking idle_time(), - this is done automatically. - """ - if self.last_frame_end is None or self.silent_interval is None: - return 0 - return self.last_frame_end + self.silent_interval - def execute(self, no_response_expected: bool, request: ModbusPDU) -> ModbusPDU: """Execute request and get response (call **sync/async**). diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index 84faced4e..791781d99 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -206,7 +206,6 @@ def __init__( # pylint: disable=too-many-arguments trace_connect, ) self.socket: serial.Serial | None = None - self.last_frame_end = None self._t0 = float(1 + bytesize + stopbits) / baudrate # Check every 4 bytes / 2 registers if the reading is ready @@ -215,13 +214,8 @@ def __init__( # pylint: disable=too-many-arguments self._recv_interval = max(self._recv_interval, 0.001) self.inter_byte_timeout: float = 0 - self.silent_interval: float = 0 - if baudrate > 19200: - self.silent_interval = 1.75 / 1000 # ms - else: + if baudrate <= 19200: self.inter_byte_timeout = 1.5 * self._t0 - self.silent_interval = 3.5 * self._t0 - self.silent_interval = round(self.silent_interval, 6) @property def connected(self) -> bool: @@ -243,7 +237,6 @@ def connect(self) -> bool: exclusive=True, ) self.socket.inter_byte_timeout = self.inter_byte_timeout - self.last_frame_end = None # except serial.SerialException as msg: # pyserial raises undocumented exceptions like termios except Exception as msg: # pylint: disable=broad-exception-caught @@ -303,7 +296,6 @@ def recv(self, size: int | None) -> bytes: if size > self._in_waiting(): self._wait_for_data() result = self.socket.read(size) - self.last_frame_end = round(time.time(), 6) return result def is_socket_open(self) -> bool: diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index dfd77f1a7..d45390b7b 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -275,8 +275,6 @@ def recv(self, size: int | None) -> bytes: break recv_size = size - data_length - - self.last_frame_end = round(time.time(), 6) return b"".join(data) def _handle_abrupt_socket_close(self, size: int | None, data: list[bytes], duration: float) -> bytes: diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index f5e9fbdc7..7b8740dcf 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -2,7 +2,6 @@ from __future__ import annotations import socket -import time from collections.abc import Callable from pymodbus.client.base import ModbusBaseClient, ModbusBaseSyncClient @@ -228,7 +227,6 @@ def recv(self, size: int | None) -> bytes: if size is None: size = 4096 data = self.socket.recvfrom(size)[0] - self.last_frame_end = round(time.time(), 6) return data def is_socket_open(self): diff --git a/test/client/test_client.py b/test/client/test_client.py index 506f434d9..791595c96 100755 --- a/test/client/test_client.py +++ b/test/client/test_client.py @@ -424,11 +424,6 @@ async def test_client_instanciate( **cur_args["opt_args"], ) - # Test information methods - client.last_frame_end = 2 - client.silent_interval = 2 - client.last_frame_end = None - # a successful execute client.transaction = mock.Mock(**{"execute.return_value": True}) @@ -633,20 +628,13 @@ class CustomRequest: # pylint: disable=too-few-public-methods client.register(CustomRequest) client.framer.decoder.register.assert_called_once_with(CustomRequest) - def test_idle_time(self): - """Test idle_time().""" - client = lib_client.ModbusTcpClient("127.0.0.1") - assert not client.idle_time() - client.last_frame_end = None - assert not client.idle_time() - def test_sync_block(self): - """Test idle_time().""" + """Test sync block.""" with lib_client.ModbusTcpClient("127.0.0.1") as client: assert not client.connected def test_sync_execute(self): - """Test idle_time().""" + """Test sync execute.""" client = lib_client.ModbusTcpClient("127.0.0.1") client.connect = mock.Mock(return_value=False) with pytest.raises(ConnectionException): diff --git a/test/client/test_client_sync.py b/test/client/test_client_sync.py index 24a1526e7..0f0ff1acc 100755 --- a/test/client/test_client_sync.py +++ b/test/client/test_client_sync.py @@ -282,13 +282,6 @@ def test_sync_serial_client_instantiation(self): FramerRTU, ) - def test_sync_serial_rtu_client_timeouts(self): - """Test sync serial rtu.""" - client = ModbusSerialClient("/dev/null", framer=FramerType.RTU, baudrate=9600) - assert client.silent_interval == round((3.5 * 10 / 9600), 6) - client = ModbusSerialClient("/dev/null", framer=FramerType.RTU, baudrate=38400) - assert client.silent_interval == round((1.75 / 1000), 6) - @mock.patch("serial.Serial") def test_basic_sync_serial_client(self, mock_serial): """Test the basic methods for the serial sync client."""