ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
esphome::modbus::ModbusClientDevice Class Reference

#include <modbus.h>

Inheritance diagram for esphome::modbus::ModbusClientDevice:
esphome::growatt_solar::GrowattSolar esphome::havells_solar::HavellsSolar esphome::kuntze::Kuntze esphome::modbus_controller::ModbusController esphome::pzemac::PZEMAC esphome::pzemdc::PZEMDC esphome::sdm_meter::SDMMeter esphome::selec_meter::SelecMeter

Public Member Functions

 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)
 
virtual void on_response (std::span< const uint8_t > request_pdu, std::span< const uint8_t > response_pdu)
 Called with the request PDU this device sent and the response PDU received (both: function code + data, no address, no CRC).
 
virtual void on_error (std::span< const uint8_t > request_pdu, ModbusExceptionCode exception_code)
 Called with the request PDU and the modbus exception code decoded from the error response.
 
virtual void on_not_sent ()
 
virtual bool on_no_response ()
 Called when no (valid) response arrived; return true to have the hub re-queue the frame for a retry.
 
 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()
 
void send (uint8_t function, uint16_t start_address, uint16_t number_of_entities, uint8_t payload_len=0, const uint8_t *payload=nullptr)
 
void send_pdu (std::span< const uint8_t > pdu)
 
void send_raw (const std::vector< uint8_t > &payload)
 
void clear_tx_queue_for_address (bool clear_sent=true)
 
void clear_tx_queue_for_device ()
 
 ESPDEPRECATED ("Use ready_for_immediate_send() instead. Removed in 2026.9.0", "2026.3.0") bool waiting_for_response()
 
bool ready_for_immediate_send ()
 

Protected Attributes

ModbusClientHubparent_ {nullptr}
 
uint8_t address_ {0}
 

Detailed Description

Definition at line 168 of file modbus.h.

Constructor & Destructor Documentation

◆ ModbusClientDevice() [1/4]

esphome::modbus::ModbusClientDevice::ModbusClientDevice ( )
default

◆ ModbusClientDevice() [2/4]

esphome::modbus::ModbusClientDevice::ModbusClientDevice ( ModbusClientHub * parent,
uint8_t address )
inline

Definition at line 171 of file modbus.h.

◆ ~ModbusClientDevice()

virtual esphome::modbus::ModbusClientDevice::~ModbusClientDevice ( )
inlinevirtual

Definition at line 172 of file modbus.h.

◆ ModbusClientDevice() [3/4]

esphome::modbus::ModbusClientDevice::ModbusClientDevice ( const ModbusClientDevice & )
delete

◆ ModbusClientDevice() [4/4]

esphome::modbus::ModbusClientDevice::ModbusClientDevice ( ModbusClientDevice && )
delete

Member Function Documentation

◆ clear_tx_queue_for_address()

void esphome::modbus::ModbusClientDevice::clear_tx_queue_for_address ( bool clear_sent = true)
inline

Definition at line 221 of file modbus.h.

◆ clear_tx_queue_for_device()

void esphome::modbus::ModbusClientDevice::clear_tx_queue_for_device ( )
inline

Definition at line 224 of file modbus.h.

◆ ESPDEPRECATED() [1/3]

esphome::modbus::ModbusClientDevice::ESPDEPRECATED ( "Override on_no_response() instead. Removed in 2027.2.0" ,
"2026.8.0"  )
inline

Definition at line 210 of file modbus.h.

◆ ESPDEPRECATED() [2/3]

esphome::modbus::ModbusClientDevice::ESPDEPRECATED ( "Override on_not_sent() instead. Removed in 2027.2.0" ,
"2026.8.0"  )
inline

Definition at line 207 of file modbus.h.

◆ ESPDEPRECATED() [3/3]

esphome::modbus::ModbusClientDevice::ESPDEPRECATED ( "Use ready_for_immediate_send() instead. Removed in 2026.9.0" ,
"2026.3.0"  )
inline

Definition at line 227 of file modbus.h.

◆ on_error()

virtual void esphome::modbus::ModbusClientDevice::on_error ( std::span< const uint8_t > request_pdu,
ModbusExceptionCode exception_code )
inlinevirtual

Called with the request PDU and the modbus exception code decoded from the error response.

Reimplemented in esphome::modbus_controller::ModbusController.

Definition at line 187 of file modbus.h.

◆ on_no_response()

virtual bool esphome::modbus::ModbusClientDevice::on_no_response ( )
inlinevirtual

Called when no (valid) response arrived; return true to have the hub re-queue the frame for a retry.

The hub does not bound retries: the device is responsible for limiting them (e.g. track a counter and return false when exhausted), or an unresponsive peer will starve other traffic on the bus.

Definition at line 200 of file modbus.h.

◆ on_not_sent()

virtual void esphome::modbus::ModbusClientDevice::on_not_sent ( )
inlinevirtual

Definition at line 191 of file modbus.h.

◆ on_response()

virtual void esphome::modbus::ModbusClientDevice::on_response ( std::span< const uint8_t > request_pdu,
std::span< const uint8_t > response_pdu )
inlinevirtual

Called with the request PDU this device sent and the response PDU received (both: function code + data, no address, no CRC).

The spans are only valid for the duration of the call - copy the bytes if they must outlive it. Slice the payload out of the response with helpers::server_pdu_payload().

Reimplemented in esphome::growatt_solar::GrowattSolar, esphome::havells_solar::HavellsSolar, esphome::kuntze::Kuntze, esphome::modbus_controller::ModbusController, esphome::pzemac::PZEMAC, esphome::pzemdc::PZEMDC, esphome::sdm_meter::SDMMeter, and esphome::selec_meter::SelecMeter.

Definition at line 185 of file modbus.h.

◆ operator=() [1/2]

ModbusClientDevice & esphome::modbus::ModbusClientDevice::operator= ( const ModbusClientDevice & )
delete

◆ operator=() [2/2]

ModbusClientDevice & esphome::modbus::ModbusClientDevice::operator= ( ModbusClientDevice && )
delete

◆ ready_for_immediate_send()

bool esphome::modbus::ModbusClientDevice::ready_for_immediate_send ( )
inline

Definition at line 229 of file modbus.h.

◆ send()

void esphome::modbus::ModbusClientDevice::send ( uint8_t function,
uint16_t start_address,
uint16_t number_of_entities,
uint8_t payload_len = 0,
const uint8_t * payload = nullptr )
inline

Definition at line 212 of file modbus.h.

◆ send_pdu()

void esphome::modbus::ModbusClientDevice::send_pdu ( std::span< const uint8_t > pdu)
inline

Definition at line 219 of file modbus.h.

◆ send_raw()

void esphome::modbus::ModbusClientDevice::send_raw ( const std::vector< uint8_t > & payload)
inline

Definition at line 220 of file modbus.h.

◆ set_address()

void esphome::modbus::ModbusClientDevice::set_address ( uint8_t address)
inline

Definition at line 181 of file modbus.h.

◆ set_parent()

void esphome::modbus::ModbusClientDevice::set_parent ( ModbusClientHub * parent)
inline

Definition at line 180 of file modbus.h.

Field Documentation

◆ address_

uint8_t esphome::modbus::ModbusClientDevice::address_ {0}
protected

Definition at line 233 of file modbus.h.

◆ parent_

ModbusClientHub* esphome::modbus::ModbusClientDevice::parent_ {nullptr}
protected

Definition at line 232 of file modbus.h.


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