Page 1 of 1

read multiple registers in modbus RTU

Posted: Thu May 16, 2024 12:02 pm
by manas_frinso
I want to read 4 register values together , I am successful in getting a response. But I am only able to read the first 2 register values.
This is how I have defined my values
{ CID_INP_DATA_0, STR("active_energy"), STR(" "), MB_DEVICE_ADDR1, MB_PARAM_INPUT, 01127, 4,
INPUT_OFFSET(data_block1), PARAM_TYPE_U16, 8, OPTS( 0, 0, 0 ), PAR_PERMS_READ_WRITE_TRIGGER },

if(param_descriptor->cid == 0){
ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = %08lX read successful.",
param_descriptor->cid,
(char*)param_descriptor->param_key,
(char*)param_descriptor->param_units,
value);
}

where am I making a mistake.

Re: read multiple registers in modbus RTU

Posted: Mon May 27, 2024 9:50 am
by ESP_alisitsyn
@manas_frinso ,

Your code missing some information on how the value is defined and how you read the data.
There are several possibilities to address the block of registers. One is using the

Code: Select all

 PARAM_TYPE_ASCII
type in data dictionary, then read the data to the instance of the data block. Then you can iterate through the elements of corresponded type or just address array elements by index. Other approach on how to address arrays of elements in Modbus I described here: https://esp32.com/viewtopic.php?f=13&t= ... lit=modbus. In this case you pack all the read elements into corresponded array of the same type and can iterate through them.