Trait serialport::SerialPort
[−]
[src]
pub trait SerialPort: Read + Write { fn settings(&self) -> SerialPortSettings; fn baud_rate(&self) -> Option<BaudRate>; fn data_bits(&self) -> Option<DataBits>; fn flow_control(&self) -> Option<FlowControl>; fn parity(&self) -> Option<Parity>; fn stop_bits(&self) -> Option<StopBits>; fn timeout(&self) -> Duration; fn set_all(&mut self, _: SerialPortSettings) -> Result<()>; fn set_baud_rate(&mut self, baud_rate: BaudRate) -> Result<()>; fn set_data_bits(&mut self, data_bits: DataBits) -> Result<()>; fn set_flow_control(&mut self, flow_control: FlowControl) -> Result<()>; fn set_parity(&mut self, parity: Parity) -> Result<()>; fn set_stop_bits(&mut self, stop_bits: StopBits) -> Result<()>; fn set_timeout(&mut self, timeout: Duration) -> Result<()>; fn write_request_to_send(&mut self, level: bool) -> Result<()>; fn write_data_terminal_ready(&mut self, level: bool) -> Result<()>; fn read_clear_to_send(&mut self) -> Result<bool>; fn read_data_set_ready(&mut self) -> Result<bool>; fn read_ring_indicator(&mut self) -> Result<bool>; fn read_carrier_detect(&mut self) -> Result<bool>; }
A trait for serial port devices
This trait is all that's necessary to implement a new serial port driver for a new platform.
Required Methods
fn settings(&self) -> SerialPortSettings
Returns a struct with the current port settings
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, _: 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, timeout: Duration) -> Result<()>
Sets the timeout for future I/O operations.
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.
Implementors
impl SerialPort for COMPort