read multiple registers in modbus RTU

manas_frinso
Posts: 3
Joined: Tue Apr 16, 2024 12:01 pm

read multiple registers in modbus RTU

Postby manas_frinso » Thu May 16, 2024 12:02 pm

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.

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: read multiple registers in modbus RTU

Postby ESP_alisitsyn » Mon May 27, 2024 9:50 am

@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.

Who is online

Users browsing this forum: No registered users and 395 guests