From a0db420159fee0545dd2cf025d3b2e2a2532311e Mon Sep 17 00:00:00 2001 From: jan iversen Date: Mon, 30 Sep 2024 12:59:11 +0200 Subject: [PATCH 1/2] Remove reconnect= from client.close(). --- pymodbus/client/base.py | 9 +++------ pymodbus/client/serial.py | 4 ---- pymodbus/client/tcp.py | 4 ---- pymodbus/client/udp.py | 5 ----- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index cf03882d4..06bbe0a1f 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -79,12 +79,9 @@ def register(self, custom_response_class: ModbusResponse) -> None: """ self.ctx.framer.decoder.register(custom_response_class) - def close(self, reconnect: bool = False) -> None: + def close(self) -> None: """Close connection.""" - if reconnect: - self.ctx.connection_lost(asyncio.TimeoutError("Server not responding")) - else: - self.ctx.close() + self.ctx.close() def execute(self, request: ModbusRequest): """Execute request and get response (call **sync/async**). @@ -124,7 +121,7 @@ async def async_execute(self, request) -> ModbusResponse: except asyncio.exceptions.TimeoutError: count += 1 if count > self.retries: - self.close(reconnect=True) + self.ctx.connection_lost(asyncio.TimeoutError("Server not responding")) raise ModbusIOException( f"ERROR: No response received after {self.retries} retries" ) diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index 2da85a2ba..9e3814b84 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -102,10 +102,6 @@ def __init__( # pylint: disable=too-many-arguments on_connect_callback, ) - def close(self, reconnect: bool = False) -> None: - """Close connection.""" - super().close(reconnect=reconnect) - class ModbusSerialClient(ModbusBaseSyncClient): """**ModbusSerialClient**. diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 0a431a5d2..7b1e4f6bd 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -85,10 +85,6 @@ def __init__( # pylint: disable=too-many-arguments on_connect_callback, ) - def close(self, reconnect: bool = False) -> None: - """Close connection.""" - super().close(reconnect=reconnect) - class ModbusTcpClient(ModbusBaseSyncClient): """**ModbusTcpClient**. diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index 23c6db759..296d1ae46 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -84,11 +84,6 @@ def __init__( # pylint: disable=too-many-arguments ) self.source_address = source_address - @property - def connected(self): - """Return true if connected.""" - return self.ctx.is_active() - class ModbusUdpClient(ModbusBaseSyncClient): """**ModbusUdpClient**. From 804e24631aa6b6674c48aa8bb76004ce52a6944f Mon Sep 17 00:00:00 2001 From: jan iversen Date: Mon, 30 Sep 2024 13:37:19 +0200 Subject: [PATCH 2/2] remove socket. --- pymodbus/client/tcp.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 7b1e4f6bd..0f6f0de44 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -51,8 +51,6 @@ async def run(): Please refer to :ref:`Pymodbus internals` for advanced usage. """ - socket: socket.socket | None - def __init__( # pylint: disable=too-many-arguments self, host: str,