From e96bec02eeb16da4d48b1ea60c5b9ba2c69f6b1a Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 14 Jun 2024 13:13:38 +0200 Subject: [PATCH] Solve serial unrequested frame. --- pymodbus/framer/old_framer_rtu.py | 2 ++ pymodbus/transaction.py | 4 +++- test/framers/test_old_framers.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pymodbus/framer/old_framer_rtu.py b/pymodbus/framer/old_framer_rtu.py index a57fd75da..024dba269 100644 --- a/pymodbus/framer/old_framer_rtu.py +++ b/pymodbus/framer/old_framer_rtu.py @@ -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) @@ -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) diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index 13f84e31a..9aa614e82 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -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) diff --git a/test/framers/test_old_framers.py b/test/framers/test_old_framers.py index e7b394701..39bc5035b 100644 --- a/test/framers/test_old_framers.py +++ b/test/framers/test_old_framers.py @@ -216,7 +216,7 @@ def callback(data): "crc": b"\x49\xAD", "uid": 17, "len": 11, - "tid": 17, + "tid": 0, }, ), ( @@ -225,7 +225,7 @@ def callback(data): "crc": b"\x49\xAD", "uid": 17, "len": 11, - "tid": 17, + "tid": 0, }, ), ],