|
ESPHome 2026.10.0-dev
|
#include <modbus_controller.h>
Public Member Functions | |
| virtual void | parse_and_publish (std::span< const uint8_t > data)=0 |
| Parse this sensor's slice out of its range's response and publish it. | |
| bool | addresses_bits () const |
| Coils and discrete inputs address individual bits; every other type addresses 16-bit registers. | |
| uint16_t | write_address () const |
| Address a write entity (switch/number/select) targets, derived from its resolved position within the range so that a write lands on the register the sensor reads from. | |
| void | set_offset_from_start_address (uint8_t offset) |
| Records the offset as configured, and seeds the resolved position with it. | |
| void | set_address (uint16_t address) |
| Sets the configured address, and points the range base at it. | |
| void | set_custom_pdu (std::initializer_list< uint8_t > pdu) |
| virtual uint16_t | entity_count () const |
| Entities this item spans: one bit for bit-addressed types, ceil(bytes / 2) registers for RAW with a response_size, else the value type's register width. | |
| virtual size_t | get_register_size () const |
| Bytes this item's registers occupy in a response: one per bit for bit-addressed types; response_size when set (devices that answer more bytes per register than the standard two); else two per register. | |
| void | set_register_size (uint8_t register_size) |
Data Fields | |
| modbus::EntityType | register_type {modbus::EntityType::CUSTOM} |
| SensorValueType | sensor_value_type {SensorValueType::RAW} |
| uint16_t | start_address {0} |
| uint32_t | bitmask {0} |
| uint8_t | offset {0} |
| Position of this sensor's data within its range's response - a byte offset for registers, a bit index for coils and discrete inputs. | |
| uint8_t | response_bytes {0} |
| uint8_t | offset_from_start_address {0} |
The offset exactly as configured: measured from this sensor's own start_address, where offset is measured from the first register of the range it ends up polled in. | |
| uint16_t | range_start_address {0} |
| First register of the range this sensor is polled in; equals start_address for an unpolled item. | |
| SmallInlineBuffer< 8 > | custom_pdu {} |
| RangeReuse | reuse_previous_range {RangeReuse::AUTO} |
Definition at line 139 of file modbus_controller.h.
|
inline |
Coils and discrete inputs address individual bits; every other type addresses 16-bit registers.
Definition at line 147 of file modbus_controller.h.
|
inlinevirtual |
Entities this item spans: one bit for bit-addressed types, ceil(bytes / 2) registers for RAW with a response_size, else the value type's register width.
Reimplemented in esphome::modbus_controller::ModbusBinarySensor.
Definition at line 175 of file modbus_controller.h.
|
inlinevirtual |
Bytes this item's registers occupy in a response: one per bit for bit-addressed types; response_size when set (devices that answer more bytes per register than the standard two); else two per register.
Definition at line 187 of file modbus_controller.h.
|
pure virtual |
Parse this sensor's slice out of its range's response and publish it.
The span points into the response buffer and is only valid for the duration of the call. Read the sensor's data from offset within it.
Implemented in esphome::modbus_controller::ModbusBinaryOutput, esphome::modbus_controller::ModbusBinarySensor, esphome::modbus_controller::ModbusFloatOutput, esphome::modbus_controller::ModbusNumber, esphome::modbus_controller::ModbusSelect, esphome::modbus_controller::ModbusSensor, esphome::modbus_controller::ModbusSwitch, and esphome::modbus_controller::ModbusTextSensor.
|
inline |
Sets the configured address, and points the range base at it.
Building the ranges moves the base to the range's first register; an item that is never polled (an output, or a switch with assumed_state) keeps its own address, so write_address() stays correct for it.
Definition at line 166 of file modbus_controller.h.
|
inline |
Definition at line 171 of file modbus_controller.h.
|
inline |
Records the offset as configured, and seeds the resolved position with it.
Building the ranges overwrites offset with the position within the range; an item that is never polled keeps this value, which is what its own address arithmetic expects.
Definition at line 158 of file modbus_controller.h.
|
inline |
Definition at line 195 of file modbus_controller.h.
|
inline |
Address a write entity (switch/number/select) targets, derived from its resolved position within the range so that a write lands on the register the sensor reads from.
Definition at line 151 of file modbus_controller.h.
| uint32_t esphome::modbus_controller::SensorItem::bitmask {0} |
Definition at line 199 of file modbus_controller.h.
| SmallInlineBuffer<8> esphome::modbus_controller::SensorItem::custom_pdu {} |
Definition at line 214 of file modbus_controller.h.
| uint8_t esphome::modbus_controller::SensorItem::offset {0} |
Position of this sensor's data within its range's response - a byte offset for registers, a bit index for coils and discrete inputs.
Resolved while the ranges are built, so it already accounts for the registers ahead of it (including wide response_size ones) and for any offset inherited from an earlier sensor sharing the same register.
Definition at line 204 of file modbus_controller.h.
| uint8_t esphome::modbus_controller::SensorItem::offset_from_start_address {0} |
The offset exactly as configured: measured from this sensor's own start_address, where offset is measured from the first register of the range it ends up polled in.
Same units as offset - bytes for registers, bits for coils and discrete inputs. Kept so the resolution can be recomputed, and so the sort order of the sensor set never depends on the resolved value. Declared before range_start_address so it lands in the padding after response_bytes.
Definition at line 211 of file modbus_controller.h.
| uint16_t esphome::modbus_controller::SensorItem::range_start_address {0} |
First register of the range this sensor is polled in; equals start_address for an unpolled item.
Definition at line 213 of file modbus_controller.h.
| modbus::EntityType esphome::modbus_controller::SensorItem::register_type {modbus::EntityType::CUSTOM} |
Definition at line 196 of file modbus_controller.h.
| uint8_t esphome::modbus_controller::SensorItem::response_bytes {0} |
Definition at line 205 of file modbus_controller.h.
| RangeReuse esphome::modbus_controller::SensorItem::reuse_previous_range {RangeReuse::AUTO} |
Definition at line 215 of file modbus_controller.h.
| SensorValueType esphome::modbus_controller::SensorItem::sensor_value_type {SensorValueType::RAW} |
Definition at line 197 of file modbus_controller.h.
| uint16_t esphome::modbus_controller::SensorItem::start_address {0} |
Definition at line 198 of file modbus_controller.h.