When trying to modify the modbus slave example i've run into some issues.
I'm trying to print the registers values after they have been changed however the value never changes on the esp32 side.
Running the modbus poll tool shows that after i've written a value to the esp32 slave that it has changed after reading again with the tool.
On the esp side the variable doesn't seem to update though for some reason.
This is using esp-idf 4.0
Code: Select all
if(event & (MB_EVENT_HOLDING_REG_WR | MB_EVENT_HOLDING_REG_RD)) {
// Get parameter information from parameter queue
ESP_ERROR_CHECK(mbc_slave_get_param_info(®_info, MB_PAR_INFO_GET_TOUT));
printf("HOLDING %s: time_stamp(us):%u, mb_addr:%u, type:%u, st_address:0x%.4x, size:%u\r\n",
rw_str,
(uint32_t)reg_info.time_stamp,
(uint32_t)reg_info.mb_offset,
(uint32_t)reg_info.type,
(uint32_t)reg_info.address,
(uint32_t)reg_info.size);
if (reg_info.address == (uint8_t*)&holding_reg_params.data_chan2)
{
// do something
printf("Holding reg value, %f", holding_reg_params.data_chan2);
}
Holding reg value, 0.000000HOLDING WRITE: time_stamp(us):38686618, mb_addr:1, type:1, st_address:0x3ffb2f94, size:4
Holding reg value, 0.000000HOLDING READ: time_stamp(us):42933014, mb_addr:1, type:2, st_address:0x3ffb2f94, size:4
Holding reg value, 0.000000HOLDING READ: time_stamp(us):46748690, mb_addr:1, type:2, st_address:0x3ffb2f94, size:4
Holding reg value, 0.000000HOLDING READ: time_stamp(us):47860313, mb_addr:1, type:2, st_address:0x3ffb2f94, size:4
This same method works fine for the coil registers but i seem to be stuck at trying to make the holding registers work.
So any insight would be much appreciated.