|
| | ModbusClientDevice ()=default |
| |
| | ModbusClientDevice (ModbusClientHub *parent, uint8_t address) |
| |
| virtual | ~ModbusClientDevice () |
| |
| | ModbusClientDevice (const ModbusClientDevice &)=delete |
| |
| ModbusClientDevice & | operator= (const ModbusClientDevice &)=delete |
| |
| | ModbusClientDevice (ModbusClientDevice &&)=delete |
| |
| ModbusClientDevice & | operator= (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) |
| | Low-level response hook: called with the request PDU this device sent and the response PDU received The spans are only valid for the duration of the call - copy the bytes if they must outlive it.
|
| |
| virtual void | on_error (std::span< const uint8_t > request_pdu, ExceptionCode exception_code) |
| | Low-level error hook: called with the request PDU and the modbus exception code from the error response.
|
| |
| virtual void | on_not_sent (std::span< const uint8_t > request_pdu) |
| | Called when an accepted request was dropped before transmission by clear_tx_queue_for_address().
|
| |
| virtual void | on_sent (std::span< const uint8_t > request_pdu) |
| | Called when this device's frame is actually written to the wire.
|
| |
| virtual bool | on_no_response (std::span< const uint8_t > request_pdu) |
| | Called when no matching, uninterrupted 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() |
| |
| 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 |
| |
Callback contract.
Each accepted request ends in exactly ONE terminal: on_response() (data), on_error() (exception), on_no_response() (timeout/interruption), or on_not_sent() (dropped by clear_tx_queue_for_address before transmission). A request refused at queue_pdu() (false return) gets none, and a broadcast (address 0) gets on_sent() with NO terminal, since a broadcast is never answered (Modbus 4.1). on_sent() is additional, once per transmission, never for an on_not_sent() request. on_response()/on_error() fire at parse time and on_no_response() at the send-wait watchdog, all from a quiescent hub; only on_not_sent() is delivered by the sweep. Sending or clearing from inside a callback is safe (picked up by the next sweep). Exceptions to "exactly one terminal": a broadcast is fire-and-forget (on_sent, no terminal); clear_tx_queue_for_device() drops the caller's own frames silently; a continuous poll's cycles are its own accounting (a one-shot duplicate downgrades the poll to a one-shot; a continuous duplicate merges into it).
Invariants:
- Public entry points (queue_pdu/clear_tx_queue_*) only append to the queue or mutate an existing entry through its callback-free transition methods.
- Public entry points can never trigger a callback synchronously.
- Callbacks are delivered only from within loop().
- At most one callback is ever issued between calls to sweep_(): sweep_ -> parse (response OR error) OR timeout (no_response) -> sweep_ -> send (sent) -> sweep_ (next loop)
Definition at line 440 of file modbus.h.
| virtual void esphome::modbus::ModbusClientDevice::on_response |
( |
std::span< const uint8_t > | request_pdu, |
|
|
std::span< const uint8_t > | response_pdu ) |
|
inlinevirtual |
| virtual void esphome::modbus::ModbusClientDevice::on_write_single_register |
( |
uint16_t | address, |
|
|
uint16_t | value, |
|
|
ResponseStatus | status ) |
|
inlinevirtual |
Write acknowledgements.
These deliberately mirror the read callbacks' shapes, so a write ack can be fed through the same handler as a read (registers.size() / bits.size() gives the count)
IMPORTANT - for the multi-writes these are the values that were REQUESTED, not device-confirmed state: a multi-write ack only echoes the start address and count, so the values are decoded from the request PDU, and they are delivered even when status holds an exception code. Always check status, and treat publishing them as an optimistic update rather than a read-back. The single writes are the exception: their successful ack echoes the value, so on success the delivered value is the device's echo (on an exception it falls back to the request copy).
Reimplemented in esphome::modbus_client::WriteSingleRegisterAction< Ts >.
Definition at line 525 of file modbus.h.