diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index a91efc618c..63cf8732bc 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -130,7 +130,7 @@ def __init__( # pylint: disable=too-many-arguments ) self.reconnect_delay = self.params.reconnect_delay self.reconnect_delay_current = self.params.reconnect_delay - self.use_protocol = False + self.use_sync = False self.use_udp = False self.state = ModbusTransactionState.IDLE self.last_frame_end: float = 0 @@ -175,13 +175,13 @@ def execute(self, request: ModbusRequest = None) -> ModbusResponse: :returns: The result of the request execution :raises ConnectionException: Check exception text. """ - if self.use_protocol: - if not self.transport: - raise ConnectionException(f"Not connected[{str(self)}]") - return self.async_execute(request) - if not self.connect(): - raise ConnectionException(f"Failed to connect[{str(self)}]") - return self.transaction.execute(request) + if self.use_sync: + if not self.connect(): + raise ConnectionException(f"Failed to connect[{str(self)}]") + return self.transaction.execute(request) + if not self.transport: + raise ConnectionException(f"Not connected[{str(self)}]") + return self.async_execute(request) # ----------------------------------------------------------------------- # # Merged client methods diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index beefdd112c..20224a6da3 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -61,7 +61,6 @@ def __init__( ) -> None: """Initialize Asyncio Modbus Serial Client.""" super().__init__(framer=framer, **kwargs) - self.use_protocol = True self.params.port = port self.params.baudrate = baudrate self.params.bytesize = bytesize @@ -158,6 +157,7 @@ def __init__( self.params.stopbits = stopbits self.params.handle_local_echo = handle_local_echo self.socket = None + self.use_sync = True self.last_frame_end = None diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 52ab59ad65..df77724c60 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -47,7 +47,6 @@ def __init__( ) -> None: """Initialize Asyncio Modbus TCP Client.""" super().__init__(framer=framer, **kwargs) - self.use_protocol = True self.params.host = host self.params.port = port self.params.source_address = source_address @@ -140,6 +139,7 @@ def __init__( self.params.port = port self.params.source_address = source_address self.socket = None + self.use_sync = True @property def connected(self): diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index 1d7ef71cb6..112e7da3e7 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -50,7 +50,6 @@ def __init__( ) -> None: """Initialize Asyncio Modbus UDP Client.""" super().__init__(framer=framer, **kwargs) - self.use_protocol = True self.params.host = host self.params.port = port self.params.source_address = source_address @@ -138,6 +137,7 @@ def __init__( self.params.source_address = source_address self.socket = None + self.use_sync = True def connect(self): # pylint: disable=invalid-overridden-method """Connect to the modbus tcp server.