pub struct PortStates(/* private fields */);Expand description
Represents the collective states of all NUMBER_OF_PORTS ports.
This struct holds an array of PortState and provides constants
for reading all port states using a single Modbus “Read Holding Registers” (0x03) command.
Implementations§
Source§impl PortStates
impl PortStates
Sourcepub const ADDRESS: u16 = 1u16
pub const ADDRESS: u16 = 1u16
The Modbus function code 0x03 (Read Holding Registers) register address used for reading all port states sequentially.
Sourcepub const QUANTITY: u16 = 8u16
pub const QUANTITY: u16 = 8u16
The number of consecutive Modbus registers (Words) to read to get all port states.
This corresponds to NUMBER_OF_PORTS.
Sourcepub fn decode_from_holding_registers(words: &[Word]) -> Self
pub fn decode_from_holding_registers(words: &[Word]) -> Self
Decodes the states of all ports from a slice of Modbus holding register values.
Expects words to contain NUMBER_OF_PORTS values. Each word in the slice
corresponds to the state of a single port, decoded via PortState::decode_from_holding_registers.
If words contains fewer than NUMBER_OF_PORTS items, the remaining
port states in the returned struct will retain their default initialized value (PortState::Close).
Extra items in words beyond NUMBER_OF_PORTS are ignored.
§Arguments
words: A slice ofWordcontaining the register values read from the device.
§Returns
A PortStates struct containing the decoded state for each port.
§Panics
Panics if words does not have length equal to NUMBER_OF_PORTS.
§Example
// Example data mimicking a Modbus read response for 8 registers
let modbus_data: [Word; NUMBER_OF_PORTS] = [0x1, 0x0, 0xFFFF, 0x0, 0x0, 0x0, 0x1234, 0x0];
let decoded_states = PortStates::decode_from_holding_registers(&modbus_data);
assert_eq!(decoded_states.as_array()[0], PortState::Open);
assert_eq!(decoded_states.as_array()[1], PortState::Close);
assert_eq!(decoded_states.as_array()[2], PortState::Open); // Non-zero treated as Open
// ... and so on for all portsTrait Implementations§
Source§impl Clone for PortStates
impl Clone for PortStates
Source§fn clone(&self) -> PortStates
fn clone(&self) -> PortStates
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PortStates
impl Debug for PortStates
Source§impl Display for PortStates
Provides a comma-separated string representation of all port states (e.g., “close, open, close, …”).
impl Display for PortStates
Provides a comma-separated string representation of all port states (e.g., “close, open, close, …”).