pub struct SerialConnection { /* private fields */ }Expand description
Implementations§
Source§impl SerialConnection
impl SerialConnection
Sourcepub async fn open(config: ConnectionConfig) -> Result<Self>
pub async fn open(config: ConnectionConfig) -> Result<Self>
Open a serial port using the supplied configuration.
Sourcepub fn from_io(port: String, io: Box<dyn SerialIo>) -> Self
pub fn from_io(port: String, io: Box<dyn SerialIo>) -> Self
Build a connection from an arbitrary SerialIo backend. Used by
tests to inject an in-memory duplex stream.
pub fn from_io_with_config( config: ConnectionConfig, io: Box<dyn SerialIo>, ) -> Self
pub fn id(&self) -> &str
pub fn port(&self) -> &str
pub fn name(&self) -> Option<&str>
pub fn baud_rate(&self) -> u32
pub fn flow_control(&self) -> FlowControl
pub fn data_bits(&self) -> DataBits
pub fn stop_bits(&self) -> StopBits
pub fn parity(&self) -> Parity
Sourcepub fn port_info(&self) -> Option<&PortInfo>
pub fn port_info(&self) -> Option<&PortInfo>
Return the OS-level port identity captured at open time.
Sourcepub fn tx_framing_default(&self) -> Option<TxFramingConfig>
pub fn tx_framing_default(&self) -> Option<TxFramingConfig>
Default TX framing stored on the connection (from profile or open).
Returns by value (cloned from interior mutex for live mutation).
Sourcepub fn rx_framing_default(&self) -> Option<RxFramingConfig>
pub fn rx_framing_default(&self) -> Option<RxFramingConfig>
Default RX framing stored on the connection.
Sourcepub fn rx_parser_default(&self) -> Option<ParserConfig>
pub fn rx_parser_default(&self) -> Option<ParserConfig>
Default RX parser stored on the connection.
Sourcepub fn protocol_default(&self) -> Option<ProtocolPreset>
pub fn protocol_default(&self) -> Option<ProtocolPreset>
Default protocol preset stored on the connection. Copy, so returned by value.
Lock internal mutex for live mutation via configure.
Sourcepub fn max_buffered_bytes_default(&self) -> usize
pub fn max_buffered_bytes_default(&self) -> usize
Default max buffered bytes for read operations. Mutable live.
Sourcepub fn active_profile_binding(&self) -> Option<ActiveProfileBinding>
pub fn active_profile_binding(&self) -> Option<ActiveProfileBinding>
The active profile-session binding, if this connection was opened through a public open path.
Sourcepub fn rx_buffer_size(&self) -> usize
pub fn rx_buffer_size(&self) -> usize
The effective RX ring buffer size configured at open time.
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
Return the current connection health state.
Sourcepub async fn mark_disconnected(&self, error_message: String)
pub async fn mark_disconnected(&self, error_message: String)
Mark the connection as disconnected due to a fatal I/O error. Takes the io handle out (sets to None), cancels in-flight operations, and clears RX buffers.
Sourcepub async fn reconnect(&self) -> Result<()>
pub async fn reconnect(&self) -> Result<()>
Attempt to re-establish the serial port connection.
Rebuilds a SerialStream from the stored config and replaces the
current io handle in place. Preserves all counters, id, name,
and log buffer. Called by auto-reconnect tasks and the reconnect
tool.
Sourcepub fn record_tx_bytes(&self, n: usize)
pub fn record_tx_bytes(&self, n: usize)
Record n bytes written to the device.
Sourcepub fn record_rx_bytes(&self, n: usize)
pub fn record_rx_bytes(&self, n: usize)
Record n bytes read from the device.
Sourcepub fn last_activity_ms(&self) -> Option<u64>
pub fn last_activity_ms(&self) -> Option<u64>
Return the last I/O activity as milliseconds since Unix epoch.
Sourcepub fn record_read_op(&self)
pub fn record_read_op(&self)
Record one successful read-pipeline operation (read, transact read
half, or capture_boot).
Sourcepub fn record_write_op(&self)
pub fn record_write_op(&self)
Record one successful write operation.
Sourcepub fn record_truncation(&self)
pub fn record_truncation(&self)
Record one RX truncation (bytes_returned < bytes_observed).
Sourcepub fn status_snapshot(&self) -> ConnectionStatus
pub fn status_snapshot(&self) -> ConnectionStatus
Build a snapshot of the current status of this connection.
pub fn cancel_token(&self) -> CancellationToken
pub fn summary(&self) -> ConnectionSummary
Sourcepub async fn write(&self, data: &[u8]) -> Result<usize>
pub async fn write(&self, data: &[u8]) -> Result<usize>
Write a byte slice, flushing before returning.
Sourcepub async fn read(
&self,
dst: &mut [u8],
timeout_ms: Option<u64>,
) -> Result<usize>
pub async fn read( &self, dst: &mut [u8], timeout_ms: Option<u64>, ) -> Result<usize>
Read up to dst.len() bytes. Returns SerialError::ReadTimeout if
timeout_ms is set and elapses before any byte arrives.
When a timeout is given, the lock on the underlying IO is held for at
most POLL_MS milliseconds at a time and released between polls. This
lets concurrent write calls on the same connection proceed without
waiting for the full read timeout — which is essential for the
request/response pattern (transact) on CDC-ACM devices.
Sourcepub async fn read_latest(&self, max_bytes: usize) -> Result<Vec<u8>>
pub async fn read_latest(&self, max_bytes: usize) -> Result<Vec<u8>>
Read up to max_bytes with a brief timeout (100ms) to capture any
immediately available data without blocking long.
Sourcepub async fn flush_buffers(&self, target: FlushTarget) -> Result<()>
pub async fn flush_buffers(&self, target: FlushTarget) -> Result<()>
Discard data buffered in the OS for the input, output, or both directions of this port.
Sourcepub async fn set_dtr_rts(&self, dtr: bool, rts: bool) -> Result<()>
pub async fn set_dtr_rts(&self, dtr: bool, rts: bool) -> Result<()>
Drive the DTR and RTS control lines. Common use case: pulse DTR low to soft-reset an Arduino, or hold both low to enter the ESP32 bootloader.
Takes the per-connection line-control lock so the change cannot
interleave with a capture_boot reset pulse.
pub async fn set_flow_control(&self, flow_control: FlowControl) -> Result<()>
Sourcepub async fn set_break_state(&self, enabled: bool) -> Result<()>
pub async fn set_break_state(&self, enabled: bool) -> Result<()>
Set the BREAK condition on the TX line.
Sourcepub async fn send_break(&self, duration_ms: u64) -> Result<()>
pub async fn send_break(&self, duration_ms: u64) -> Result<()>
Assert the BREAK condition on the TX line for duration_ms
milliseconds, then release it.
Sourcepub async fn reconfigure(
&self,
baud_rate: Option<u32>,
data_bits: Option<DataBits>,
stop_bits: Option<StopBits>,
parity: Option<Parity>,
flow_control: Option<FlowControl>,
) -> Result<ConnectionStatus>
pub async fn reconfigure( &self, baud_rate: Option<u32>, data_bits: Option<DataBits>, stop_bits: Option<StopBits>, parity: Option<Parity>, flow_control: Option<FlowControl>, ) -> Result<ConnectionStatus>
Reconfigure serial parameters on a live connection. Parameters passed
as None are left unchanged. Returns the effective config after the
operation completes.