pub enum ModbusValue {
Bool(bool),
U16(u16),
I16(i16),
U32(u32),
I32(i32),
F32(f32),
U64(u64),
I64(i64),
F64(f64),
}Expand description
Industrial data type enumeration for Modbus register values.
This enum represents all numeric types commonly used in industrial
automation and SCADA systems. It is designed to be self-contained
(no external dependencies) for use with ModbusCodec.
§Register Mapping
| Type | Registers | Description |
|---|---|---|
| Bool | 1 (coil) | Single bit value |
| U16/I16 | 1 | Single 16-bit register |
| U32/I32/F32 | 2 | Two consecutive registers |
| U64/I64/F64 | 4 | Four consecutive registers |
§Example
use voltage_modbus::ModbusValue;
let temp = ModbusValue::F32(25.5);
assert_eq!(temp.register_count(), 2);
assert!((temp.as_f64() - 25.5).abs() < 0.001);Variants§
Bool(bool)
Boolean value (typically from coils)
U16(u16)
Unsigned 16-bit integer (1 register)
I16(i16)
Signed 16-bit integer (1 register)
U32(u32)
Unsigned 32-bit integer (2 registers)
I32(i32)
Signed 32-bit integer (2 registers)
F32(f32)
32-bit floating point (2 registers)
U64(u64)
Unsigned 64-bit integer (4 registers)
I64(i64)
Signed 64-bit integer (4 registers)
F64(f64)
64-bit floating point (4 registers)
Implementations§
Source§impl ModbusValue
impl ModbusValue
Sourcepub fn as_f64(&self) -> f64
pub fn as_f64(&self) -> f64
Convert the value to f64 for uniform numeric handling.
This is useful for calculations, comparisons, and storing values in a normalized format.
Sourcepub fn as_i64(&self) -> i64
pub fn as_i64(&self) -> i64
Convert the value to i64 for integer operations.
Float values are rounded to the nearest integer.
Sourcepub fn register_count(&self) -> usize
pub fn register_count(&self) -> usize
Returns the number of 16-bit Modbus registers required for this value.
§Returns
0for Bool (coils use separate addressing)1for U16/I162for U32/I32/F324for U64/I64/F64
Trait Implementations§
Source§impl Clone for ModbusValue
impl Clone for ModbusValue
Source§fn clone(&self) -> ModbusValue
fn clone(&self) -> ModbusValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more