Function rmodbus::guess_request_frame_len[][src]

pub fn guess_request_frame_len(
    frame: &[u8],
    proto: ModbusProto
) -> Result<u8, ErrorKind>

Guess request frame length

Frames are often read byte-by-byte. The function allows to guess total frame length, having first 7 (or more) bytes read.

How to use: read at least first 7 bytes (16 for ASCII) into buffer and call the function to guess the total frame length. The remaining amount of bytes to read will be function result - 7. 8 bytes is also fine, as that’s the minimal correct frame length.

  • the function will panic if the buffer length is less than 7 (for ASCII - 16)

  • the function may return wrong result for broken frames

  • the function may return ErrorKind::FrameBroken for broken ASCII frames