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
//! Async transport abstraction — parallel to the sync [`Transport`](super::Transport) trait.
//!
//! Enabled by the `async` feature flag. No new dependencies are required; `async fn`
//! desugars to `core::future::Future` which is always available in `no_std` environments.
use crateMAX_ADU_FRAME_LEN;
use crateMbusError;
use crateTransportType;
use Future;
use Vec;
/// Async transport abstraction for Modbus communication.
///
/// This trait is the async parallel of the sync [`Transport`](super::Transport) trait.
/// Implementations live in `mbus-network` (`TokioTcpTransport`) and `mbus-serial`
/// (`TokioRtuTransport`, `TokioAsciiTransport`) behind their respective `async` feature flags.
///
/// # Framing contract
///
/// Unlike the sync `Transport::recv()` which returns whatever bytes are available,
/// `AsyncTransport::recv()` **must not return until exactly one complete ADU is ready**:
///
/// - **TCP**: reads the 6-byte MBAP prefix, parses the length field, then reads exactly that
/// many remaining bytes. Always returns a complete, valid-length frame.
/// - **Serial RTU**: accumulates bytes and returns when the inter-frame silence timer fires
/// (3.5 character times). The timer resets on every received byte.
/// The timer is only started after the first byte arrives — silence before any data
/// is not treated as a frame boundary.
/// - **Serial ASCII**: accumulates bytes until the `\r\n` terminator is found.
///
/// # Send bounds
///
/// Both `send` and `recv` return futures that are `Send`, enabling their use with
/// `tokio::spawn` without boxing. Implementations using `async fn` syntax are accepted
/// by the compiler as long as all captured state is `Send`.