Read Multiple String Registers using Master MODBUS RTU

PoojaVernekar
Posts: 3
Joined: Thu Jul 08, 2021 6:19 am

Read Multiple String Registers using Master MODBUS RTU

Postby PoojaVernekar » Mon Mar 07, 2022 9:19 am

I am communicating ESP32-WROOM32D with Inverter using RS485 lines.
Able to read all electrical parameters like AC, DC voltage and current. I am using Holding registers for reading Electrical parameters.

My struggle is want to read Manufacturer Serial Number of Inverter, using Input Registers.
0x2001 to 0x2007 - Manufacturer serial number.


This is how i have defined CID, last one is for reading Serial Number.
{
CID_HOLD_DATA_0, STR("DC VOLTAGE"), STR("VOLTS"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0006, 2,
HOLD_OFFSET(dc_voltage), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_1, STR("DC CURRENT"), STR("AMPS"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0007, 2,
HOLD_OFFSET(dc_current), PARAM_TYPE_U16, 2, OPTS(0,100,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_2, STR("AC VOLTAGE"), STR("VOLTS"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x000F, 2,
HOLD_OFFSET(ac_voltage), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_3, STR("AC CURRENT"), STR("AMPS"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0010, 2,
HOLD_OFFSET(ac_current), PARAM_TYPE_U16, 2, OPTS(0,100,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_4, STR("AC FREQUENCY"), STR("HZ"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x000E, 2,
HOLD_OFFSET(ac_frequency), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_5, STR("TODAY ENERGY"), STR("KWH"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0019, 2,
HOLD_OFFSET(todays_energy), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_6, STR("ALL TIME ENERGY-MSB"), STR("-"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0015, 2,
HOLD_OFFSET(all_time_energy_msb), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_7, STR("ALL TIME ENERGY-LSB"), STR("-"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0016, 2,
HOLD_OFFSET(all_time_energy_lsb), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_8, STR("INVERTER TEMPERATURE"), STR("DEG C"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x001C, 2,
HOLD_OFFSET(inverter_temperature), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_9, STR("INVERTER STATUS"), STR("-"), MB_DEVICE_ADDR_1, MB_PARAM_HOLDING, 0x0000, 2,
HOLD_OFFSET(inverter_status), PARAM_TYPE_U16, 2, OPTS(0,600,1), PAR_PERMS_READ
},
{
CID_HOLD_DATA_10, STR("INVERTER SN"), STR("-"), MB_DEVICE_ADDR_1, MB_PARAM_INPUT, 0x2001, 7,
HOLD_OFFSET(inverter_sn), PARAM_TYPE_ASCII, 116, OPTS(0,100,0), PAR_PERMS_READ
},

ESP32 Output :

I (1839176) HAVELLS_ENVIRO_MODBUS: Running Havells inverter modbus client task
I (1839176) HAVELLS_ENVIRO_MODBUS: Querying inverter 1/3

I (1839176) uart: queue free spaces: 20
I (1839226) HAVELLS_ENVIRO_MODBUS: Modbus Client stack for HAVELLS inverter initialized...
I (1839226) HAVELLS_ENVIRO_MODBUS: The current date/time in India Mon Mar 7 14:43:51 2022
I (1839266) HAVELLS_ENVIRO_MODBUS: 0, key: DC VOLTAGE, VOLTS 0 value 3962(0xf7a)

I (1839296) HAVELLS_ENVIRO_MODBUS: 1, key: DC CURRENT, AMPS 0 value 124(0x7c)

I (1839326) HAVELLS_ENVIRO_MODBUS: 2, key: AC VOLTAGE, VOLTS 0 value 2313(0x909)

I (1839366) HAVELLS_ENVIRO_MODBUS: 3, key: AC CURRENT, AMPS 0 value 212(0xd4)

I (1839396) HAVELLS_ENVIRO_MODBUS: 4, key: AC FREQUENCY, HZ 0 value 4983(0x1377)

I (1839436) HAVELLS_ENVIRO_MODBUS: 5, key: TODAY ENERGY, KWH 0 value 217(0xd9)

I (1839466) HAVELLS_ENVIRO_MODBUS: 6, key: ALL TIME ENERGY-MSB, - 0 value 0(0x0)

I (1839506) HAVELLS_ENVIRO_MODBUS: 7, key: ALL TIME ENERGY-LSB, - 0 value 24(0x18)

I (1839536) HAVELLS_ENVIRO_MODBUS: 8, key: INVERTER TEMPERATURE, DEG C 0 value 53(0x35)

I (1839566) HAVELLS_ENVIRO_MODBUS: 9, key: INVERTER STATUS, - 0 value 2(0x2)

E (1839716) MB_CONTROLLER_MASTER: mbc_master_get_parameter(111): SERIAL master get parameter failure error=(0x107) (ESP_ERR_TIMEOUT).
I (1839726) HAVELLS_ENVIRO_MODBUS: Modbus client stack unloaded
{"device_serial_number": "HAVELLS-1", "modbus_address": 1, "objectType": "havells-telemetry", "deviceType": "HAVELLS", "GatewayId": "ARKAPGOLA--HAVELLS--ALPHA2","timestamp": 1646644431, "timestamp_v": "Mon Mar 7 14:43:51 2022", "error" : "error reading modbus parameter" }
Current time = Mon Mar 7 14:43:51 2022




How can i read Alpha Numeric values using MODBUS RTU. ???????
Please suggest

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

Re: Read Multiple String Registers using Master MODBUS RTU

Postby ESP_alisitsyn » Mon Mar 14, 2022 9:06 am

Hi @PoojaVernekar ,

If you use the official Modbus serial example
https://github.com/espressif/esp-idf/bl ... ster.c#L84
then to save the value of the input registers correctly, you need to set up a separate structure for input registers and set offset for its field in the data dictionary.

Code: Select all

INPUT_OFFSET(inverter_sn)
Please also make sure your offset = 0x2001 is correct according to your device mapping table.

The ESP_ERR_TIMEOUT error means the slave could not recognize your request. Try to send the same request using ModbusPoll first then follow with the configuration of your master.

Code: Select all

{
CID_INPUT_DATA_10, STR("INVERTER SN"), STR("-"), MB_DEVICE_ADDR_1, MB_PARAM_INPUT, 0x2001, 7,
INPUT_OFFSET(inverter_sn), PARAM_TYPE_ASCII, 14, OPTS(0,100,0), PAR_PERMS_READ
},

Who is online

Users browsing this forum: cfyronald96 and 86 guests