Skip to main content

Client

Struct Client 

Source
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>

Source

pub fn builder() -> ClientBuilder<(), (), NoDelay>

Returns a ClientBuilder for constructing a Client.

Source

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>
where S: Read + Write, TX: OutputPin,

Source

pub fn connect<TS>(&mut self, stream: TS) -> ClientSession<'_, S, TX, TS, D>
where TS: Read + Write,

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>
where D: Freeze, S: Freeze, TX: Freeze,

§

impl<S, TX, D> RefUnwindSafe for Client<S, TX, D>

§

impl<S, TX, D> Send for Client<S, TX, D>
where D: Send, S: Send, TX: Send,

§

impl<S, TX, D> Sync for Client<S, TX, D>
where D: Sync, S: Sync, TX: Sync,

§

impl<S, TX, D> Unpin for Client<S, TX, D>
where D: Unpin, S: Unpin, TX: Unpin,

§

impl<S, TX, D> UnsafeUnpin for Client<S, TX, D>

§

impl<S, TX, D> UnwindSafe for Client<S, TX, D>
where D: UnwindSafe, S: UnwindSafe, TX: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.