pub enum RegisterKind {
U16,
I16,
U32Be,
F32Be,
}Expand description
How a device’s register map spells one quantity.
Registers are 16-bit words and mean nothing by themselves: the same two words are 100 000 to one meter and 50.0 to the next. Which it is comes from the device’s manual and is decided here — once, as a calculation over the words, so no caller reassembles bytes.
Four kinds, because four are what common meter manuals print. A fifth
arrives with the device that needs it, as a variant the compiler makes
every match account for.
Variants§
U16
One register as an unsigned 16-bit integer.
I16
One register as a signed 16-bit integer.
U32Be
Two registers as an unsigned 32-bit integer, most significant word first.
F32Be
Two registers as an IEEE 754 binary32, most significant word first.
Implementations§
Source§impl RegisterKind
impl RegisterKind
Sourcepub const fn registers(self) -> u16
pub const fn registers(self) -> u16
How many registers this kind occupies.
Exhaustive by construction, like crate::FunctionCode::code: a
fifth kind does not compile until someone writes here how wide it is.
Sourcepub const fn fits(self, count: RegisterCount) -> bool
pub const fn fits(self, count: RegisterCount) -> bool
Whether a read of count registers is the width this kind needs.
The one spelling of that rule, so every register map asks the same
question instead of writing the comparison again: a U32Be read as one
register is half a number.
Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
The kind’s name, for an error an operator reads beside a manual.
Sourcepub fn decode(self, words: &[u16]) -> Result<f64, ModbusError>
pub fn decode(self, words: &[u16]) -> Result<f64, ModbusError>
The number these words carry, unscaled.
Big-endian throughout, first word most significant, which is the protocol’s order and the order most device manuals print.
§Errors
Returns ModbusError::WordCount when the slice is not exactly
Self::registers words long. A U32Be decoded from one word would
be half a number.