ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
esphome::modbus_controller::ControllerDevice Class Reference

The shared feedback half of a controller-owned hub device: online/offline tracking, retry counting and the on_command_sent trigger all route to the controller from here. More...

#include <modbus_controller.h>

Inheritance diagram for esphome::modbus_controller::ControllerDevice:
esphome::modbus::ModbusClientDevice esphome::modbus_controller::PollingDevice esphome::modbus_controller::WriterDevice

Public Member Functions

void set_controller (ModbusController *controller)
 

Protected Member Functions

 ControllerDevice ()=default
 
 ControllerDevice (ModbusController *controller)
 
void on_response (std::span< const uint8_t > request_pdu, std::span< const uint8_t > response_pdu) override
 
void on_error (std::span< const uint8_t > request_pdu, modbus::ExceptionCode exception_code) override
 
void on_sent (std::span< const uint8_t > request_pdu) override
 
void on_not_sent (std::span< const uint8_t > request_pdu) override
 
bool on_no_response (std::span< const uint8_t > request_pdu) override
 
void notify_online_ (std::span< const uint8_t > request_pdu)
 
- Protected Member Functions inherited from esphome::modbus::ModbusClientDevice
 ModbusClientDevice ()=default
 
 ModbusClientDevice (ModbusClientHub *parent, uint8_t address)
 
virtual ~ModbusClientDevice ()
 
 ModbusClientDevice (const ModbusClientDevice &)=delete
 
ModbusClientDeviceoperator= (const ModbusClientDevice &)=delete
 
 ModbusClientDevice (ModbusClientDevice &&)=delete
 
ModbusClientDeviceoperator= (ModbusClientDevice &&)=delete
 
void set_parent (ModbusClientHub *parent)
 
void set_address (uint8_t address)
 
 ESPDEPRECATED ("Override on_not_sent() instead. Removed in 2027.2.0", "2026.8.0") virtual void on_modbus_not_sent()
 
 ESPDEPRECATED ("Override on_no_response() instead. Removed in 2027.2.0", "2026.8.0") virtual bool on_modbus_no_response()
 
virtual void on_read_registers (EntityType entity_type, uint16_t start_address, std::span< const uint16_t > registers, ResponseStatus status)
 High-level typed response callbacks, fired by the default on_response()/on_error() with arguments parsed from the request and response PDUs.
 
virtual void on_read_holding_registers (uint16_t start_address, std::span< const uint16_t > registers, ResponseStatus status)
 
virtual void on_read_input_registers (uint16_t start_address, std::span< const uint16_t > registers, ResponseStatus status)
 
virtual void on_read_bits (EntityType entity_type, uint16_t start_address, PackedBits bits, ResponseStatus status)
 Coil/discrete-input reads are delivered as a PackedBits view (bit 0 = the bit at start_address, bits.size() = the count requested).
 
virtual void on_read_coils (uint16_t start_address, PackedBits bits, ResponseStatus status)
 
virtual void on_read_discrete_inputs (uint16_t start_address, PackedBits bits, ResponseStatus status)
 
virtual void on_write_single_register (uint16_t address, uint16_t value, ResponseStatus status)
 Write acknowledgements.
 
virtual void on_write_single_coil (uint16_t address, bool value, ResponseStatus status)
 
virtual void on_write_multiple_registers (uint16_t start_address, std::span< const uint16_t > registers, ResponseStatus status)
 
virtual void on_write_multiple_coils (uint16_t start_address, PackedBits bits, ResponseStatus status)
 
