Struct serial2::SerialPort [−][src]
pub struct SerialPort { /* fields omitted */ }
Expand description
A serial port.
Implementations
Open and configure a serial port by path or name.
On Unix systems, the name
parameter must be a path to a TTY device.
On Windows, it must be the name of a COM device, such as COM1, COM2, etc.
The second argument is used to configure the serial port.
For simple cases, you pass a u32
for the baud rate.
See IntoSettings
for more information.
Example
SerialPort::open("/dev/ttyUSB0", 115200)?;
Get a list of available serial ports.
Not currently supported on all platforms. On unsupported platforms, this function always returns an error.
Configure (or reconfigure) the serial port.
Get the current configuration of the serial port.
This function can fail if the underlying syscall fails,
or if the serial port configuration can’t be reported using Settings
.
Read bytes from the serial port.
This is identical to std::io::Read::read()
, except that this function takes a const reference &self
.
This allows you to use the serial port concurrently from multiple threads.
Note that there are no guarantees on which thread receives what data when multiple threads are reading from the serial port. You should normally limit yourself to a single reading thread and a single writing thread.
Read bytes from the serial port into a slice of buffers.
This is identical to std::io::Read::read_vectored()
, except that this function takes a const reference &self
.
This allows you to use the serial port concurrently from multiple threads.
Note that there are no guarantees on which thread receives what data when multiple threads are reading from the serial port. You should normally limit yourself to a single reading thread and a single writing thread.
Check if the implementation supports vectored reads.
If this returns false, then Self::read_vectored()
will only use the first buffer of the given slice.
All platforms except for Windows support vectored reads.
Write bytes to the serial port.
This is identical to std::io::Write::write()
, except that this function takes a const reference &self
.
This allows you to use the serial port concurrently from multiple threads.
Note that data written to the same serial port from multiple threads may end up interleaved at the receiving side. You should normally limit yourself to a single reading thread and a single writing thread.
Write bytes to the serial port from a slice of buffers.
This is identical to std::io::Write::write_vectored()
, except that this function takes a const reference &self
.
This allows you to use the serial port concurrently from multiple threads.
Note that data written to the same serial port from multiple threads may end up interleaved at the receiving side. You should normally limit yourself to a single reading thread and a single writing thread.
Check if the implementation supports vectored writes.
If this returns false, then Self::write_vectored()
will only use the first buffer of the given slice.
All platforms except for Windows support vectored writes.
Flush all data queued to be written.
This will block until the OS buffer has been fully transmitted.
This is identical to std::io::Write::flush()
, except that this function takes a const reference &self
.
Set the read timeout for the serial port.
The timeout set by this function is an upper bound on individual calls to std::io::Read::read()
.
Other platform specific time-outs may trigger before this timeout does.
Get the read timeout of the serial port.
Set the write timeout for the serial port.
The timeout set by this function is an upper bound on individual calls to std::io::Write::write()
.
Other platform specific time-outs may trigger before this timeout does.
Get the write timeout of the serial port.
Discard the kernel input and output buffers for the serial port.
When you write to a serial port, the data may be put in a buffer by the OS to be transmitted by the actual device later. Similarly, data received on the device can be put in a buffer by the OS untill you read it. This function clears both buffers: any untransmitted data and received but unread data is discarded by the OS.
Discard the kernel input buffers for the serial port.
Data received on the device can be put in a buffer by the OS untill you read it. This function clears that buffer: received but unread data is discarded by the OS.
This is particularly useful when communicating with a device that only responds to commands that you send to it. If you discard the input buffer before sending the command, you discard any noise that may have been received after the last command.
Discard the kernel output buffers for the serial port.
When you write to a serial port, the data is generally put in a buffer by the OS to be transmitted by the actual device later. This function clears that buffer: any untransmitted data is discarded by the OS.
Set the state of the Ready To Send line.
If hardware flow control is enabled on the serial port, it is platform specific what will happen. The function may fail with an error or it may silently be ignored. It may even succeed and interfere with the flow control.
Read the state of the Clear To Send line.
If hardware flow control is enabled on the serial port, it is platform specific what will happen. The function may fail with an error, it may return a bogus value, or it may return the actual state of the CTS line.
Set the state of the Data Terminal Ready line.
If hardware flow control is enabled on the serial port, it is platform specific what will happen. The function may fail with an error or it may silently be ignored.
Read the state of the Data Set Ready line.
If hardware flow control is enabled on the serial port, it is platform specific what will happen. The function may fail with an error, it may return a bogus value, or it may return the actual state of the DSR line.
Read the state of the Ring Indicator line.
This line is also sometimes also called the RNG or RING line.
Trait Implementations
Constructs a new instance of Self
from the given raw file
descriptor. Read more
Consumes this object, returning the raw underlying file descriptor. Read more
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
read_initializer
)Determines if this Read
er can work with buffers of uninitialized
memory. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
Creates a “by reference” adapter for this instance of Read
. Read more
Creates an adapter which will chain this stream with another. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more