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

Fix too many sync client log messages. #2491

Merged
merged 1 commit into from
Dec 8, 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
1 change: 0 additions & 1 deletion pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def __init__(
self.state = ModbusTransactionState.IDLE
self.last_frame_end: float | None = 0
self.silent_interval: float = 0
self.transport = None

# ----------------------------------------------------------------------- #
# Client external interface
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def generate_ssl(
@property
def connected(self) -> bool:
"""Connect internal."""
return self.transport is not None
return self.socket is not None

def connect(self):
"""Connect to the modbus tls server."""
Expand Down
6 changes: 2 additions & 4 deletions pymodbus/transaction/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ def sync_execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbus
REMARK: this method is identical to execute, apart from the lock and sync_receive.
any changes in either method MUST be mirrored !!!
"""
if not self.transport:
Log.warning("Not connected, trying to connect!")
if not self.sync_client.connect():
raise ConnectionException("Client cannot connect (automatic retry continuing) !!")
if not self.sync_client.connect():
raise ConnectionException("Client cannot connect (automatic retry continuing) !!")
with self._sync_lock:
request.transaction_id = self.getNextTID()
count_retries = 0
Expand Down
2 changes: 1 addition & 1 deletion test/client/test_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_basic_syn_tls_client(self, mock_select):
assert client.recv(1) == b"\x45"

# connect/disconnect
assert not client.connected
assert client.connected
assert client.connect()
client.close()

Expand Down
3 changes: 3 additions & 0 deletions test/transaction/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def test_sync_transaction_receiver(self, use_clc):
None,
sync_client=client,
)
transact.sync_client.connect = mock.Mock(return_value=True)
transact.sync_client.send = mock.Mock()
request = ReadCoilsRequest(address=117, count=5)
response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False])
Expand Down Expand Up @@ -366,6 +367,7 @@ def test_sync_client_protocol_execute_outside(self, use_clc, no_resp):
None,
sync_client=client,
)
transact.sync_client.connect = mock.Mock(return_value=True)
request = ReadCoilsRequest(address=117, count=5)
response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False])
transact.retries = 0
Expand Down Expand Up @@ -400,6 +402,7 @@ def test_sync_client_protocol_execute_no_pdu(self, use_clc):
None,
sync_client=client,
)
transact.sync_client.connect = mock.Mock(return_value=True)
request = ReadCoilsRequest(address=117, count=5)
response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False])
transact.retries = 0
Expand Down