Struct mio_serial::unix::Serial
[−]
[src]
pub struct Serial { /* fields omitted */ }
*nix serial port using termios
Methods
impl Serial
[src]
fn from_path<T: AsRef<Path>>(
path: T,
settings: &SerialPortSettings
) -> Result<Self>
path: T,
settings: &SerialPortSettings
) -> Result<Self>
Open a nonblocking serial port from the provided path.
Example
use std::path::Path; use mio_serial::unix::Serial; use mio_serial::SerialPortSettings; let tty_name = Path::new("/dev/ttyUSB0"); let serial = Serial::from_path(tty_name, &SerialPortSettings::default()).unwrap();
fn from_serial(port: TTYPort) -> Result<Self>
Convert an existing serialport::posix::TTYPort
struct.
Example
extern crate serialport; use std::path::Path; use serialport::posix::TTYPort; use mio_serial::unix::Serial; let tty_name = Path::new("/dev/ttyUSB0"); let blocking_serial = TTYPort::open(tty_path).unwrap(); let serial = Serial::from_serial(blocking_serial).unwrap();
fn pair() -> SerialResult<(Self, Self)>
Create a pair of pseudo serial terminals
Returns
Two connected Serial
objects: (master, slave)
Errors
Attempting any IO or parameter settings on the slave tty after the master tty is closed will return errors.
Examples
use mio_serial::unix::Serial; let (master, slave) = Serial::pair().unwrap();
fn set_exclusive(&mut self, exclusive: bool) -> SerialResult<()>
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.
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.
Trait Implementations
impl SerialPort for Serial
[src]
fn settings(&self) -> SerialPortSettings
Returns a struct with the current port settings
fn port_name(&self) -> Option<String>
Return the name associated with the serial port, if known.
fn baud_rate(&self) -> Option<BaudRate>
Returns the current baud rate.
This function returns None
if the baud rate could not be determined. This may occur if
the hardware is in an uninitialized state. Setting a baud rate with set_baud_rate()
should initialize the baud rate to a supported value.
fn data_bits(&self) -> Option<DataBits>
Returns the character size.
This function returns None
if the character size could not be determined. This may occur
if the hardware is in an uninitialized state or is using a non-standard character size.
Setting a baud rate with set_char_size()
should initialize the character size to a
supported value.
fn flow_control(&self) -> Option<FlowControl>
Returns the flow control mode.
This function returns None
if the flow control mode could not be determined. This may
occur if the hardware is in an uninitialized state or is using an unsupported flow control
mode. Setting a flow control mode with set_flow_control()
should initialize the flow
control mode to a supported value.
fn parity(&self) -> Option<Parity>
Returns the parity-checking mode.
This function returns None
if the parity mode could not be determined. This may occur if
the hardware is in an uninitialized state or is using a non-standard parity mode. Setting
a parity mode with set_parity()
should initialize the parity mode to a supported value.
fn stop_bits(&self) -> Option<StopBits>
Returns the number of stop bits.
This function returns None
if the number of stop bits could not be determined. This may
occur if the hardware is in an uninitialized state or is using an unsupported stop bit
configuration. Setting the number of stop bits with set_stop-bits()
should initialize the
stop bits to a supported value.
fn timeout(&self) -> Duration
Returns the current timeout.
fn set_all(&mut self, settings: &SerialPortSettings) -> Result<()>
Applies all settings for a struct. This isn't guaranteed to involve only a single call into the driver, though that may be done on some platforms.
fn set_baud_rate(&mut self, baud_rate: BaudRate) -> Result<()>
Sets the baud rate.
Errors
If the implementation does not support the requested baud rate, this function may return an
InvalidInput
error. Even if the baud rate is accepted by set_baud_rate()
, it may not be
supported by the underlying hardware.
fn set_data_bits(&mut self, data_bits: DataBits) -> Result<()>
Sets the character size.
fn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()>
Sets the flow control mode.
fn set_parity(&mut self, parity: Parity) -> Result<()>
Sets the parity-checking mode.
fn set_stop_bits(&mut self, stop_bits: StopBits) -> Result<()>
Sets the number of stop bits.
fn set_timeout(&mut self, _: Duration) -> Result<()>
Sets the timeout for future I/O operations. This parameter is ignored but required for trait completeness.
fn write_request_to_send(&mut self, level: bool) -> Result<()>
Sets the state of the RTS (Request To Send) control signal.
Setting a value of true
asserts the RTS control signal. false
clears the signal.
Errors
This function returns an error if the RTS control signal could not be set to the desired state on the underlying hardware:
NoDevice
if the device was disconnected.Io
for any other type of I/O error.
fn write_data_terminal_ready(&mut self, level: bool) -> Result<()>
Writes to the Data Terminal Ready pin
Setting a value of true
asserts the DTR control signal. false
clears the signal.
Errors
This function returns an error if the DTR control signal could not be set to the desired state on the underlying hardware:
NoDevice
if the device was disconnected.Io
for any other type of I/O error.
fn read_clear_to_send(&mut self) -> Result<bool>
Reads the state of the CTS (Clear To Send) control signal.
This function returns a boolean that indicates whether the CTS control signal is asserted.
Errors
This function returns an error if the state of the CTS control signal could not be read from the underlying hardware:
NoDevice
if the device was disconnected.Io
for any other type of I/O error.
fn read_data_set_ready(&mut self) -> Result<bool>
Reads the state of the Data Set Ready control signal.
This function returns a boolean that indicates whether the DSR control signal is asserted.
Errors
This function returns an error if the state of the DSR control signal could not be read from the underlying hardware:
NoDevice
if the device was disconnected.Io
for any other type of I/O error.
fn read_ring_indicator(&mut self) -> Result<bool>
Reads the state of the Ring Indicator control signal.
This function returns a boolean that indicates whether the RI control signal is asserted.
Errors
This function returns an error if the state of the RI control signal could not be read from the underlying hardware:
NoDevice
if the device was disconnected.Io
for any other type of I/O error.
fn read_carrier_detect(&mut self) -> Result<bool>
Reads the state of the Carrier Detect control signal.
This function returns a boolean that indicates whether the CD control signal is asserted.
Errors
This function returns an error if the state of the CD control signal could not be read from the underlying hardware:
NoDevice
if the device was disconnected.Io
for any other type of I/O error.
impl Read for Serial
[src]
fn read(&mut self, bytes: &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 Self
1.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>
🔬 This is a nightly-only experimental API. (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 char
s. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0
R: Read,
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 Serial
[src]
fn write(&mut self, bytes: &[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 Self
1.0.0
Creates a "by reference" adaptor for this instance of Write
. Read more
impl<'a> Read for &'a Serial
[src]
fn read(&mut self, bytes: &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 Self
1.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>
🔬 This is a nightly-only experimental API. (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 char
s. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0
R: Read,
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<'a> Write for &'a Serial
[src]
fn write(&mut self, bytes: &[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 Self
1.0.0
Creates a "by reference" adaptor for this instance of Write
. Read more
impl AsRawFd for Serial
[src]
impl IntoRawFd for Serial
[src]
fn into_raw_fd(self) -> RawFd
Consumes this object, returning the raw underlying file descriptor. Read more
impl FromRawFd for Serial
[src]
unsafe fn from_raw_fd(fd: RawFd) -> Self
Constructs a new instance of Self
from the given raw file descriptor. Read more
impl Evented for Serial
[src]
fn register(
&self,
poll: &Poll,
token: Token,
interest: Ready,
opts: PollOpt
) -> Result<()>
&self,
poll: &Poll,
token: Token,
interest: Ready,
opts: PollOpt
) -> Result<()>
Register self
with the given Poll
instance. Read more
fn reregister(
&self,
poll: &Poll,
token: Token,
interest: Ready,
opts: PollOpt
) -> Result<()>
&self,
poll: &Poll,
token: Token,
interest: Ready,
opts: PollOpt
) -> Result<()>
Re-register self
with the given Poll
instance. Read more
fn deregister(&self, poll: &Poll) -> Result<()>
Deregister self
from the given Poll
instance Read more