Skip to content

Commit 6233706

Browse files
pazzarpjdhoomakethu
authored andcommitted
Task Cancellation and CRC Errors
Alternate solution for #356 and #360. Changes the RTU to make the transaction ID as the unit ID instead of an ever incrementing number. Previously this transaction ID was always 0 on the receiving end but was the unique transaction ID on sending. As such the FIFO buffer made the most sense. By tying it to the unit ID, we can recover from failure modes such as: - - Asyncio task cancellations (eg. timeouts) #360 - Skipped responses from slaves. (hangs on master #360) - CRC Errors #356 - Busy response
1 parent 7650421 commit 6233706

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pymodbus/client/sync.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ def __init__(self, framer, **kwargs):
3939
:param framer: The modbus framer implementation to use
4040
"""
4141
self.framer = framer
42-
if isinstance(self.framer, ModbusSocketFramer):
43-
self.transaction = DictTransactionManager(self, **kwargs)
44-
else:
45-
self.transaction = FifoTransactionManager(self, **kwargs)
42+
self.transaction = DictTransactionManager(self, **kwargs)
4643
self._debug = False
4744
self._debugfd = None
4845
self.broadcast_enable = kwargs.get('broadcast_enable', Defaults.broadcast_enable)

pymodbus/framer/rtu_framer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def populateResult(self, result):
191191
:param result: The response packet
192192
"""
193193
result.unit_id = self._header['uid']
194+
result.transaction_id = self._header['uid']
194195

195196
# ----------------------------------------------------------------------- #
196197
# Public Member Functions
@@ -227,6 +228,9 @@ def processIncomingPacket(self, data, callback, unit, **kwargs):
227228
_logger.debug("Not a valid unit id - {}, "
228229
"ignoring!!".format(self._header['uid']))
229230
self.resetFrame()
231+
else:
232+
_logger.debug("Frame check failed, ignoring!!")
233+
self.resetFrame()
230234
else:
231235
_logger.debug("Frame - [{}] not ready".format(data))
232236

@@ -241,6 +245,7 @@ def buildPacket(self, message):
241245
message.unit_id,
242246
message.function_code) + data
243247
packet += struct.pack(">H", computeCRC(packet))
248+
message.transaction_id = message.unit_id # Ensure that transaction is actually the unit id for serial comms
244249
return packet
245250

246251
def sendPacket(self, message):

0 commit comments

Comments
 (0)