-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send request not updating buffer (IDFGH-14966) #108
Comments
Hello @RoootNoodle, Thank you for your report. I can see in your log the response has been correctly received, but the data is mapped incorrectly.
This issue can be due to incorrect linking of the Could you let me know some aspects:
Thanks. |
I am using version 2.0.2 Should I make use of the mb_parameter_descriptor if the data is being read with mbc_master_send_request()? |
Thank you for the update. I will take a look to it and investigate when possible. Which esp-idf version is used?
It actually does not matter if you setup reading using the data dictionary or send the request directly (the read data shall be stored to parameter buffer). The mapping rw callback function shall be executed from the command handler from the event task context in both cases. The mapping function is correctly linked as per your map file and should be called from the handler. I need to reproduce this behavior but it is called on my side and maps the data correctly. The call below shall do the job: uint16_t holding_registers[2] = {0};
req.slave_addr = MB_DEVICE_ADDR1; // the slave UID to send the request
req.command = 0x03; // the function code,
req.reg_start = 0; // start register,
req.reg_size = 2; // length of the data to send (registers)
err = mbc_master_send_request(master_handle, &req, (void *)&holding_registers[0]);
if (err != ESP_OK) {
ESP_LOGE("CUSTOM_DATA", "Send custom request fail.");
} else {
ESP_LOG_BUFFER_HEX_LEVEL("READ_DATA", (void*)holding_registers, sizeof(holding_registers), ESP_LOG_WARN);
} Could you try to make sure that the callback |
I am using ESP-IDF v5.4.0, I used the same code as provided but the data still did not map. I will move the library and try again. |
I added the first two lines, there is still no change in the output. Could the problem with the setup in my code or is this library orientated? I'm attaching my main.c |
It is required to move library first to components folder! If it does not print the strings, please remove the weak attribute in the function prototype to check it instantiation:
then check if the function is called on request. |
This is just to check the reason on your side.
What kind of slave do you use? According to standard the slave should not respond to the broadcast request. Thanks. |
I got it working, thank you very much. The problem was with broadcasting the request to all the slaves and not requesting data from an individual slave. Changing the req.slave_addr = 1 fixed the problem. Thanks for the assistance |
Checklist
Issue or Suggestion Description
I want to read a 32bit float holding register value using the library as a master. As shown in the images, the correct value is received from the slave but does not get loaded into the buffer. I am not sure whether there is a bug on the library side or if made a mistake in the configuration. Please note the the guide provided by the link is very outdated and not all the functions shown in the link is available in the latest release.
https://docs.espressif.com/projects/esp-modbus/en/stable/esp32/overview_messaging_and_mapping.html
The image below show the code sent to the slave: 00 03 00 00 00 02 c5 da
With a reply: 00 03 04 41 45 70 a4 cb 61
The reply should be decoded as 12.34 but as seen the Float value = 0
The above values is confirmed by the image below
The loop to continuously send a request
The setup code
I also tried implementing a descriptor, but the result was the same, with only a 0 on return. As per my understanding, the mbc_master_send_request() function should trigger a callback function mbc_reg_holding_master_cb() to update the buffer value, which does not happen. The mbc_reg_holding_master_cb() is defined as a weak function, which im not certain whether to include some reference to it in my main.c.
I could not find help or a guide on the internet, any advice would be appreciated
The text was updated successfully, but these errors were encountered: