1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: MIT OR Apache-2.0
//! 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
//!
//! ```no_run
//! use oms_modbus::*;
//! use std::net::{IpAddr, Ipv4Addr, SocketAddr};
//! use std::sync::Arc;
//! use std::time::Duration;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! 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?;
//! # Ok(())
//! # }
//! ```
//!
//! # Key types
//!
//! | Type | Description |
//! |------|-------------|
//! | [`ModbusClient`] | Master (client) trait — TCP, RTU, ASCII share this API |
//! | [`SlaveStore`] | Default Slave (server) — in-memory register/coil store |
//! | [`Service`] | Trait for custom server backends |
//! | [`ClientOptions`] | Builder: timeout, capture, reconnect, bus timing |
//! | [`BusCapture`] | Recording + statistics — implements [`WireTap`] |
//! | [`WireTap`] | Passive bus observer — implement for custom capture |
//! | [`BusTiming`] | RS-485 frame spacing — per Modbus Serial Spec |
//! | [`ModbusError`] | Structured error — `Display`, `detail()`, `label()` |
//!
//! # Examples
//!
//! See the [examples directory](https://github.com/orangehorsetech/oms-modbus/tree/master/examples)
//! for 14 runnable examples covering TCP, RTU, ASCII, monitoring, reconnect,
//! custom services, and bus timing.
pub use calculate_crc;
pub use calculate_lrc;
pub use ReconnectConfig;
pub use BusTiming;
pub use BusCapture;
pub use ModbusClient;
pub use ModbusError;
pub use ;
pub use ;
pub use ClientOptions;
pub use Service;
pub use ;
pub use SlaveStore;
pub use ;