Skip to main content

StdSerialTransport

Struct StdSerialTransport 

Source
pub struct StdSerialTransport<const ASCII: bool = false> { /* private fields */ }
Expand description

A concrete implementation of Transport for Serial communication using serialport crate.

The const generic ASCII selects the framing mode at compile time:

  • false → Modbus RTU (binary + CRC)
  • true → Modbus ASCII (: delimited + LRC)

Prefer the type aliases StdRtuTransport and StdAsciiTransport.

Implementations§

Source§

impl<const ASCII: bool> StdSerialTransport<ASCII>

Source

pub fn new() -> Self

Creates a new StdSerialTransport instance.

Source

pub fn available_ports() -> Result<Vec<SerialPortInfo>, Error>

Returns a list of available serial ports on the system. This can be useful for allowing a user to select a port.

Trait Implementations§

Source§

impl<const ASCII: bool> Debug for StdSerialTransport<ASCII>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const ASCII: bool> Default for StdSerialTransport<ASCII>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const ASCII: bool> Transport for StdSerialTransport<ASCII>

Source§

fn connect(&mut self, config: &ModbusConfig) -> Result<(), Self::Error>

Establishes a connection to the specified serial port.

§Arguments
  • config - The ModbusConfig containing the serial port configuration. This must be the ModbusConfig::Serial variant.
§Returns

Ok(()) if the connection is successfully established, or an error otherwise.

Source§

fn disconnect(&mut self) -> Result<(), Self::Error>

Closes the active serial port connection.

If no connection is active, this operation does nothing and returns Ok(()).

Source§

fn send(&mut self, adu: &[u8]) -> Result<(), Self::Error>

Sends a Modbus Application Data Unit (ADU) over the serial port.

§Arguments
  • adu - The byte slice representing the ADU to send.
§Returns

Ok(()) if the ADU is successfully sent, or an error otherwise.

Source§

fn recv(&mut self) -> Result<Vec<u8, MAX_ADU_FRAME_LEN>, Self::Error>

Receives a Modbus Application Data Unit (ADU) from the serial port.

This implementation is non-blocking: it checks the serial port’s input buffer and reads only the bytes currently available. If no bytes are available, it returns TransportError::Timeout.

§Returns

Ok(Vec<u8, MAX_ADU_FRAME_LEN>) containing the received ADU, or an error otherwise.

Source§

fn is_connected(&self) -> bool

Checks if the transport is currently connected to a remote host.

Source§

const SUPPORTS_BROADCAST_WRITES: bool = true

Compile-time capability flag for Serial-style broadcast write semantics. Read more
Source§

const TRANSPORT_TYPE: TransportType

Compile-time transport type metadata. Read more
Source§

type Error = TransportError

The specific error type returned by this transport implementation. It must be convertible into the common MbusError for upper-layer processing.
Source§

fn transport_type_rt(&self) -> TransportType

Runtime transport type accessor. Read more

Auto Trait Implementations§

§

impl<const ASCII: bool = false> !RefUnwindSafe for StdSerialTransport<ASCII>

§

impl<const ASCII: bool = false> !Sync for StdSerialTransport<ASCII>

§

impl<const ASCII: bool = false> !UnwindSafe for StdSerialTransport<ASCII>

§

impl<const ASCII: bool> Freeze for StdSerialTransport<ASCII>

§

impl<const ASCII: bool> Send for StdSerialTransport<ASCII>

§

impl<const ASCII: bool> Unpin for StdSerialTransport<ASCII>

§

impl<const ASCII: bool> UnsafeUnpin for StdSerialTransport<ASCII>

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.