Struct mio_serial::SerialPort
[−]
[src]
pub struct SerialPort { /* fields omitted */ }A mio compatable serial port for *nix
Methods
impl SerialPort[src]
fn open<T: AsRef<Path>>(path: T) -> Result<Self>
Construct a new SerialPort
Opens the a serial port at the location provided by path with the following
default settings:
- 9600,8N1 (9600 Baud, 8-bit data, no parity, 1 stop bit)
- Receiver enabled in "Cannonical mode"
- Non-blocking
- No flow control (software OR hardware)
- Ignores hardware control lines
Errors
SerialPort construction can fail for a few reasons:
- An invalid path is provided
- The path does not represent a serial port device
- We are unable to configure the serial port ANY of the default settings. (Unlikely... but IS possible)
fn termios(&self) -> Result<Termios>
Retrieve the termios structure for the serial port.
fn set_termios(&mut self, action: i32, t: &Termios) -> Result<()>
Set low-level serial port settings
The action parameter must be one of the following:
termios::TCSANOWUpdate immediatelytermios::TCSADRAINFinish reading buffered data before updating.termios::TCSAFLUSHFinish writing buffered data before updating.
Errors
Will return ErrorKind::InvalidInput if action is not one of the three constants
defined above.
fn set_nonblocking(&mut self, blocking: bool) -> Result<()>
Enable or disable blocking reads and writes.
Panics
Will panic if the underlying fcntl system call returns a value other than 0 or -1
fn is_blocking(&self) -> Result<bool>
Get the current blocking mode for the serial port
Panics
Will panic if the underlying fcntl system call returns a value other than 0 or -1
fn maybe_write(&mut self, buf: &[u8]) -> Result<Option<usize>>
Try writing some data.
Similar to the standard io::Write implementation, but errors
due to blocking IO are translated into Ok(None) results.
Returns
Ok(Some(size))on successful writesOk(None)if calling write would block.Err(e)for all other IO errors
fn maybe_read(&mut self, buf: &mut [u8]) -> Result<Option<usize>>
Try reading some data.
Similar to the standard io::Read implementation, but errors
due to blocking IO are translated into Ok(None) results.
Returns
Ok(Some(size))on successful readsOk(None)if calling read would block.Err(e)for all other IO errors
fn set_baudrate(&mut self, baud: i32) -> Result<()>
Set the serial baudrate
Valid baudrates are:
- 0
- 50
- 75
- 110
- 134
- 150
- 200
- 300
- 600
- 1200
- 1800
- 2400
- 4800
- 9600
- 19200
- 38400
Errors
Returns an io::ErrorKind::InvalidInput for baud rates no in the list above.
fn baudrate(&self) -> Result<i32>
Get the serial baudrate
Valid baudrates are:
- 0
- 50
- 75
- 110
- 134
- 150
- 200
- 300
- 600
- 1200
- 1800
- 2400
- 4800
- 9600
- 19200
- 38400
Errors
Returns an io::ErrorKind::InvalidInput for baud rates no in the list above.
fn set_raw(&mut self, raw: bool) -> Result<()>
Enable or disable raw mode
In raw mode, input is available character by character, echoing is disabled, and all special processing of terminal input and output characters is disabled.
fn is_raw(&self) -> bool
Return if raw mode is enabled or not.
Trait Implementations
impl Drop for SerialPort[src]
impl AsRawFd for SerialPort[src]
impl Read for SerialPort[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>1.0.0
Read all bytes until EOF in this source, placing them into buf. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>1.0.0
Read all bytes until EOF in this source, placing them into buf. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>1.6.0
Read the exact number of bytes required to fill buf. Read more
fn by_ref(&mut self) -> &mut Self1.0.0
Creates a "by reference" adaptor for this instance of Read. Read more
fn bytes(self) -> Bytes<Self>1.0.0
Transforms this Read instance to an Iterator over its bytes. Read more
fn chars(self) -> Chars<Self>
io): the semantics of a partial read/write of where errors happen is currently unclear and may change
Transforms this Read instance to an Iterator over chars. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where R: Read1.0.0
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>1.0.0
Creates an adaptor which will read at most limit bytes from it. Read more
impl Write for SerialPort[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self1.0.0
Creates a "by reference" adaptor for this instance of Write. Read more