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>
impl<const ASCII: bool> StdSerialTransport<ASCII>
Sourcepub fn available_ports() -> Result<Vec<SerialPortInfo>, Error>
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>
impl<const ASCII: bool> Debug for StdSerialTransport<ASCII>
Source§impl<const ASCII: bool> Default for StdSerialTransport<ASCII>
impl<const ASCII: bool> Default for StdSerialTransport<ASCII>
Source§impl<const ASCII: bool> Transport for StdSerialTransport<ASCII>
impl<const ASCII: bool> Transport for StdSerialTransport<ASCII>
Source§fn disconnect(&mut self) -> Result<(), Self::Error>
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 recv(&mut self) -> Result<Vec<u8, MAX_ADU_FRAME_LEN>, Self::Error>
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
fn is_connected(&self) -> bool
Checks if the transport is currently connected to a remote host.
Source§const SUPPORTS_BROADCAST_WRITES: bool = true
const SUPPORTS_BROADCAST_WRITES: bool = true
Source§const TRANSPORT_TYPE: TransportType
const TRANSPORT_TYPE: TransportType
Source§type Error = TransportError
type Error = TransportError
MbusError for upper-layer processing.