diff --git a/pymodbus/framer/rtu_framer.py b/pymodbus/framer/rtu_framer.py index 2cc8fe164e..2a73f78418 100644 --- a/pymodbus/framer/rtu_framer.py +++ b/pymodbus/framer/rtu_framer.py @@ -86,7 +86,6 @@ def checkFrame(self): 2. Discard frame if UID does not match """ try: - self.populateHeader() frame_size = self._header["len"] data = self._buffer[: frame_size - 2] crc = self._header["crc"] @@ -131,16 +130,15 @@ def isFrameReady(self): :returns: True if ready, False otherwise """ - if len(self._buffer) <= self._hsize: - return False - try: - # Frame is ready only if populateHeader() successfully - # populates crc field which finishes RTU frame otherwise, - # if buffer is not yet long enough, populateHeader() raises IndexError - self.populateHeader() - except IndexError: - return False + size = self._header.get('len', 0) + if size == 0 and len(self._buffer) > self._hsize: + try: + size = self.populateHeader() + except IndexError: + return False + + return len(self._buffer) >= size if size > 0 else False return True @@ -164,6 +162,7 @@ def populateHeader(self, data=None): # pylint: disable=invalid-name # crc yet not available raise IndexError self._header["crc"] = data[size - 2 : size] + return size def addToFrame(self, message): """Add the received data to the buffer handle.