Skip to content

Commit 14ec87e

Browse files
authored
Solve serial unrequested frame. (#2219)
1 parent 98d1d4a commit 14ec87e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pymodbus/framer/old_framer_rtu.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def is_frame_ready(self):
8080
try:
8181
self._header["uid"] = int(self._buffer[0])
8282
self._header["tid"] = int(self._buffer[0])
83+
self._header["tid"] = 0 # fix for now
8384
func_code = int(self._buffer[1])
8485
pdu_class = self.decoder.lookupPduClass(func_code)
8586
size = pdu_class.calculateRtuFrameSize(self._buffer)
@@ -117,6 +118,7 @@ def check_frame(self):
117118
try:
118119
self._header["uid"] = int(self._buffer[0])
119120
self._header["tid"] = int(self._buffer[0])
121+
self._header["tid"] = 0 # fix for now
120122
func_code = int(self._buffer[1])
121123
pdu_class = self.decoder.lookupPduClass(func_code)
122124
size = pdu_class.calculateRtuFrameSize(self._buffer)

pymodbus/transaction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ def getTransaction(self, tid):
453453
Log.debug("Getting transaction {}", tid)
454454
if not tid:
455455
if self.transactions:
456-
return self.transactions.popitem()[1]
456+
ret = self.transactions.popitem()[1]
457+
self.transactions.clear()
458+
return ret
457459
return None
458460
return self.transactions.pop(tid, None)
459461

test/framers/test_old_framers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def callback(data):
216216
"crc": b"\x49\xAD",
217217
"uid": 17,
218218
"len": 11,
219-
"tid": 17,
219+
"tid": 0,
220220
},
221221
),
222222
(
@@ -225,7 +225,7 @@ def callback(data):
225225
"crc": b"\x49\xAD",
226226
"uid": 17,
227227
"len": 11,
228-
"tid": 17,
228+
"tid": 0,
229229
},
230230
),
231231
],

0 commit comments

Comments
 (0)