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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//! # Voltage Modbus - High-Performance Industrial Modbus Library
//!
//! **Author:** Evan Liu <liuyifanz.1996@gmail.com>
//! **Version:** 0.4.3
//! **License:** MIT
//!
//! A comprehensive, high-performance Modbus TCP/RTU implementation in pure Rust
//! designed for industrial automation, IoT applications, and smart grid systems.
//!
//! ## Features
//!
//! - **High Performance**: Async/await support with Tokio, stack-allocated PDU
//! - **Complete Protocol Support**: Modbus TCP and RTU protocols
//! - **Memory Safe**: Pure Rust implementation with zero unsafe code
//! - **Zero-Copy Operations**: Optimized for minimal memory allocations
//! - **Industrial Features**: Command batching, read merging, device limits
//! - **Built-in Monitoring**: Comprehensive statistics and metrics
//! - **no_std Core**: PDU/protocol layer usable on embedded MCUs (disable default features)
//!
//! ## Supported Function Codes
//!
//! | Code | Function | Client |
//! |------|----------|--------|
//! | 0x01 | Read Coils | ✅ |
//! | 0x02 | Read Discrete Inputs | ✅ |
//! | 0x03 | Read Holding Registers | ✅ |
//! | 0x04 | Read Input Registers | ✅ |
//! | 0x05 | Write Single Coil | ✅ |
//! | 0x06 | Write Single Register | ✅ |
//! | 0x0F | Write Multiple Coils | ✅ |
//! | 0x10 | Write Multiple Registers | ✅ |
//!
//! ## Quick Start (std)
//!
//! ```rust,no_run
//! use voltage_modbus::{ModbusTcpClient, ModbusClient, ModbusResult};
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> ModbusResult<()> {
//! // Connect to Modbus TCP server
//! let mut client = ModbusTcpClient::from_address("127.0.0.1:502", Duration::from_secs(5)).await?;
//!
//! // Read holding registers
//! let values = client.read_03(1, 0, 10).await?;
//! println!("Read registers: {:?}", values);
//!
//! // Write single register
//! client.write_06(1, 100, 0x1234).await?;
//!
//! client.close().await?;
//! Ok(())
//! }
//! ```
//!
//! ## no_std Usage (embedded)
//!
//! Add to `Cargo.toml`:
//! ```toml
//! voltage_modbus = { version = "...", default-features = false }
//! ```
//!
//! Then use the core PDU/protocol modules without any std dependency:
//!
//! ```rust,no_run
//! use voltage_modbus::pdu::PduBuilder;
//! use voltage_modbus::constants::MAX_PDU_SIZE;
//!
//! // Build a read-holding-registers request PDU
//! let pdu = PduBuilder::build_read_request(0x03, 100, 10).unwrap();
//! let raw_bytes = pdu.as_slice(); // &[u8] — send over your transport
//! ```
// ============================================================================
// no_std support
// ============================================================================
extern crate alloc;
// ============================================================================
// Core modules — always available (no_std compatible)
// ============================================================================
/// Modbus protocol constants based on official specification
/// Core error types and result handling
/// High-performance PDU with stack-allocated fixed array
/// Modbus protocol definitions and message handling
// ============================================================================
// std-only modules — require async runtime, heap collections, or OS APIs
// ============================================================================
/// Network transport layer for TCP and RTU communication
/// Modbus client implementations
/// Utility functions and performance monitoring
/// Logging system for the library
// ============================================================================
// Industrial enhancement modules (std-only)
// ============================================================================
/// Industrial data value types for Modbus
/// Byte order handling for multi-register data types
/// Encoding and decoding of Modbus data with byte order support
/// Command batching for optimized write operations
/// Read coalescing for merging adjacent/overlapping register read requests
/// Device-specific protocol limits configuration
// ============================================================================
// Re-exports for convenience
// ============================================================================
// === Core protocol — always available (no_std compatible) ===
pub use ;
pub use ;
pub use ;
pub use ;
// === std-only re-exports ===
pub use tokio;
pub use ;
pub use ByteOrder;
pub use ModbusValue;
pub use ;
pub use ;
pub use ModbusCodec;
pub use DeviceLimits;
pub use ;
pub use ;
pub use PerformanceMetrics;
pub use ;
// === Hidden but preserved (backward compatibility, std-only) ===
pub use ;
pub use ;
pub use ;
pub use ;
pub use OperationTimer;
pub use ModbusRtuClient;
pub use RtuTransport;
/// Default timeout for operations (5 seconds)
pub const DEFAULT_TIMEOUT_MS: u64 = 5000;
/// Modbus TCP default port
pub const DEFAULT_TCP_PORT: u16 = 502;
/// Library version
pub const VERSION: &str = env!;
/// Get library information (std only — requires String allocation)