pub struct SerialPortStreamBuilder { /* private fields */ }Expand description
Builder for configuring and opening a serial port stream.
Use the new() function to create a builder, then chain configuration
methods before calling open().
§Example
use serialport_stream::new;
use serialport::{DataBits, Parity, StopBits, FlowControl};
use std::time::Duration;
let stream = new("/dev/ttyUSB0", 115200)
.data_bits(DataBits::Eight)
.parity(Parity::None)
.stop_bits(StopBits::One)
.flow_control(FlowControl::None)
.timeout(Duration::from_millis(100))
.open()?;Implementations§
Source§impl SerialPortStreamBuilder
impl SerialPortStreamBuilder
Sourcepub fn path<'a>(self, path: impl Into<Cow<'a, str>>) -> Self
pub fn path<'a>(self, path: impl Into<Cow<'a, str>>) -> Self
Sets the path to the serial port device.
§Examples
- Unix:
"/dev/ttyUSB0","/dev/ttyACM0" - Windows:
"COM3","COM10"
Sourcepub fn baud_rate(self, baud_rate: u32) -> Self
pub fn baud_rate(self, baud_rate: u32) -> Self
Sets the baud rate (bits per second).
Common values: 9600, 19200, 38400, 57600, 115200
Sourcepub fn data_bits(self, data_bits: DataBits) -> Self
pub fn data_bits(self, data_bits: DataBits) -> Self
Sets the number of data bits per character.
Default: DataBits::Eight
Sourcepub fn flow_control(self, flow_control: FlowControl) -> Self
pub fn flow_control(self, flow_control: FlowControl) -> Self
Sets the flow control mode.
Default: FlowControl::None
Sourcepub fn parity(self, parity: Parity) -> Self
pub fn parity(self, parity: Parity) -> Self
Sets the parity checking mode.
Default: Parity::None
Sourcepub fn stop_bits(self, stop_bits: StopBits) -> Self
pub fn stop_bits(self, stop_bits: StopBits) -> Self
Sets the number of stop bits.
Default: StopBits::One
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the timeout for read and write operations.
Default: Duration::from_millis(0) (non-blocking)
Sourcepub fn dtr_on_open(self, state: bool) -> Self
pub fn dtr_on_open(self, state: bool) -> Self
Sets the DTR (Data Terminal Ready) signal state when opening the port.
If not called, the DTR state is preserved from the previous port state.
Sourcepub fn preserve_dtr_on_open(self) -> Self
pub fn preserve_dtr_on_open(self) -> Self
Preserves the current DTR state when opening the port.
This is the default behavior.
Sourcepub fn open(self) -> Result<SerialPortStream>
pub fn open(self) -> Result<SerialPortStream>
Opens the serial port and creates the stream.
Trait Implementations§
Source§impl Clone for SerialPortStreamBuilder
impl Clone for SerialPortStreamBuilder
Source§fn clone(&self) -> SerialPortStreamBuilder
fn clone(&self) -> SerialPortStreamBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more