Skip to main content

Crate oms_modbus

Crate oms_modbus 

Source
Expand description

OMS Modbus — high-performance, transport-generic Modbus library in pure Rust.

Complete Master (client) and Slave (server) for TCP, RTU, and ASCII — all through a single unified API. Passive bus-level WireTap with microsecond timestamps, auto-reconnect with USB serial resilience, and spec-compliant RS-485 bus timing.

§Quick start

use oms_modbus::*;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use std::time::Duration;

let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0);
let server = tcp::TcpServer::bind(addr).await?;
let bind_addr = server.local_addr()?;
let store = Arc::new(SlaveStore::with_holding_registers(&[(0, 1234)]));
tokio::spawn(async move { server.serve_forever(store).await.ok(); });

let client = tcp::TcpClient::connect_with_timeout(
    bind_addr, Duration::from_secs(3),
).await?;
let regs = client.read_holding_registers(1, 0, 1).await?;

§Key types

TypeDescription
ModbusClientMaster (client) trait — TCP, RTU, ASCII share this API
SlaveStoreDefault Slave (server) — in-memory register/coil store
ServiceTrait for custom server backends
ClientOptionsBuilder: timeout, capture, reconnect, bus timing
BusCaptureRecording + statistics — implements WireTap
WireTapPassive bus observer — implement for custom capture
BusTimingRS-485 frame spacing — per Modbus Serial Spec
ModbusErrorStructured error — Display, detail(), label()

§Examples

See the examples directory for 14 runnable examples covering TCP, RTU, ASCII, monitoring, reconnect, custom services, and bus timing.

Re-exports§

pub use codec::calculate_crc;
pub use codec::calculate_lrc;
pub use reconnect::ReconnectConfig;
pub use bus_timing::BusTiming;
pub use capture::BusCapture;
pub use client::ModbusClient;
pub use error::ModbusError;
pub use frame::Exception;
pub use frame::ExceptionResponse;
pub use frame::FunctionCode;
pub use frame::Request;
pub use frame::Response;
pub use intercept::format_timestamp;
pub use intercept::PacketCapture;
pub use intercept::PacketData;
pub use intercept::PacketRecord;
pub use intercept::TrafficStats;
pub use options::ClientOptions;
pub use server::Service;
pub use server::HookedService;
pub use server::ServerHook;
pub use slave_store::SlaveStore;
pub use wire_tap::now_micros;
pub use wire_tap::WireTap;

Modules§

ascii
bus_timing
Bus frame spacing — enforces minimum silence between Modbus frames.
capture
BusCapture — unified recording + statistics backend.
client
Modbus client (master) trait.
codec
Modbus codecs — RTU (CRC-16) and ASCII (LRC) framing.
error
Modbus error types and message constants.
frame
Modbus frame types — Request, Response, Exception, FunctionCode.
intercept
Packet data types for Modbus traffic capture.
monitor
Recording backends — in-memory, file, channel, and user-extensible.
options
Shared client options — capture, reconnect, timeout.
reconnect
Auto-reconnect configuration for all transports.
rtu
server
Modbus server (slave) service trait.
slave_store
In-memory Modbus slave register store.
tcp
transport
Transport implementations — TCP, RTU, ASCII clients and servers.
wire_tap
Passive bus observer — attached to the physical transport via SniffIo.