diff --git a/pymodbus/framer/rtu_framer.py b/pymodbus/framer/rtu_framer.py index c5fe5a616..00d555ba9 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._buffer[frame_size - 2:frame_size] @@ -137,13 +136,15 @@ def isFrameReady(self): :returns: True if ready, False otherwise """ - if len(self._buffer) > self._hsize: - if not self._header: - self.populateHeader() - return self._header and len(self._buffer) >= self._header['len'] - else: - 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 def populateHeader(self, data=None): """ @@ -163,6 +164,7 @@ def populateHeader(self, data=None): size = pdu_class.calculateRtuFrameSize(data) self._header['len'] = size self._header['crc'] = data[size - 2:size] + return size def addToFrame(self, message): """