Skip to main content

Settings

Struct Settings 

Source
pub struct Settings {
    pub baud: u32,
    pub parity: Parity,
    pub stop_bits: StopBits,
}
Expand description

A port’s speed and character format: eight data bits, with the parity and stop bits given.

§Examples

use pamoja_hal::port::{Parity, Settings};

// A Modbus RTU meter at 9600 baud, with the even parity the protocol defaults to: one
// stop bit, and eleven bits a character.
let meter = Settings::new(9_600).with_parity(Parity::Even);
assert_eq!(meter.to_string(), "9600 8E1");
assert_eq!(meter.bits_per_character(), 11);
assert_eq!(meter.character_nanos(), 1_145_834);

Fields§

§baud: u32

The speed, in bits a second.

§parity: Parity

The parity bit each character carries.

§stop_bits: StopBits

How many stop bits end each character.

Implementations§

Source§

impl Settings

Source

pub const fn new(baud: u32) -> Settings

Eight data bits, no parity, and one stop bit, the format most devices start in.

§Arguments
  • baud - the speed, in bits a second.
§Returns

The settings.

Source

pub const fn with_parity(self, parity: Parity) -> Settings

Sets the parity bit.

§Arguments
  • parity - the parity each character carries.
§Returns

The settings.

Source

pub const fn with_stop_bits(self, stop_bits: StopBits) -> Settings

Sets the stop bits.

§Arguments
  • stop_bits - how many stop bits end each character.
§Returns

The settings.

Source

pub const fn bits_per_character(&self) -> u32

Returns the bits one character takes on the wire: a start bit, eight data bits, the parity bit if there is one, and the stop bits.

Source

pub const fn character_nanos(&self) -> u64

Returns how long one character takes on the wire, in nanoseconds, rounded up.

Source

pub const fn transfer_micros(&self, bytes: usize) -> u64

Returns how long a run of bytes takes on the wire, sent back to back, in microseconds, rounded up.

§Arguments
  • bytes - how many bytes.
§Returns

The time on the wire.

Trait Implementations§

Source§

impl Clone for Settings

Source§

fn clone(&self) -> Settings

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Settings

Source§

impl Debug for Settings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Settings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Settings

Source§

impl Hash for Settings

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Settings

Source§

fn eq(&self, other: &Settings) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Settings

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.