Skip to content

Commit

Permalink
Solve serial unrequested frame. (#2219)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Jun 14, 2024
1 parent 98d1d4a commit 14ec87e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pymodbus/framer/old_framer_rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def is_frame_ready(self):
try:
self._header["uid"] = int(self._buffer[0])
self._header["tid"] = int(self._buffer[0])
self._header["tid"] = 0 # fix for now
func_code = int(self._buffer[1])
pdu_class = self.decoder.lookupPduClass(func_code)
size = pdu_class.calculateRtuFrameSize(self._buffer)
Expand Down Expand Up @@ -117,6 +118,7 @@ def check_frame(self):
try:
self._header["uid"] = int(self._buffer[0])
self._header["tid"] = int(self._buffer[0])
self._header["tid"] = 0 # fix for now
func_code = int(self._buffer[1])
pdu_class = self.decoder.lookupPduClass(func_code)
size = pdu_class.calculateRtuFrameSize(self._buffer)
Expand Down
4 changes: 3 additions & 1 deletion pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ def getTransaction(self, tid):
Log.debug("Getting transaction {}", tid)
if not tid:
if self.transactions:
return self.transactions.popitem()[1]
ret = self.transactions.popitem()[1]
self.transactions.clear()
return ret
return None
return self.transactions.pop(tid, None)

Expand Down
4 changes: 2 additions & 2 deletions test/framers/test_old_framers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def callback(data):
"crc": b"\x49\xAD",
"uid": 17,
"len": 11,
"tid": 17,
"tid": 0,
},
),
(
Expand All @@ -225,7 +225,7 @@ def callback(data):
"crc": b"\x49\xAD",
"uid": 17,
"len": 11,
"tid": 17,
"tid": 0,
},
),
],
Expand Down

0 comments on commit 14ec87e

Please sign in to comment.