Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client.close should not allow reconnect= #2347

Merged
merged 2 commits into from
Sep 30, 2024
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
9 changes: 3 additions & 6 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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**).
Expand Down Expand Up @@ -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"
)
Expand Down
4 changes: 0 additions & 4 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
6 changes: 0 additions & 6 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,10 +83,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**.
Expand Down
5 changes: 0 additions & 5 deletions pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down