#[repr(u16)]pub enum BaudRate {
B1200 = 1_200,
B2400 = 2_400,
B4800 = 4_800,
B9600 = 9_600,
B19200 = 19_200,
}Expand description
Enum representing the supported baud rates for RS485 communication.
Variants§
B1200 = 1_200
1200 baud rate.
B2400 = 2_400
2400 baud rate.
B4800 = 4_800
4800 baud rate.
B9600 = 9_600
9600 baud rate.
B19200 = 19_200
19200 baud rate.
Implementations§
Source§impl BaudRate
impl BaudRate
Sourcepub fn decode_from_holding_registers(words: &[Word]) -> Result<Self, Error>
pub fn decode_from_holding_registers(words: &[Word]) -> Result<Self, Error>
Decodes a BaudRate from a Modbus holding register value.
Reads the first word from the provided slice, which should contain the raw value read from the device’s baud rate register (0x00FF).
§Arguments
words- A slice containing theWord(s) read from the register.
§Returns
The corresponding BaudRate or an Error if decoding fails.
§Errors
Error::UnexpectedDataLength: ifwordsdoes not contain exactly one element.Error::InvalidValueCode: if the value from the register is not a valid baud rate code.
Sourcepub fn encode_for_write_register(&self) -> Word
pub fn encode_for_write_register(&self) -> Word
Encodes the BaudRate into its corresponding Word value for writing to the Modbus register.
§Returns
The Word representation of the baud rate.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for BaudRate
Available on crate feature serde only.
impl<'de> Deserialize<'de> for BaudRate
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl TryFrom<u16> for BaudRate
impl TryFrom<u16> for BaudRate
Source§fn try_from(value: u16) -> Result<Self, Self::Error>
fn try_from(value: u16) -> Result<Self, Self::Error>
Attempts to convert a standard u16 baud rate value (e.g., 9600) into a BaudRate enum variant.
Returns an error if the value does not match a supported baud rate.
Source§type Error = ErrorInvalidBaudRate
type Error = ErrorInvalidBaudRate
The type returned in the event of a conversion error.
impl Copy for BaudRate
impl Eq for BaudRate
impl StructuralPartialEq for BaudRate
Auto Trait Implementations§
impl Freeze for BaudRate
impl RefUnwindSafe for BaudRate
impl Send for BaudRate
impl Sync for BaudRate
impl Unpin for BaudRate
impl UnwindSafe for BaudRate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more