Skip to content

Commit

Permalink
Simplify syncTransactionManager. (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Nov 8, 2024
1 parent d137c6e commit a38899d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 364 deletions.
8 changes: 5 additions & 3 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,16 @@ def recv(self, size: int | None) -> bytes:
time_ = time.time()

# If size isn't specified continue to read until timeout expires.
if size:
recv_size = size - data_length

if not size:
break
# Timeout is reduced also if some data has been received in order
# to avoid infinite loops when there isn't an expected response
# size and the slave sends noisy data continuously.
if time_ > end:
break

recv_size = size - data_length

self.last_frame_end = round(time.time(), 6)
return b"".join(data)

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def recv(self, size: int | None) -> bytes:
if not self.socket:
raise ConnectionException(str(self))
if size is None:
size = 0
size = 4096
data = self.socket.recvfrom(size)[0]
self.last_frame_end = round(time.time(), 6)
return data
Expand Down
10 changes: 8 additions & 2 deletions pymodbus/framer/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ class FramerTLS(FramerBase):
"""Modbus TLS frame type.
Layout::
[ Function Code] [ Data ]
1b Nb
[ MBAP Header ] [ Function Code] [ Data ]
[ tid ][ pid ][ length ][ uid ]
2b 2b 2b 1b 1b Nb
length = uid + function code + data
"""

MIN_SIZE = 8

def decode(self, data: bytes) -> tuple[int, int, int, bytes]:
"""Decode MDAP+PDU."""
tid = int.from_bytes(data[0:2], 'big')
Expand Down
Loading

0 comments on commit a38899d

Please sign in to comment.