Trait serial::SerialPort [] [src]

pub trait SerialPort: Read + Write {
    type Settings: SerialPortSettings;
    fn read_settings(&self) -> Result<Self::Settings>;
    fn write_settings(&mut self, settings: &Self::Settings) -> Result<()>;
    fn timeout(&self) -> Duration;
    fn set_timeout(&mut self, timeout: Duration) -> Result<()>;

    fn configure(&mut self, settings: &PortSettings) -> Result<()> { ... }
}

A trait for serial port devices.

A device's serial port settings (baud rate, parity, etc) can be configured through its Settings type, which hides implementation details of the serial port's native configuration.

Serial port input and output is implemented through the std::io::Read and std::io::Write traits. A timeout can be set with the set_timeout() method and applies to all subsequent I/O operations.

Associated Types

type Settings: SerialPortSettings

A type that implements the settings for the serial port device.

The Settings type is used to retrieve and modify the serial port's settings.

Required Methods

fn read_settings(&self) -> Result<Self::Settings>

Returns the device's current settings.

This function attempts to read the current settings from the hardware. The hardware's current settings may not match the settings that were most recently written to the hardware with apply_settings().

Errors

This function returns an error if the settings could not be read from the underlying hardware. An error could indicate that the device has been disconnected.

fn write_settings(&mut self, settings: &Self::Settings) -> Result<()>

Applies new settings to the serial device.

This function attempts to apply all settings to the serial device. Some settings may not be supported by the underlying hardware, in which case the result is dependent on the implementation. A successful return value does not guarantee that all settings were appliied successfully. To check which settings were applied by a successful write, applications should use the settings() method to obtain the latest configuration state from the device.

Errors

This function returns an error if the settings could not be applied to the underlying hardware. An error could indicate that the device has been disconnected or that the device is not compatible with the given configuration settings.

fn timeout(&self) -> Duration

Returns the current timeout.

fn set_timeout(&mut self, timeout: Duration) -> Result<()>

Sets the timeout for future I/O operations.

Provided Methods

fn configure(&mut self, settings: &PortSettings) -> Result<()>

Configures a serial port device.

Implementors