virtual void on_custom_response (std::span< const uint8_t > request_pdu, std::span< const uint8_t > response_pdu, ResponseStatus status)
 Catch-all for custom function codes and anything that is not a standard-conformant transaction (see dispatch_response_()); on failure the response is empty and the exception code is in status.
 
 ESPDEPRECATED ("Use the typed read_*/write_* helpers or queue_pdu() instead. Removed in 2027.2.0", "2026.8.0") void send(uint8_t function
 

Protected Attributes

bool dispatched_ {false}
 Write-path state owned by WriterEntity's forwarders, stored here so both bools land in the base's tail padding instead of adding a word to every writer entity.
 
bool write_buffer_deprecated_warned_ {false}
 
ModbusControllercontroller_ {nullptr}
 
- Protected Attributes inherited from esphome::modbus::ModbusClientDevice
uint16_t start_address
 
uint16_t uint16_t number_of_entities
 
uint16_t uint16_t uint8_t payload_len = 0
 
uint16_t uint16_t uint8_t const uint8_t * payload
 
ModbusClientHubparent_ {nullptr}
 
uint8_t address_ {0}
 
bool custom_response_warned_ {false}
 

Detailed Description

The shared feedback half of a controller-owned hub device: online/offline tracking, retry counting and the on_command_sent trigger all route to the controller from here.

The hub base is inherited protected, so a subclass chooses exactly what request API it exposes.

Definition at line 266 of file modbus_controller.h.

Constructor & Destructor Documentation

◆ ControllerDevice() [1/2]

esphome::modbus_controller::ControllerDevice::ControllerDevice ( )
protecteddefault

◆ ControllerDevice() [2/2]

esphome::modbus_controller::ControllerDevice::ControllerDevice ( ModbusController * controller)
inlineexplicitprotected

Definition at line 273 of file modbus_controller.h.

Member Function Documentation

◆ notify_online_()

void esphome::modbus_controller::ControllerDevice::notify_online_ ( std::span< const uint8_t > request_pdu)
protected

Definition at line 42 of file modbus_controller.cpp.

◆ on_error()

void esphome::modbus_controller::ControllerDevice::on_error ( std::span< const uint8_t > request_pdu,
modbus::ExceptionCode exception_code )
overrideprotectedvirtual

Reimplemented from esphome::modbus::ModbusClientDevice.

Reimplemented in esphome::modbus_controller::WriterDevice.

Definition at line 52 of file modbus_controller.cpp.

◆ on_no_response()

bool esphome::modbus_controller::ControllerDevice::on_no_response ( std::span< const uint8_t > request_pdu)
overrideprotectedvirtual

Reimplemented from esphome::modbus::ModbusClientDevice.

Definition at line 89 of file modbus_controller.cpp.

◆ on_not_sent()

void esphome::modbus_controller::ControllerDevice::on_not_sent ( std::span< const uint8_t > request_pdu)
overrideprotectedvirtual

Reimplemented from esphome::modbus::ModbusClientDevice.

Definition at line 77 of file modbus_controller.cpp.

◆ on_response()

void esphome::modbus_controller::ControllerDevice::on_response ( std::span< const uint8_t > request_pdu,
std::span< const uint8_t > response_pdu )
overrideprotectedvirtual

◆ on_sent()

void esphome::modbus_controller::ControllerDevice::on_sent ( std::span< const uint8_t > request_pdu)
overrideprotectedvirtual

Reimplemented from esphome::modbus::ModbusClientDevice.

Definition at line 71 of file modbus_controller.cpp.

◆ set_controller()

void esphome::modbus_controller::ControllerDevice::set_controller ( ModbusController * controller)

Definition at line 30 of file modbus_controller.cpp.

Field Documentation

◆ controller_

ModbusController* esphome::modbus_controller::ControllerDevice::controller_ {nullptr}
protected

Definition at line 287 of file modbus_controller.h.

◆ dispatched_

bool esphome::modbus_controller::ControllerDevice::dispatched_ {false}
protected

Write-path state owned by WriterEntity's forwarders, stored here so both bools land in the base's tail padding instead of adding a word to every writer entity.

The warn flag leaves in 2027.3.0.

Definition at line 285 of file modbus_controller.h.

◆ write_buffer_deprecated_warned_

bool esphome::modbus_controller::ControllerDevice::write_buffer_deprecated_warned_ {false}
protected

Definition at line 286 of file modbus_controller.h.


The documentation for this class was generated from the following files: