Skip to main content

SerialSettings

Struct SerialSettings 

Source
pub struct SerialSettings {
    pub port_name: String,
    pub baud_rate: u32,
    pub data_bits: DataBits,
    pub parity: Parity,
    pub stop_bits: StopBits,
    pub flow_control: FlowControl,
    pub timeout: Duration,
    pub exclusive: bool,
}
Expand description

Настройки serial-подключения.

Все поля публичные, чтобы приложение могло точно выставить режим конкретного устройства. Значения проверяются перед открытием порта через SerialSettings::validate.

Fields§

§port_name: String

Имя serial-порта, например /dev/cu.usbmodem101, /dev/ttyUSB0 или COM3.

§baud_rate: u32

Скорость serial-порта в бодах.

Значение должно быть больше нуля. Типичные значения для VFD: 9600, 19200, 38400, но библиотека не ограничивает список скоростей.

§data_bits: DataBits

Количество бит данных.

§parity: Parity

Проверка чётности.

§stop_bits: StopBits

Количество stop bits.

§flow_control: FlowControl

Управление потоком.

§timeout: Duration

Тайм-аут операций serial-порта.

Значение передаётся в serialport; для worker это время ожидания одной блокирующей операции на устройстве, а не timeout всей очереди команд.

§exclusive: bool

Эксклюзивное открытие serial-порта на Unix.

По умолчанию включено, чтобы второй процесс не смог случайно писать в тот же дисплей. Поле доступно только на Unix-платформах.

Implementations§

Source§

impl SerialSettings

Source

pub fn new(port_name: impl Into<String>, baud_rate: u32) -> Self

Создаёт настройки serial-порта с явным baud rate.

Остальные параметры получают распространённые значения 8N1, без flow control, timeout 100 ms и exclusive mode на Unix. Их можно изменить напрямую в полях структуры до создания VfdConfig.

§Ошибки

Метод сам не возвращает ошибку. Проверка выполняется в SerialSettings::validate или при создании VfdConfig.

§Примеры
use escpos_vfd::SerialSettings;
use std::time::Duration;

let mut serial = SerialSettings::new("/dev/ttyUSB0", 9_600);
serial.timeout = Duration::from_millis(250);
assert!(serial.validate().is_ok());
Source

pub fn validate(&self) -> Result<(), ConfigError>

Проверяет, что настройки можно применить к serial-порту.

Метод не открывает устройство. Он только ловит ошибки, которые библиотека может определить заранее: пустое имя порта и нулевой baud rate.

§Ошибки

Возвращает ConfigError::EmptyPortName или ConfigError::ZeroBaudRate.

Trait Implementations§

Source§

impl Clone for SerialSettings

Source§

fn clone(&self) -> SerialSettings

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 Debug for SerialSettings

Source§

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

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

impl Eq for SerialSettings

Source§

impl PartialEq for SerialSettings

Source§

fn eq(&self, other: &SerialSettings) -> 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 SerialSettings

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, 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.