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
mbc_master_send_request - Exception Codes (IDFGH-12757) #60
Comments
Thank you for this issue. It is a very good question. Unfortunately, the current API do propagate the error code to indicate an exception but do not provide the way to determine the exact code of exception and the way of handling for this. I don't have nice solution for this but can provide the simple workarounds for this issue. One solution will not involve the changes in the library code. |
I propose the workaround to add the user error handler function to catch the exception code. It also allows to check the data buffers on user side (this can be useful for some gateways). Please take a look and let me know if this would work for you. Thanks. |
This may work quite well for most users imo, but I am unsure if it would be the best solution for my use case since I am working on a more object oriented (and C++ based) library based on esp-modbus and I am unsure how to implement this error handler in a manner that is compatible with my approach, although I do believe it should be possible. |
I understand your requirement. It is still possible to implement this with the callback but can agree this is like workaround but not the nice approach to do. The best approach would be to propagate the possible exception codes to the subset error codes returned from |
I believe a possible way to handle this might be by adding either a function What could also work is by maybe refactoring the function to return this struct: typedef struct {
const esp_err_t err;
const uint8_t function_code;
const uint8_t exception_code;
} slave_return_t The caller can then read the error code from that structure and handle any exception accordingly, if the error code signifies an exception occured. What may definitively be needed is an error code excplicitly alerting the program that an exception has occured, rather than Obviously this second approach would definitely break the current API. |
This way will not be implemented.
Your approach is a bit different with what I mentioned the function mbc_master_get_transaction_info |
That function would be almost exactly what I need and I could easily integrate this into my library |
Ok, good. This will be updated accordingly and let us keep it as a basic approach. I would keep the callback approach as well, because it can be useful in some other user use cases. |
This old CPP wrapper will probably help you. |
Thanks but see my answer in the associated Repo. |
When
mbc_master_send_request
returns anESP_FAIL
to the caller, the documentation states that an exception or other failure occurred. However, it is unclear how to determine what might be the case, since:Clarifying information, and adding to the documentation, about this would be helpful, since the documentation is currently quite ambiguous in this regard.
The text was updated successfully, but these errors were encountered: