Struct serialport::COMPort
source · pub struct COMPort { /* private fields */ }
Expand description
A serial port implementation for Windows COM ports
The port will be closed when the value is dropped. However, this struct
should not be instantiated directly by using COMPort::open()
, instead use
the cross-platform serialport::open()
or
serialport::open_with_settings()
.
Implementations§
source§impl COMPort
impl COMPort
sourcepub fn open(builder: &SerialPortBuilder) -> Result<COMPort>
pub fn open(builder: &SerialPortBuilder) -> Result<COMPort>
Opens a COM port as a serial device.
port
should be the name of a COM port, e.g., COM1
.
If the COM port handle needs to be opened with special flags, use
from_raw_handle
method to create the COMPort
. Note that you should
set the different settings before using the serial port using set_all
.
Errors
NoDevice
if the device could not be opened. This could indicate that the device is already in use.InvalidInput
ifport
is not a valid device name.Io
for any other I/O error while opening or initializing the device.
sourcepub fn try_clone_native(&self) -> Result<COMPort>
pub fn try_clone_native(&self) -> Result<COMPort>
Attempts to clone the 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.
Also, you must be very careful when changing the settings of a cloned SerialPort
: since
the settings are cached on a per object basis, trying to modify them from two different
objects can cause some nasty behavior.
This is the same as SerialPort::try_clone()
but returns the concrete type instead.
Errors
This function returns an error if the serial port couldn’t be cloned.
Trait Implementations§
source§impl AsRawHandle for COMPort
impl AsRawHandle for COMPort
source§fn as_raw_handle(&self) -> RawHandle
fn as_raw_handle(&self) -> RawHandle
source§impl FromRawHandle for COMPort
impl FromRawHandle for COMPort
source§unsafe fn from_raw_handle(handle: RawHandle) -> Self
unsafe fn from_raw_handle(handle: RawHandle) -> Self
source§impl Read for COMPort
impl Read for COMPort
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 COMPort
impl SerialPort for COMPort
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 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 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 COMPort
impl Write for COMPort
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
)