Skip to content

Commit fde1232

Browse files
author
sanjay
committed
Merge branch 'pull/471' into dev
2 parents ce19705 + ea4705e commit fde1232

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pymodbus/client/sync.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def __init__(self, method='ascii', **kwargs):
539539
:param timeout: The timeout between serial requests (default 3s)
540540
:param strict: Use Inter char timeout for baudrates <= 19200 (adhere
541541
to modbus standards)
542+
:param handle_local_echo: Handle local echo of the USB-to-RS485 adaptor
542543
"""
543544
self.method = method
544545
self.socket = None
@@ -553,6 +554,7 @@ def __init__(self, method='ascii', **kwargs):
553554
self.timeout = kwargs.get('timeout', Defaults.Timeout)
554555
self._strict = kwargs.get("strict", True)
555556
self.last_frame_end = None
557+
self.handle_local_echo = kwargs.get("handle_local_echo", False)
556558
if self.method == "rtu":
557559
if self.baudrate > 19200:
558560
self.silent_interval = 1.75 / 1000 # ms

pymodbus/transaction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def _transact(self, packet, response_length, full=False, broadcast=False):
228228
_logger.debug("Changing transaction state from 'SENDING' "
229229
"to 'WAITING FOR REPLY'")
230230
self.client.state = ModbusTransactionState.WAITING_FOR_REPLY
231+
if self.client.handle_local_echo is True:
232+
local_echo_packet = self._recv(size, full)
233+
if local_echo_packet != packet:
234+
return b'', "Wrong local echo"
231235
result = self._recv(response_length, full)
232236
if _logger.isEnabledFor(logging.DEBUG):
233237
_logger.debug("RECV: " + hexlify_packets(result))

0 commit comments

Comments
 (0)