pub struct Client<S, TX, D = NoDelay> { /* private fields */ }Expand description
Modbus RTU→TCP client.
Owns the serial port (S) and RS-485 TX-enable pin (TX). Connect to an
upstream Modbus TCP server by calling connect with a TCP stream.
The optional third parameter D is a delay provider for I/O timeouts.
It defaults to NoDelay.
§Examples
ⓘ
use modbus_bridge::{Client, BridgeError, BridgeEvent};
let mut client = Client::builder()
.rtu(uart, tx_en_pin)
.build();
// tcp_stream connects to the upstream Modbus TCP server
let mut session = client.connect(tcp_stream);
loop {
match session.next().await {
Ok(BridgeEvent::Transaction(t)) => log::info!("modbus: {t}"),
Ok(BridgeEvent::Warning(w)) => log::warn!("modbus: {w}"),
Err(BridgeError::RtuClosed) => break, // RTU master disconnected
Err(e) => { log::error!("{e}"); break; }
}
}
let tcp_stream = session.into_stream();Implementations§
Source§impl<S, TX, D> Client<S, TX, D>
impl<S, TX, D> Client<S, TX, D>
Sourcepub fn builder() -> ClientBuilder<(), (), NoDelay>
pub fn builder() -> ClientBuilder<(), (), NoDelay>
Returns a ClientBuilder for constructing a Client.
Sourcepub fn into_inner(self) -> (S, TX, D)
pub fn into_inner(self) -> (S, TX, D)
Consumes the client and returns the inner serial port, TX-enable pin, and delay provider.
Source§impl<S, TX, D> Client<S, TX, D>
impl<S, TX, D> Client<S, TX, D>
Sourcepub fn connect<TS>(&mut self, stream: TS) -> ClientSession<'_, S, TX, TS, D>
pub fn connect<TS>(&mut self, stream: TS) -> ClientSession<'_, S, TX, TS, D>
Creates a ClientSession connected to an upstream TCP server.
Takes ownership of stream and mutably borrows the client for the lifetime
of the returned ClientSession.
§Examples
ⓘ
let mut session = client.connect(tcp_stream);
loop {
match session.next().await {
Ok(event) => { /* handle event */ }
Err(_) => break,
}
}
let tcp_stream = session.into_stream();Auto Trait Implementations§
impl<S, TX, D> Freeze for Client<S, TX, D>
impl<S, TX, D> RefUnwindSafe for Client<S, TX, D>
impl<S, TX, D> Send for Client<S, TX, D>
impl<S, TX, D> Sync for Client<S, TX, D>
impl<S, TX, D> Unpin for Client<S, TX, D>
impl<S, TX, D> UnsafeUnpin for Client<S, TX, D>
impl<S, TX, D> UnwindSafe for Client<S, TX, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more