Skip to main content

DataLink

Trait DataLink 

Source
pub trait DataLink: Send + Sync {
    // Required method
    fn exchange<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        unit_id: UnitId,
        request_pdu: &'life1 [u8],
        response_pdu: &'life2 mut [u8],
    ) -> Pin<Box<dyn Future<Output = Result<usize, DataLinkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn reconnect<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), DataLinkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn is_connected(&self) -> bool { ... }
}
Expand description

Async transport abstraction for Modbus request/response exchanges.

Implementations handle framing (TCP MBAP or RTU CRC) and wire I/O. The client crate uses this trait to remain transport-agnostic.

Required Methods§

Source

fn exchange<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, unit_id: UnitId, request_pdu: &'life1 [u8], response_pdu: &'life2 mut [u8], ) -> Pin<Box<dyn Future<Output = Result<usize, DataLinkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send a request PDU to a unit and write the response PDU into response_pdu.

Returns the number of response bytes written to response_pdu.

Provided Methods§

Source

fn reconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), DataLinkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempt to re-establish the underlying connection.

Called by the client before retrying after a transport error. The default implementation is a no-op (suitable for transports that do not support reconnection or for mock implementations).

Source

fn is_connected(&self) -> bool

Check if the transport is connected.

The default implementation always returns true.

Implementors§