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§
source§impl 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§
source§impl AsRawFd for SerialStream
impl AsRawFd for SerialStream
source§impl AsyncRead for SerialStream
impl AsyncRead for SerialStream
source§fn 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
.
source§impl AsyncWrite for SerialStream
impl AsyncWrite for SerialStream
source§fn 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
.
source§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<IoResult<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<IoResult<()>>
source§fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<IoResult<()>>
fn poll_shutdown( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<IoResult<()>>
source§fn 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 moresource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moresource§impl Debug for SerialStream
impl Debug for SerialStream
source§impl Read for SerialStream
impl Read for SerialStream
source§fn read(&mut self, buf: &mut [u8]) -> IoResult<usize>
fn read(&mut self, buf: &mut [u8]) -> IoResult<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 SerialStream
impl SerialPort for SerialStream
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, _: Duration) -> Result<()>
fn set_timeout(&mut self, _: 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 clear_break(&self) -> Result<()>
fn clear_break(&self) -> Result<()>
source§impl Write for SerialStream
impl Write for SerialStream
source§fn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
source§fn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
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 SerialStream
impl !RefUnwindSafe for SerialStream
impl Send for SerialStream
impl Sync for SerialStream
impl Unpin for SerialStream
impl !UnwindSafe for SerialStream
Blanket Implementations§
source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
source§fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf
. Read moresource§fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
source§fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
source§fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
source§fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
source§fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
source§fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
source§fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
source§fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
source§fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
source§fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
source§fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
source§fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
source§fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
source§fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
source§fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
source§fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
source§fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
source§fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
source§fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
source§fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
source§fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
source§fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
source§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf
. Read more