Skip to content

Commit

Permalink
clarify handle_local_echo. (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Jul 20, 2023
1 parent dfe487b commit ae7551f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 0 additions & 2 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ async def async_execute(self, request=None):
"""Execute requests asynchronously."""
request.transaction_id = self.transaction.getNextTID()
packet = self.framer.buildPacket(request)
Log.debug("send: {}", packet, ":hex")
self.transport_send(packet)
req = self._build_response(request.transaction_id)
if self.params.broadcast_enable and not request.slave_id:
Expand Down Expand Up @@ -217,7 +216,6 @@ def callback_data(self, data: bytes, addr: tuple = None) -> int:
returns number of bytes consumed
"""
Log.debug("recv: {} addr={}", data, ":hex", addr)
self.framer.processIncomingPacket(data, self._handle_response, slave=0)
return len(data)

Expand Down
11 changes: 3 additions & 8 deletions pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,15 @@ def data_received(self, data: bytes):
:param data: non-empty bytes object with incoming data.
"""
Log.debug("recv: {}", data, ":hex")
if self.comm_params.handle_local_echo and self.sent_buffer == data:
self.sent_buffer = b""
return
self.recv_buffer += data
cut = self.callback_data(self.recv_buffer)
self.recv_buffer = self.recv_buffer[cut:]
self.datagram_received(data, None)

def datagram_received(self, data: bytes, addr: tuple):
"""Receive datagram (UDP connections)."""
Log.debug("recv: {} addr={}", data, ":hex", addr)
if self.comm_params.handle_local_echo and self.sent_buffer == data:
Log.debug("recv skipping (local_echo): {} addr={}", data, ":hex", addr)
self.sent_buffer = b""
return
Log.debug("recv: {} addr={}", data, ":hex", addr)
self.recv_buffer += data
cut = self.callback_data(self.recv_buffer, addr=addr)
self.recv_buffer = self.recv_buffer[cut:]
Expand Down

0 comments on commit ae7551f

Please sign in to comment.