When using this library against a Modbus/RTU server, I have a problem that usually the client is faster processing the response than the server is supplying it. Because ModbusRtuFramer.header_size is set to 1, the block at transaction.py:111 only reads a single byte before switching to the state FramerState.ReadingContent. In the process, the call to self.framer.check_frame() at line 123 fails, as not enough data has been read to know how long the frame is (at least for frames that encode their own size within the frame).
To fix this, I've added a check while in the FramerState.ReadingContent state: If size == 0, indicating that the whole expected frame has been read, it calls self.framer.check_frame() again. This is because size could be zero because the whole frame has been read, or it could be zero because we don't yet know how big the frame should be; in this case, the subsequent recalculation of size at line 141 will either increase size substantially (in the case where we now know how long the frame should be) or by 1, in the case where we still don't know how long the frame should be (because in this case self.framer.get_frame_size() returns however much it's read so far + 1).
When using this library against a Modbus/RTU server, I have a problem that usually the client is faster processing the response than the server is supplying it. Because
ModbusRtuFramer.header_size
is set to 1, the block at transaction.py:111 only reads a single byte before switching to the stateFramerState.ReadingContent
. In the process, the call toself.framer.check_frame()
at line 123 fails, as not enough data has been read to know how long the frame is (at least for frames that encode their own size within the frame).To fix this, I've added a check while in the
FramerState.ReadingContent
state: Ifsize == 0
, indicating that the whole expected frame has been read, it callsself.framer.check_frame()
again. This is becausesize
could be zero because the whole frame has been read, or it could be zero because we don't yet know how big the frame should be; in this case, the subsequent recalculation ofsize
at line 141 will either increasesize
substantially (in the case where we now know how long the frame should be) or by 1, in the case where we still don't know how long the frame should be (because in this caseself.framer.get_frame_size()
returns however much it's read so far + 1).