Support for Device / Vendor specific Modbus functions#113
Draft
GraceGRD wants to merge 1 commit into
Draft
Conversation
…RVER_CUSTOM_FUNCTION_ENABLED
Author
|
Marked it as draft as I do believe this is a useful feature for the library however, I don't think this is ready for production yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows support for implementing Device / Vendor specific functions.
Enable this feature by defining
#define NMBS_SERVER_CUSTOM_FUNCTION_ENABLED.I have tested this only for the Modbus RTU.
The
handle_req_fcis modified to any function codes that are not handled by the nanoModbus library through the default case to be handled byhandle_custom_function.The
handle_custom_functiondoes only validate the CRC of the frame before passing the data and size through the callback function. The user is responsible for modifying the data buffer and patching the size. Then the function appends the CRC and sends back the response.For this function to work the size of the Modbus frame must be known. I decided to pass this through the
nmbs->platform.argpointer like this (I'm not sure if this is the way to do it however this works for me):Then register a handler for the custom function (example custom function below):
platform_conf.custom_function = CustomFunctionHandler;