Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions API_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down
12 changes: 0 additions & 12 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**).

Expand Down
10 changes: 1 addition & 9 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import socket
import time
from collections.abc import Callable

from pymodbus.client.base import ModbusBaseClient, ModbusBaseSyncClient
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 2 additions & 14 deletions test/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 0 additions & 7 deletions test/client/test_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down