Skip to main content

Crate mbrtu

Crate mbrtu 

Source
Expand description

A no_std, allocation-free parser and encoder for Modbus RTU, the serial-line PDU encoding used by industrial PLCs, sensors, and other field devices.

§Layering

  • frame parses/encodes the raw address/function-code/data/CRC-16 framing.
  • crc is Modbus RTU’s CRC-16 checksum.
  • message decodes/encodes a frame’s data into a typed ModbusRequest or ModbusResponse, one variant per supported function code.

§No allocation

Nothing in this crate uses alloc.

Re-exports§

pub use error::MbrtuError;
pub use frame::Frame;
pub use message::ModbusRequest;
pub use message::ModbusResponse;

Modules§

crc
Modbus RTU’s CRC-16 (poly 0xA001, the reflected form of 0x8005, init 0xFFFF), computed over the address, function code, and data of a frame. Cross-checked against pymodbus’s own compute_CRC.
error
Error types for every layer of the decode/encode pipeline.
frame
Raw Modbus RTU frame parsing and encoding.
message
Function-code-dispatched decoding/encoding of a frame’s data into a typed ModbusRequest or ModbusResponse.

Functions§

decode_request
Parses a single frame from buf and decodes it as a request PDU (see the message module docs on why direction is a caller-supplied fact, not something recoverable from the bytes alone).
decode_response
Parses a single frame from buf and decodes it as a response PDU.
encode_request
Encodes a request PDU into a full frame in buf, returning the number of bytes written.
encode_response
Encodes a response PDU into a full frame in buf, returning the number of bytes written.