#[repr(u16)]pub enum Baudrate {
BR1200 = 0,
BR2400 = 1,
BR4800 = 2,
BR9600 = 3,
BR19200 = 4,
BR38400 = 5,
BR57600 = 6,
BR115200 = 7,
}Expand description
Represents supported baudrates for Modbus communication.
Each variant maps to an internal ID used within the protocol. The actual baudrate values (e.g., 9600, 115200) can be obtained via conversion.
Variants§
Implementations§
Source§impl Baudrate
impl Baudrate
Sourcepub fn from_id(id: u16) -> Option<Baudrate>
pub fn from_id(id: u16) -> Option<Baudrate>
Attempts to create a Baudrate from its internal ID.
This is used when a baudrate needs to be reconstructed from a stored or transmitted ID.
§Args
id: The internal identifier corresponding to aBaudrate.
§Returns
Some(Baudrate) if the ID matches a known baudrate, otherwise None.
§Examples
use modbus_rtu::common::Baudrate;
assert_eq!(Baudrate::from_id(3), Some(Baudrate::BR9600));
assert_eq!(Baudrate::from_id(99), None);Sourcepub fn to_id(&self) -> u16
pub fn to_id(&self) -> u16
Converts the Baudrate variant into its internal ID representation.
This ID can be stored or transmitted and later converted back using from_id.
§Returns
The internal u16 ID associated with the baudrate.
§Examples
use modbus_rtu::common::Baudrate;
let baud = Baudrate::BR19200;
assert_eq!(baud.to_id(), 4);Sourcepub fn packet_end_us(&self) -> u32
pub fn packet_end_us(&self) -> u32
Calculates the packet end timeout in microseconds based on the baudrate.
In Modbus RTU communication, this value defines the idle time required to consider a packet as ended. (3.5 char time)
§Returns
The idle time (in microseconds) required to delimit the end of a Modbus RTU packet at this baudrate.
§Examples
use modbus_rtu::common::Baudrate;
let baud = Baudrate::BR9600;
let packet_end_us: u32 = baud.packet_end_us();