|
enum class | ModbusFunctionCode {
CUSTOM = 0x00
, 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 | ModbusRegisterType : uint8_t {
CUSTOM = 0x0
, COIL = 0x01
, DISCRETE_INPUT = 0x02
, HOLDING = 0x03
,
READ = 0x04
} |
|
enum class | SensorValueType : uint8_t {
RAW = 0x00
, U_WORD = 0x1
, U_DWORD = 0x2
, S_WORD = 0x3
,
S_DWORD = 0x4
, BIT = 0x5
, U_DWORD_R = 0x6
, S_DWORD_R = 0x7
,
U_QWORD = 0x8
, S_QWORD = 0x9
, U_QWORD_R = 0xA
, S_QWORD_R = 0xB
,
FP32 = 0xC
, FP32_R = 0xD
} |
|
enum class | RawEncoding { NONE = 0
, HEXBYTES = 1
, COMMA = 2
, ANSI = 3
} |
|
|
void | number_to_payload (std::vector< uint16_t > &data, int64_t value, SensorValueType value_type) |
| Convert float value to vector<uint16_t> suitable for sending.
|
|
int64_t | payload_to_number (const std::vector< uint8_t > &data, SensorValueType sensor_value_type, uint8_t offset, uint32_t bitmask) |
| Convert vector<uint8_t> response payload to number.
|
|
ModbusFunctionCode | modbus_register_read_function (ModbusRegisterType reg_type) |
|
ModbusFunctionCode | modbus_register_write_function (ModbusRegisterType reg_type) |
|
uint8_t | c_to_hex (char c) |
|
uint8_t | byte_from_hex_str (const std::string &value, uint8_t pos) |
| Get a byte from a hex string hex_byte_from_str("1122",1) returns uint_8 value 0x22 == 34 hex_byte_from_str("1122",0) returns 0x11.
|
|
uint16_t | word_from_hex_str (const std::string &value, uint8_t pos) |
| Get a word from a hex string.
|
|
uint32_t | dword_from_hex_str (const std::string &value, uint8_t pos) |
| Get a dword from a hex string.
|
|
uint64_t | qword_from_hex_str (const std::string &value, uint8_t pos) |
| Get a qword from a hex string.
|
|
template<typename T > |
T | get_data (const std::vector< uint8_t > &data, size_t buffer_offset) |
| Extract data from modbus response buffer.
|
|
bool | coil_from_vector (int coil, const std::vector< uint8_t > &data) |
| Extract coil data from modbus response buffer Responses for coil are packed into bytes .
|
|
template<typename N > |
N | mask_and_shift_by_rightbit (N data, uint32_t mask) |
| Extract bits from value and shift right according to the bitmask if the bitmask is 0x00F0 we want the values frrom bit 5 - 8.
|
|
float | payload_to_float (const std::vector< uint8_t > &data, const SensorItem &item) |
| Convert vector<uint8_t> response payload to float.
|
|
std::vector< uint16_t > | float_to_payload (float value, SensorValueType value_type) |
|
template<typename N >
N esphome::modbus_controller::mask_and_shift_by_rightbit |
( |
N | data, |
|
|
uint32_t | mask ) |
Extract bits from value and shift right according to the bitmask if the bitmask is 0x00F0 we want the values frrom bit 5 - 8.
the result is then shifted right by the position if the first right set bit in the mask Useful for modbus data where more than one value is packed in a 16 bit register Example: on Epever the "Length of night" register 0x9065 encodes values of the whole night length of time as D15 - D8 = hour, D7 - D0 = minute To get the hours use mask 0xFF00 and 0x00FF for the minute
- Parameters
-
data | an integral value between 16 aand 32 bits, |
bitmask | the bitmask to apply |
Definition at line 197 of file modbus_controller.h.