ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
esphome::modbus Namespace Reference

Namespaces

namespace  helpers
 

Data Structures

struct  CommandOptions
 
class  Modbus
 
class  ModbusClientDevice
 Callback contract. More...
 
class  ModbusClientHub
 
struct  ModbusDeviceCommand
 
struct  ModbusFrame
 
class  ModbusServerDevice
 
class  ModbusServerHub
 
class  MutablePackedBits
 Mutable counterpart of PackedBits: set() writes bits in place (deliberately no proxy operator[]=). More...
 
class  PackedBits
 Read-only view of Modbus-packed bits: bit 0 of byte 0 is the first bit (LSB first), the layout coil/discrete-input values use on the wire. More...
 

Typedefs

using ResponseStatus = std::optional<ExceptionCode>
 
using RegisterValues = StaticVector<uint16_t, MAX_NUM_OF_REGISTERS_TO_READ>
 

Enumerations

enum class  CommandPriority : uint8_t { CONTINUOUS = 0 , READ , WRITE }
 
enum class  FrameState : uint8_t {
  READY = 0 , WAITING , RECEIVED_RESPONSE , RECEIVED_EXCEPTION ,
  TIMED_OUT , INTERRUPTED , WAITING_RETIRED , INTERRUPTED_RETIRED ,
  RETIRED
}
 
enum class  FunctionCode : uint8_t {
  INVALID = 0x00 , ESPDEPRECATED , READ_COILS = 0x01 , READ_DISCRETE_INPUTS = 0x02 ,
  READ_HOLDING_REGISTERS = 0x03 , READ_INPUT_REGISTERS = 0x04 , WRITE_SINGLE_COIL = 0x05 , WRITE_SINGLE_REGISTER = 0x06 ,
  READ_EXCEPTION_STATUS = 0x07 , DIAGNOSTICS = 0x08 , GET_COMM_EVENT_COUNTER = 0x0B , GET_COMM_EVENT_LOG = 0x0C ,
  WRITE_MULTIPLE_COILS = 0x0F , WRITE_MULTIPLE_REGISTERS = 0x10 , REPORT_SERVER_ID = 0x11 , READ_FILE_RECORD = 0x14 ,
  WRITE_FILE_RECORD = 0x15 , MASK_WRITE_REGISTER = 0x16 , READ_WRITE_MULTIPLE_REGISTERS = 0x17 , READ_FIFO_QUEUE = 0x18
}
 
enum class  EntityType : uint8_t {
  CUSTOM = 0x00 , COIL = 0x01 , DISCRETE_INPUT = 0x02 , HOLDING = 0x03 ,
  INPUT_REGISTER = 0x04 , ESPDEPRECATED =("Use EntityType::INPUT_REGISTER instead. Removed in 2027.2.0", "2026.7.0") = INPUT_REGISTER
}
 
enum class  ExceptionCode : uint8_t {
  ILLEGAL_FUNCTION = 0x01 , ILLEGAL_DATA_ADDRESS = 0x02 , ILLEGAL_DATA_VALUE = 0x03 , SERVICE_DEVICE_FAILURE = 0x04 ,
  ACKNOWLEDGE = 0x05 , SERVER_DEVICE_BUSY = 0x06 , MEMORY_PARITY_ERROR = 0x08 , GATEWAY_PATH_UNAVAILABLE = 0x0A ,
  GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 0x0B
}
 

Functions

bool succeeded (ResponseStatus status)
 True when a transaction carried no exception.
 
bool operator== (FunctionCode lhs, uint8_t rhs)
 
bool operator== (uint8_t lhs, FunctionCode rhs)
 
bool operator!= (FunctionCode lhs, uint8_t rhs)
 
bool operator!= (uint8_t lhs, FunctionCode rhs)
 
constexpr size_t packed_bit_bytes (size_t bits)
 Bits pack 8 per data byte, rounded up to whole bytes.
 

Variables

const uint8_t FUNCTION_CODE_USER_DEFINED_SPACE_1_INIT = 65
 Modbus definitions from specs: https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf.
 
const uint8_t FUNCTION_CODE_USER_DEFINED_SPACE_1_END = 72
 
const uint8_t FUNCTION_CODE_USER_DEFINED_SPACE_2_INIT = 100
 
const uint8_t FUNCTION_CODE_USER_DEFINED_SPACE_2_END = 110
 
const uint8_t FUNCTION_CODE_MASK = 0x7F
 
const uint8_t FUNCTION_CODE_EXCEPTION_MASK = 0x80
 

Typedef Documentation

◆ RegisterValues

using esphome::modbus::RegisterValues = StaticVector<uint16_t, MAX_NUM_OF_REGISTERS_TO_READ>

Definition at line 314 of file modbus.h.

◆ ResponseStatus

Definition at line 306 of file modbus.h.

Enumeration Type Documentation

◆ CommandPriority

