diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 26d7871b87..9675a6afa8 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -78,10 +78,8 @@ def register(self, custom_response_class: ModbusResponse) -> None: def close(self, reconnect: bool = False) -> None: """Close connection.""" - if reconnect: - self.ctx.connection_lost(asyncio.TimeoutError("Server not responding")) - else: - self.ctx.close() + print("Reconnect " + str(reconnect)) + self.ctx.close() def idle_time(self) -> float: """Time before initiating next transaction (call **sync**). @@ -126,7 +124,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" )