Hi @alllllllllllllllllll,
It supposed that device stores its specific data as device parameters of type (float, uint16_t, uint8_t, ascii, etc.) and its data mapped to Modbus register spaces (Holding registers, Input Registers, Coils, Discr inputs).
The master and slave examples contain instances for each type of Modbus register space and its data addresses by data dictionary:
https://github.com/espressif/esp-idf/bl ... ster.c#L88
The actual instances (structures that incapsulate device data) are located here:
https://github.com/espressif/esp-idf/bl ... rams.c#L10
This package contains data instances which are common for master and slave examples.
The example of data dictionary: The characteristic "Data_channel_0" below corresponds to parameter stored in slave device with address=MB_DEVICE_ADDR1 as input registers (MB_PARAM_INPUT) from modbus address 0, length of parameter in registers = 2 registers,
this parameter will be stored in the instance input_reg_params.input_data0 of float type, instance length in bytes = 4, Options defined, access for parameter set as R/W)
// { CID, Param Name, Units, Modbus Slave Addr, Modbus Reg Type, Reg Start, Reg Size, Instance Offset, Data Type, Data Size, Parameter Options, Access Mode}
{ CID_INP_DATA_0, STR("Data_channel_0"), STR("Volts"), MB_DEVICE_ADDR1, MB_PARAM_INPUT, 0, 2,
INPUT_OFFSET(input_data0), PARAM_TYPE_FLOAT, 4, OPTS( -10, 10, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
}
So, The Characteristic can be linked to any Modbus register or complex parameter within any slave and be stored in appropriate place or structure of device memory. This allows to integrate this approach easily with MQTT, MESH and other networks or protocols.
User can store parameters differently by modifying *_OFFSET(par) macro to calculate offset to actual parameter and modify the master_get_param_data() function to calculate the address of actual storage for each characteristic according to offset.
The data dictionary can be simplified to work with modbus registers instead of parameters.
In this case the data dictionary can be modified as:
const mb_parameter_descriptor_t device_parameters[] = {
// CID, Name, Units, Modbus addr, register type, Modbus Reg Start Addr, Modbus Reg read length,
// Instance offset (NA), Instance type, Instance length (bytes), Options (NA), Permissions
{ CID_DEV_REG0, STR("MB_hold_reg-0"), STR("Data"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0, 1,
0, PARAM_TYPE_U16, 2, OPTS( 0,0,0 ), PAR_PERMS_READ_WRITE_TRIGGER },
}
Please see the following topic for more information:
https://esp32.com/viewtopic.php?f=13&t= ... 150#p63158
Let me know if you have further questions.