Skip to main content

RtuApplicationLayer

Struct RtuApplicationLayer 

Source
pub struct RtuApplicationLayer { /* private fields */ }

Implementations§

Source§

impl RtuApplicationLayer

Source

pub fn new<P: PhysicalLayer + 'static>( physical: Arc<P>, options: RtuApplicationLayerOptions, ) -> Arc<Self>

Build an RTU application layer bound to physical.

Options (all optional; see RtuApplicationLayerOptions for defaults):

  • interval_between_frames — overrides the default 3.5T computation.
    • FrameInterval::Bits(n)n bit-times (default 38.5 = 3.5 char times).
    • FrameInterval::Ms(n) — explicit milliseconds.
    • On serial with None: baud > 19200 → 1.75 ms (spec fix), else ceil((38.5 * 1000) / baud).
  • inter_char_timeout — opt-in t1.5. Disabled by default. Same units. On serial: baud > 19200 → 0.75 ms, else ceil((16.5 * 1000) / baud).
  • baud_rate — defaults to 9600 for Serial. Ignored on Net.
Source

pub fn add_custom_function_code(&self, cfc: CustomFunctionCode)

Register a custom function code predictor. Required for any non-standard FC; without registration the frame is rejected with a framing error.

Source

pub fn remove_custom_function_code(&self, fc: u8)

Trait Implementations§

Source§

impl ApplicationLayer for RtuApplicationLayer

Source§

fn set_role(&self, role: ApplicationRole) -> Result<(), ModbusError>

Bind the application layer to a master/slave role. Must succeed on the first call and fail (ModbusError::InvalidState) if a different role is then assigned. Re-assigning the same role is a no-op (idempotent).
Source§

fn role(&self) -> Option<ApplicationRole>

Current role, or None if not yet assigned.
Source§

fn protocol(&self) -> ApplicationProtocol

Wire protocol implemented by this layer. Used by ModbusMaster to validate concurrent configuration at construction time.
Source§

fn encode(&self, adu: &ApplicationDataUnit) -> Vec<u8>

Encode an ADU into wire bytes per the protocol’s framing format (MBAP for TCP, CRC for RTU, hex+LRC for ASCII).
Source§

fn decode(&self, data: &[u8]) -> Result<FramedDataUnit, ModbusError>

Decode a single complete frame back into an ADU. Returned only for backward compatibility with the previous stateless API; new consumers should subscribe to subscribe_framing instead.
Source§

fn flush(&self)

Drop any per-connection state (decoding buffers, timers). Called by Master before each request, by Slave between sessions.
Source§

fn subscribe_framing(&self) -> Receiver<Framing>

Subscribe to successfully framed PDUs assembled from the underlying physical layer.
Source§

fn subscribe_framing_error(&self) -> Receiver<ModbusError>

Subscribe to framing-level errors (CRC/LRC failure, invalid MBAP header, etc.). One error per offending physical-layer chunk.
Source§

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

Release task handles and drop physical-layer subscriptions.
Source§

fn add_custom_function_code(&self, _cfc: CustomFunctionCode)

Register a custom function code predictor. Default is a no-op; only RtuApplicationLayer overrides this with real behavior.
Source§

fn remove_custom_function_code(&self, _fc: u8)

Remove a previously registered custom function code. Default is a no-op.

Auto Trait Implementations§

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.