Skip to content

Commit

Permalink
black.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Mar 21, 2023
1 parent 2f846e3 commit 252949a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
14 changes: 0 additions & 14 deletions pymodbus/framer/patched_rtuframer
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ log = logging.getLogger(__name__)


class PatchedModbusRtuFramer(ModbusRtuFramer):
def advanceToNextOccurrenceOfUnit(self, units: list[int]):
j = None
for i, b in enumerate(self._buffer):
if b in units and i > 0:
j = i
break

if j:
self._buffer = self._buffer[j:]
else:
self._buffer = b""

self._header = {"uid": 0x00, "len": 0, "crc": b"\x00\x00"}
return len(self._buffer)

def processIncomingPacket(self, data, callback, unit, **kwargs):
if not isinstance(unit, (list, tuple)):
Expand Down
18 changes: 17 additions & 1 deletion pymodbus/framer/rtu_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pylint: disable=missing-type-doc
import struct
import time
from typing import List

from pymodbus.exceptions import (
InvalidMessageReceivedException,
Expand Down Expand Up @@ -201,13 +202,28 @@ def populateResult(self, result):
result.slave_id = self._header["uid"]
result.transaction_id = self._header["uid"]

def isOurFrame(self, slaves: list[int]):
def isFrameIntendedForUs(self, slaves: List[int]):
"""Check slave ID of frame."""
try:
return self._buffer[0] in slaves
except IndexError:
return True

def advanceToNextOccurrenceOfUnit(self, slaves: List[int]):
"""Skip to next slave id."""
j = None
for i, databyte in enumerate(self._buffer):
if databyte in slaves and i > 0:
j = i
break
if j:
self._buffer = self._buffer[j:]
else:
self._buffer = b""

self._header = {"uid": 0x00, "len": 0, "crc": b"\x00\x00"}
return len(self._buffer)

# ----------------------------------------------------------------------- #
# Public Member Functions
# ----------------------------------------------------------------------- #
Expand Down

0 comments on commit 252949a

Please sign in to comment.