Crates.io | modbus_buffer |
lib.rs | modbus_buffer |
version | 0.0.2 |
source | src |
created_at | 2024-04-29 13:42:46.273317 |
updated_at | 2024-04-29 13:45:43.025841 |
description | Circular buffer implementation tailored for Modbus communication in no_std environments. |
homepage | |
repository | https://github.com/pythcoiner/modbus_buffer |
max_upload_size | |
id | 1224183 |
size | 20,613 |
ModbusBuffer
is a Rust crate providing a circular buffer implementation tailored for Modbus communication.
It's designed to handle the buffering of Modbus frames efficiently, with features such as configurable frame length
and optional data overwriting when the buffer is full.
This crate is especially useful in systems where no standard library is available (i.e., no_std
environments).
The initial purpose of this crate was to allow decoding Modbus stream over RS485 without care out the silences
.
Add this to your Cargo.toml
:
[dependencies]
modbus_buffer = "0.0.2"
use modbus_buffer::ModbusBuffer;
fn main() {
let mut buffer = ModbusBuffer::<16>::new()
.min_frame_len(3)
.max_frame_len(8)
.overwrite(true);
// start receiving data in the middle of a request
buffer.push(0xCD); // value
buffer.push(0x9F); // crc
buffer.push(0xBE); // crc
// Receive a second request
buffer.push(0x12); // unit address
buffer.push(0x06); // fn code
buffer.push(0x22); // addr
buffer.push(0x22); // addr
buffer.push(0xAB); // value
buffer.push(0xCD); // value
buffer.push(0x9F); // crc
buffer.push(0xBE); // crc
let mut output = [0u8; 16];
// Here, the 'noise' from previous request will be dropped and the second request detected
let len = buff.try_decode_frame(&mut output);
}
Contributions are welcome! Please feel free to submit pull requests or create issues if you find bugs or have suggestions for improvements.