Module protocol

Module protocol 

Source
Expand description

Defines data structures, constants, and protocol logic for interacting with an 8-Channel Multifunction RS485 Module via Modbus RTU, based on the protocol specification document.

This module covers:

  • Representing port states (PortState, PortStates).
  • Identifying specific ports (Port) and the Modbus device address (Address).
  • Defining Modbus register addresses and data values for reading states and controlling ports.
  • Encoding and decoding values from/to Modbus register format (Word).
  • Error handling for invalid port or address values.

Assumes standard Modbus function codes “Read Holding Registers” (0x03) and “Write Single Register” (0x06) are used externally to interact with the device.

Structs§

Address
Represents a validated Modbus device address, used for RTU communication over RS485.
ErrorAddressOutOfRange
Error indicating that a provided Modbus device address (u8) is outside the valid range for assignable addresses, defined by Address::MIN and Address::MAX (inclusive).
ErrorPortOutOfRange
Error indicating that a provided port index (u8) is outside the valid range defined by Port::MIN and Port::MAX (inclusive).
Port
Represents a validated port index, guaranteed to be within the valid range 0..NUMBER_OF_PORTS.
PortStates
Represents the collective states of all NUMBER_OF_PORTS ports.
PortsAll
A zero-sized type providing constants for controlling all ports simultaneously.

Enums§

Error
A comprehensive error type for all operations within the protocol module.
PortState
Represents the state of a single digital I/O port (e.g., relay).

Constants§

NUMBER_OF_PORTS
The total number of controllable digital I/O ports on the module.

Type Aliases§

Word
Represents a single 16-bit value stored in a Modbus register.