enum class esphome::modbus::CommandPriority : uint8_t
strong
Enumerator
CONTINUOUS 
READ 
WRITE 

Definition at line 95 of file modbus.h.

◆ EntityType

enum class esphome::modbus::EntityType : uint8_t
strong
Enumerator
CUSTOM 
COIL 
DISCRETE_INPUT 
HOLDING 
INPUT_REGISTER 
ESPDEPRECATED 

Definition at line 58 of file modbus_definitions.h.

◆ ExceptionCode

enum class esphome::modbus::ExceptionCode : uint8_t
strong
Enumerator
ILLEGAL_FUNCTION 
ILLEGAL_DATA_ADDRESS 
ILLEGAL_DATA_VALUE 
SERVICE_DEVICE_FAILURE 
ACKNOWLEDGE 
SERVER_DEVICE_BUSY 
MEMORY_PARITY_ERROR 
GATEWAY_PATH_UNAVAILABLE 
GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND 

Definition at line 76 of file modbus_definitions.h.

◆ FrameState

enum class esphome::modbus::FrameState : uint8_t
strong
Enumerator
READY 
WAITING 
RECEIVED_RESPONSE 
RECEIVED_EXCEPTION 
TIMED_OUT 
INTERRUPTED 
WAITING_RETIRED 
INTERRUPTED_RETIRED 
RETIRED 

Definition at line 99 of file modbus.h.

◆ FunctionCode

enum class esphome::modbus::FunctionCode : uint8_t
strong
Enumerator
INVALID 
ESPDEPRECATED 
READ_COILS 
READ_DISCRETE_INPUTS 
READ_HOLDING_REGISTERS 
READ_INPUT_REGISTERS 
WRITE_SINGLE_COIL 
WRITE_SINGLE_REGISTER 
READ_EXCEPTION_STATUS 
DIAGNOSTICS 
GET_COMM_EVENT_COUNTER 
GET_COMM_EVENT_LOG 
WRITE_MULTIPLE_COILS 
WRITE_MULTIPLE_REGISTERS 
REPORT_SERVER_ID 
READ_FILE_RECORD 
WRITE_FILE_RECORD 
MASK_WRITE_REGISTER 
READ_WRITE_MULTIPLE_REGISTERS 
READ_FIFO_QUEUE 

Definition at line 21 of file modbus_definitions.h.

Function Documentation

◆ operator!=() [1/2]

bool esphome::modbus::operator!= ( FunctionCode lhs,
uint8_t rhs )
inline

Definition at line 52 of file modbus_definitions.h.

◆ operator!=() [2/2]

bool esphome::modbus::operator!= ( uint8_t lhs,
FunctionCode rhs )
inline

Definition at line 53 of file modbus_definitions.h.

◆ operator==() [1/2]

bool esphome::modbus::operator== ( FunctionCode lhs,
uint8_t rhs )
inline

Definition at line 50 of file modbus_definitions.h.

◆ operator==() [2/2]

bool esphome::modbus::operator== ( uint8_t lhs,
FunctionCode rhs )
inline

Definition at line 51 of file modbus_definitions.h.

◆ packed_bit_bytes()

size_t esphome::modbus::packed_bit_bytes ( size_t bits)
constexpr

Bits pack 8 per data byte, rounded up to whole bytes.

Definition at line 133 of file modbus_definitions.h.

◆ succeeded()

bool esphome::modbus::succeeded ( ResponseStatus status)
inline

True when a transaction carried no exception.

Definition at line 309 of file modbus.h.

Variable Documentation

◆ FUNCTION_CODE_EXCEPTION_MASK

const uint8_t esphome::modbus::FUNCTION_CODE_EXCEPTION_MASK = 0x80

Definition at line 74 of file modbus_definitions.h.

◆ FUNCTION_CODE_MASK

const uint8_t esphome::modbus::FUNCTION_CODE_MASK = 0x7F

Definition at line 73 of file modbus_definitions.h.

◆ FUNCTION_CODE_USER_DEFINED_SPACE_1_END

const uint8_t esphome::modbus::FUNCTION_CODE_USER_DEFINED_SPACE_1_END = 72

Definition at line 16 of file modbus_definitions.h.

◆ FUNCTION_CODE_USER_DEFINED_SPACE_1_INIT

const uint8_t esphome::modbus::FUNCTION_CODE_USER_DEFINED_SPACE_1_INIT = 65

◆ FUNCTION_CODE_USER_DEFINED_SPACE_2_END

const uint8_t esphome::modbus::FUNCTION_CODE_USER_DEFINED_SPACE_2_END = 110

Definition at line 19 of file modbus_definitions.h.

◆ FUNCTION_CODE_USER_DEFINED_SPACE_2_INIT

const uint8_t esphome::modbus::FUNCTION_CODE_USER_DEFINED_SPACE_2_INIT = 100

Definition at line 18 of file modbus_definitions.h.