Struct tokio_serial::SerialStream
source · pub struct SerialStream { /* private fields */ }
Expand description
Async serial port I/O
Reading and writing to a TcpStream
is usually done using the
convenience methods found on the tokio::io::AsyncReadExt
and tokio::io::AsyncWriteExt
traits.
Implementations
sourceimpl SerialStream
impl SerialStream
sourcepub fn open(builder: &SerialPortBuilder) -> Result<Self>
pub fn open(builder: &SerialPortBuilder) -> Result<Self>
Open serial port from a provided path, using the default reactor.
sourcepub fn pair() -> Result<(Self, Self)>
pub fn pair() -> Result<(Self, Self)>
sourcepub fn set_exclusive(&mut self, exclusive: bool) -> Result<()>
pub fn set_exclusive(&mut self, exclusive: bool) -> Result<()>
Sets the exclusivity of the port
If a port is exclusive, then trying to open the same device path again will fail.
See the man pages for the tiocexcl and tiocnxcl ioctl’s for more details.
Errors
Io
for any error while setting exclusivity for the port.
sourcepub fn exclusive(&self) -> bool
pub fn exclusive(&self) -> bool
Returns the exclusivity of the port
If a port is exclusive, then trying to open the same device path again will fail.
sourcepub fn try_read(&mut self, buf: &mut [u8]) -> IoResult<usize>
pub fn try_read(&mut self, buf: &mut [u8]) -> IoResult<usize>
Try to read bytes on the serial port. On success returns the number of bytes read.
The function must be called with valid byte array buf
of sufficient
size to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.
When there is no pending data, Err(io::ErrorKind::WouldBlock)
is
returned. This function is usually paired with readable()
.
sourcepub async fn readable(&self) -> IoResult<()>
pub async fn readable(&self) -> IoResult<()>
Wait for the port to become readable.
This function is usually paired with try_read()
.
The function may complete without the socket being readable. This is a
false-positive and attempting a try_read()
will return with
io::ErrorKind::WouldBlock
.
Trait Implementations
sourceimpl AsRawFd for SerialStream
impl AsRawFd for SerialStream
sourceimpl AsyncRead for SerialStream
impl AsyncRead for SerialStream
sourcefn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<IoResult<()>>
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<IoResult<()>>
Attempts to ready bytes on the serial port.
Note that on multiple calls to a poll_*
method in the read direction, only the
Waker
from the Context
passed to the most recent call will be scheduled to
receive a wakeup.
Return value
The function returns:
Poll::Pending
if the socket is not ready to readPoll::Ready(Ok(()))
reads dataReadBuf
if the socket is readyPoll::Ready(Err(e))
if an error is encountered.
Errors
This function may encounter any standard I/O error except WouldBlock
.
sourceimpl AsyncWrite for SerialStream
impl AsyncWrite for SerialStream
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<IoResult<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<IoResult<usize>>
Attempts to send data on the serial port
Note that on multiple calls to a poll_*
method in the send direction,
only the Waker
from the Context
passed to the most recent call will
be scheduled to receive a wakeup.
Return value
The function returns:
Poll::Pending
if the socket is not available to writePoll::Ready(Ok(n))
n
is the number of bytes sentPoll::Ready(Err(e))
if an error is encountered.
Errors
This function may encounter any standard I/O error except WouldBlock
.
sourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<IoResult<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<IoResult<()>>
sourcefn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<IoResult<()>>
fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<IoResult<()>>
sourcefn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
poll_write
, except that it writes from a slice of buffers. Read moresourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moresourceimpl Debug for SerialStream
impl Debug for SerialStream
sourceimpl Read for SerialStream
impl Read for SerialStream
sourcefn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
1.36.0 · sourcefn 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 moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf
. Read more1.0.0 · sourcefn 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 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)sourcefn 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 · sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresourceimpl SerialPort for SerialStream
impl SerialPort for SerialStream
sourcefn try_clone(&self) -> Result<Box<dyn SerialPort>>
fn try_clone(&self) -> Result<Box<dyn SerialPort>>
sourcefn flow_control(&self) -> Result<FlowControl>
fn flow_control(&self) -> Result<FlowControl>
sourcefn set_data_bits(&mut self, data_bits: DataBits) -> Result<()>
fn set_data_bits(&mut self, data_bits: DataBits) -> Result<()>
sourcefn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()>
fn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()>
sourcefn set_parity(&mut self, parity: Parity) -> Result<()>
fn set_parity(&mut self, parity: Parity) -> Result<()>
sourcefn set_stop_bits(&mut self, stop_bits: StopBits) -> Result<()>
fn set_stop_bits(&mut self, stop_bits: StopBits) -> Result<()>
sourcefn set_timeout(&mut self, _: Duration) -> Result<()>
fn set_timeout(&mut self, _: Duration) -> Result<()>
sourcefn write_request_to_send(&mut self, level: bool) -> Result<()>
fn write_request_to_send(&mut self, level: bool) -> Result<()>
sourcefn write_data_terminal_ready(&mut self, level: bool) -> Result<()>
fn write_data_terminal_ready(&mut self, level: bool) -> Result<()>
sourcefn read_clear_to_send(&mut self) -> Result<bool>
fn read_clear_to_send(&mut self) -> Result<bool>
sourcefn read_data_set_ready(&mut self) -> Result<bool>
fn read_data_set_ready(&mut self) -> Result<bool>
sourcefn read_ring_indicator(&mut self) -> Result<bool>
fn read_ring_indicator(&mut self) -> Result<bool>
sourcefn read_carrier_detect(&mut self) -> Result<bool>
fn read_carrier_detect(&mut self) -> Result<bool>
sourcefn bytes_to_read(&self) -> Result<u32>
fn bytes_to_read(&self) -> Result<u32>
sourcefn bytes_to_write(&self) -> Result<u32>
fn bytes_to_write(&self) -> Result<u32>
sourcefn clear(&self, buffer_to_clear: ClearBuffer) -> Result<()>
fn clear(&self, buffer_to_clear: ClearBuffer) -> Result<()>
sourcefn clear_break(&self) -> Result<()>
fn clear_break(&self) -> Result<()>
sourceimpl Write for SerialStream
impl Write for SerialStream
sourcefn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
sourcefn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
sourcefn 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 !RefUnwindSafe for SerialStream
impl Send for SerialStream
impl Sync for SerialStream
impl Unpin for SerialStream
impl !UnwindSafe for SerialStream
Blanket Implementations
sourceimpl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
sourcefn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
sourcefn read_buf<B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>where
Self: Sized + Unpin,
B: BufMut,
fn read_buf<B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>where
Self: Sized + Unpin,
B: BufMut,
sourcefn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf
. Read moresourcefn read_u8(&'a mut self) -> ReadU8<&'a mut Self>where
Self: Unpin,
fn read_u8(&'a mut self) -> ReadU8<&'a mut Self>where
Self: Unpin,
sourcefn read_i8(&'a mut self) -> ReadI8<&'a mut Self>where
Self: Unpin,
fn read_i8(&'a mut self) -> ReadI8<&'a mut Self>where
Self: Unpin,
sourcefn read_u16(&'a mut self) -> ReadU16<&'a mut Self>where
Self: Unpin,
fn read_u16(&'a mut self) -> ReadU16<&'a mut Self>where
Self: Unpin,
sourcefn read_i16(&'a mut self) -> ReadI16<&'a mut Self>where
Self: Unpin,
fn read_i16(&'a mut self) -> ReadI16<&'a mut Self>where
Self: Unpin,
sourcefn read_u32(&'a mut self) -> ReadU32<&'a mut Self>where
Self: Unpin,
fn read_u32(&'a mut self) -> ReadU32<&'a mut Self>where
Self: Unpin,
sourcefn read_i32(&'a mut self) -> ReadI32<&'a mut Self>where
Self: Unpin,
fn read_i32(&'a mut self) -> ReadI32<&'a mut Self>where
Self: Unpin,
sourcefn read_u64(&'a mut self) -> ReadU64<&'a mut Self>where
Self: Unpin,
fn read_u64(&'a mut self) -> ReadU64<&'a mut Self>where
Self: Unpin,
sourcefn read_i64(&'a mut self) -> ReadI64<&'a mut Self>where
Self: Unpin,
fn read_i64(&'a mut self) -> ReadI64<&'a mut Self>where
Self: Unpin,
sourcefn read_u128(&'a mut self) -> ReadU128<&'a mut Self>where
Self: Unpin,
fn read_u128(&'a mut self) -> ReadU128<&'a mut Self>where
Self: Unpin,
sourcefn read_i128(&'a mut self) -> ReadI128<&'a mut Self>where
Self: Unpin,
fn read_i128(&'a mut self) -> ReadI128<&'a mut Self>where
Self: Unpin,
sourcefn read_f32(&'a mut self) -> ReadF32<&'a mut Self>where
Self: Unpin,
fn read_f32(&'a mut self) -> ReadF32<&'a mut Self>where
Self: Unpin,
sourcefn read_f64(&'a mut self) -> ReadF64<&'a mut Self>where
Self: Unpin,
fn read_f64(&'a mut self) -> ReadF64<&'a mut Self>where
Self: Unpin,
sourcefn read_u16_le(&'a mut self) -> ReadU16Le<&'a mut Self>where
Self: Unpin,
fn read_u16_le(&'a mut self) -> ReadU16Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i16_le(&'a mut self) -> ReadI16Le<&'a mut Self>where
Self: Unpin,
fn read_i16_le(&'a mut self) -> ReadI16Le<&'a mut Self>where
Self: Unpin,
sourcefn read_u32_le(&'a mut self) -> ReadU32Le<&'a mut Self>where
Self: Unpin,
fn read_u32_le(&'a mut self) -> ReadU32Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i32_le(&'a mut self) -> ReadI32Le<&'a mut Self>where
Self: Unpin,
fn read_i32_le(&'a mut self) -> ReadI32Le<&'a mut Self>where
Self: Unpin,
sourcefn read_u64_le(&'a mut self) -> ReadU64Le<&'a mut Self>where
Self: Unpin,
fn read_u64_le(&'a mut self) -> ReadU64Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i64_le(&'a mut self) -> ReadI64Le<&'a mut Self>where
Self: Unpin,
fn read_i64_le(&'a mut self) -> ReadI64Le<&'a mut Self>where
Self: Unpin,
sourcefn read_u128_le(&'a mut self) -> ReadU128Le<&'a mut Self>where
Self: Unpin,
fn read_u128_le(&'a mut self) -> ReadU128Le<&'a mut Self>where
Self: Unpin,
sourcefn read_i128_le(&'a mut self) -> ReadI128Le<&'a mut Self>where
Self: Unpin,
fn read_i128_le(&'a mut self) -> ReadI128Le<&'a mut Self>where
Self: Unpin,
sourcefn read_f32_le(&'a mut self) -> ReadF32Le<&'a mut Self>where
Self: Unpin,
fn read_f32_le(&'a mut self) -> ReadF32Le<&'a mut Self>where
Self: Unpin,
sourcefn read_f64_le(&'a mut self) -> ReadF64Le<&'a mut Self>where
Self: Unpin,
fn read_f64_le(&'a mut self) -> ReadF64Le<&'a mut Self>where
Self: Unpin,
sourcefn read_to_end(&'a mut self, buf: &'a mut Vec<u8, Global>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8, Global>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf
. Read moresourcefn read_to_string(&'a mut self, dst: &'a mut String) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string(&'a mut self, dst: &'a mut String) -> ReadToString<'a, Self>where
Self: Unpin,
buf
. Read more