-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from pymodbus.framer.rtu_framer import ModbusRtuFramer | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class PatchedModbusRtuFramer(ModbusRtuFramer): | ||
|
||
def processIncomingPacket(self, data, callback, unit, **kwargs): | ||
if not isinstance(unit, (list, tuple)): | ||
unit = [unit] | ||
self.addToFrame(data) | ||
single = kwargs.get("single", False) | ||
while True: | ||
if not self.isFrameIntendedForUs(unit): | ||
if self.advanceToNextOccurrenceOfUnit(unit) == 0: | ||
log.info(f"❌ Frame - [{data}] not intended for us, ignoring!!") | ||
break | ||
elif self.isFrameReady(): | ||
if self.checkFrame(): | ||
if self._validate_unit_id(unit, single): | ||
self._process(callback) | ||
log.info(f"✅ Frame - [{data}] responded to!!") | ||
else: | ||
header_txt = self._header["uid"] | ||
log.info(f"Not a valid unit id - {header_txt}, ignoring!!") | ||
self.resetFrame() | ||
break | ||
else: | ||
log.info("Frame check failed, ignoring!!") | ||
if self.advanceToNextOccurrenceOfUnit(unit) == 0: | ||
break | ||
else: | ||
log.info(f"Frame - [{data}] not ready") | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters