pub struct VirtualPort { /* private fields */ }Expand description
VirtualPort simulates a serial port for testing purposes. It supports
setting various serial port parameters like baud rate, data bits, flow control,
parity, and stop bits. It also supports reading from and writing to buffers.
Port pair wiring diagram:
Port 1 Port 2 ┌─────┐ ┌─────┐ │ TXD ├──────────▶│ RXD │ │ RXD │◂──────────┤ TXD │ │ RTS ├──────────▶│ CTS │ │ CTS │◂──────────┤ RTS │ │ DTR ├─────────┬▶│ DSR │ │ │ └▶│ CD │ │ DSR │◂┬─────────┤ DTR │ │ CD │◂┘ │ │ │ RI ├───────────┤ RI │ └─────┘ └─────┘
Implementations§
Source§impl VirtualPort
impl VirtualPort
Sourcepub fn loopback(baud_rate: u32, buffer_capacity: u32) -> Result<Self>
pub fn loopback(baud_rate: u32, buffer_capacity: u32) -> Result<Self>
Opens a single loopback virtual port with the specified baud rate.
Sourcepub fn pair(baud_rate: u32, buffer_capacity: u32) -> Result<(Self, Self)>
pub fn pair(baud_rate: u32, buffer_capacity: u32) -> Result<(Self, Self)>
Opens a pair of connected virtual ports with the specified baud rate. These ports can simulate a communication between two devices.
Sourcepub fn into_boxed(self) -> Box<dyn SerialPort>
pub fn into_boxed(self) -> Box<dyn SerialPort>
Boxes the instance as a SerialPort.
Sourcepub fn simulate_delay(&self) -> bool
pub fn simulate_delay(&self) -> bool
Returns whether transmission delay simulation is enabled.
Sourcepub fn set_simulate_delay(&mut self, value: bool)
pub fn set_simulate_delay(&mut self, value: bool)
Sets whether to simulate the transmission delay for reading operations.
Sourcepub fn noise_on_config_mismatch(&self) -> bool
pub fn noise_on_config_mismatch(&self) -> bool
Returns whether to simulate corrupted symbols if physical settings don’t match.
Sourcepub fn set_noise_on_config_mismatch(&mut self, value: bool)
pub fn set_noise_on_config_mismatch(&mut self, value: bool)
Sets whether to simulate corrupted symbols if physical settings don’t match.
Trait Implementations§
Source§impl Clone for VirtualPort
impl Clone for VirtualPort
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Read for VirtualPort
impl Read for VirtualPort
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl SerialPort for VirtualPort
impl SerialPort for VirtualPort
Source§fn flow_control(&self) -> Result<FlowControl>
fn flow_control(&self) -> Result<FlowControl>
Source§fn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()>
fn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()>
Source§fn set_timeout(&mut self, timeout: Duration) -> Result<()>
fn set_timeout(&mut self, timeout: Duration) -> Result<()>
Source§fn write_request_to_send(&mut self, level: bool) -> Result<()>
fn write_request_to_send(&mut self, level: bool) -> Result<()>
Source§fn write_data_terminal_ready(&mut self, level: bool) -> Result<()>
fn write_data_terminal_ready(&mut self, level: bool) -> Result<()>
Source§fn read_clear_to_send(&mut self) -> Result<bool>
fn read_clear_to_send(&mut self) -> Result<bool>
Source§fn read_data_set_ready(&mut self) -> Result<bool>
fn read_data_set_ready(&mut self) -> Result<bool>
Source§fn read_ring_indicator(&mut self) -> Result<bool>
fn read_ring_indicator(&mut self) -> Result<bool>
Source§fn read_carrier_detect(&mut self) -> Result<bool>
fn read_carrier_detect(&mut self) -> Result<bool>
Source§fn bytes_to_read(&self) -> Result<u32>
fn bytes_to_read(&self) -> Result<u32>
Source§fn bytes_to_write(&self) -> Result<u32>
fn bytes_to_write(&self) -> Result<u32>
Source§fn clear(&self, buffer_to_clear: ClearBuffer) -> Result<()>
fn clear(&self, buffer_to_clear: ClearBuffer) -> Result<()>
Source§fn try_clone(&self) -> Result<Box<dyn SerialPort>>
fn try_clone(&self) -> Result<Box<dyn SerialPort>>
SerialPort. This allow you to write and read simultaneously from the
same serial connection. Please note that if you want a real asynchronous serial port you
should look at mio-serial or
tokio-serial. Read moreSource§fn clear_break(&self) -> Result<()>
fn clear_break(&self) -> Result<()>
Source§impl Write for VirtualPort
impl Write for VirtualPort
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)