Skip to content

Commit

Permalink
Broadcast with Handle Local Echo (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsgunth authored Aug 16, 2023
1 parent e11fe6b commit 85890dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def _transact(self, packet, response_length, full=False, broadcast=False):
)
self.client.state = ModbusTransactionState.PROCESSING_REPLY
return size, None
if self.client.comm_params.handle_local_echo is True:
if self._recv(size, full) != packet:
return b"", "Wrong local echo"
if broadcast:
if size:
Log.debug(
Expand All @@ -310,9 +313,6 @@ def _transact(self, packet, response_length, full=False, broadcast=False):
'to "WAITING FOR REPLY"'
)
self.client.state = ModbusTransactionState.WAITING_FOR_REPLY
if self.client.comm_params.handle_local_echo is True:
if self._recv(size, full) != packet:
return b"", "Wrong local echo"
result = self._recv(response_length, full)
# result2 = self._recv(response_length, full)
Log.debug("RECV: {}", result, ":hex")
Expand Down
12 changes: 12 additions & 0 deletions test/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ def test_execute(self, mock_time):
response = trans.execute(request)
assert response == b"Broadcast write sent - no response expected"

# Broadcast w/ Local echo
client.comm_params.handle_local_echo = True
client.params.broadcast_enable = True
recv = trans._recv = mock.MagicMock( # pylint: disable=protected-access
return_value=b"deadbeef"
)
request.slave_id = 0
response = trans.execute(request)
assert response == b"Broadcast write sent - no response expected"
recv.assert_called_once_with(8, False)
client.comm_params.handle_local_echo = False

# ----------------------------------------------------------------------- #
# Dictionary based transaction manager
# ----------------------------------------------------------------------- #
Expand Down

0 comments on commit 85890dc

Please sign in to comment.