Skip to content

Commit

Permalink
change use_protocol to use_sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed May 31, 2023
1 parent 23ff820 commit ff18161
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ff18161

Please sign in to comment.