Skip to content

Commit 6ecccd8

Browse files
committed
Solve serial unrequested frame. (#2219)
1 parent 750f3c7 commit 6ecccd8

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pymodbus/framer/rtu_framer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def is_frame_ready(self):
8282
try:
8383
self._header["uid"] = int(self._buffer[0])
8484
self._header["tid"] = int(self._buffer[0])
85+
self._header["tid"] = 0 # fix for now
8586
func_code = int(self._buffer[1])
8687
pdu_class = self.decoder.lookupPduClass(func_code)
8788
size = pdu_class.calculateRtuFrameSize(self._buffer)
@@ -119,6 +120,7 @@ def check_frame(self):
119120
try:
120121
self._header["uid"] = int(self._buffer[0])
121122
self._header["tid"] = int(self._buffer[0])
123+
self._header["tid"] = 0 # fix for now
122124
func_code = int(self._buffer[1])
123125
pdu_class = self.decoder.lookupPduClass(func_code)
124126
size = pdu_class.calculateRtuFrameSize(self._buffer)

pymodbus/transaction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ def getTransaction(self, tid):
460460
Log.debug("Getting transaction {}", tid)
461461
if not tid:
462462
if self.transactions:
463-
return self.transactions.popitem()[1]
463+
ret = self.transactions.popitem()[1]
464+
self.transactions.clear()
465+
return ret
464466
return None
465467
return self.transactions.pop(tid, None)
466468

test/test_framers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def callback(data):
223223
"crc": b"\x49\xAD",
224224
"uid": 17,
225225
"len": 11,
226-
"tid": 17,
226+
"tid": 0,
227227
},
228228
),
229229
(
@@ -232,7 +232,7 @@ def callback(data):
232232
"crc": b"\x49\xAD",
233233
"uid": 17,
234234
"len": 11,
235-
"tid": 17,
235+
"tid": 0,
236236
},
237237
),
238238
],

0 commit comments

Comments
 (0)