Struct virtual_serialport::VirtualPort
source · 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 open_loopback(baud_rate: u32, buffer_capacity: usize) -> Result<Self>
pub fn open_loopback(baud_rate: u32, buffer_capacity: usize) -> Result<Self>
Opens a single loopback virtual port with the specified baud rate.
sourcepub fn open_pair(baud_rate: u32, buffer_capacity: usize) -> Result<(Self, Self)>
pub fn open_pair(baud_rate: u32, buffer_capacity: usize) -> 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 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 moresource§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)Auto Trait Implementations§
impl Freeze for VirtualPort
impl RefUnwindSafe for VirtualPort
impl Send for VirtualPort
impl Sync for VirtualPort
impl Unpin for VirtualPort
impl UnwindSafe for VirtualPort
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)