Skip to content
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

Add support for custom function codes. (IDFGH-13746) #75

Open
3 tasks done
klasrpersson opened this issue Sep 19, 2024 · 1 comment
Open
3 tasks done

Add support for custom function codes. (IDFGH-13746) #75

klasrpersson opened this issue Sep 19, 2024 · 1 comment
Assignees

Comments

@klasrpersson
Copy link

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Described the feature in detail and justified the reason for the request.
  • Provided specific use cases and examples.

Feature description

Add a way to write data to modbus slaves using arbitrary function codes. It could have an interface similar to eMBMasterReqWriteMultipleHoldingRegister but without the hardcoded function code.

Use cases

I need to upgrade the firmware of a modbus device and it uses function codes 0x13 and 0x14 to download and upgrade firmware respectively. These function codes are not supported today and i cannot find a way to send in custom function codes.

Alternatives

No response

Additional context

I dont know if these function codes are established function codes for this purpose or if it is specific to the device im working with.

@github-actions github-actions bot changed the title Add support for custom function codes. Add support for custom function codes. (IDFGH-13746) Sep 19, 2024
@alisitsyn
Copy link
Collaborator

alisitsyn commented Sep 20, 2024

@klasrpersson,

Thanks you for the issue. Unfortunately, I can not add support of huge list of all Modbus commands into this stack.

Add a way to write data to modbus slaves using arbitrary function codes. It could have an interface similar to eMBMasterReqWriteMultipleHoldingRegister but without the hardcoded function code.

The functions 0x13 and 0x14 included in the Modbus specification but are in the reserved list of commands (not standard). The support of custom commands and its handlers is not provided for now but this request is already added into feature list to implement.
However, it is possible to do workaround in your application code to support your new commands without any changes in the stack code:
There is the function mbc_master_send_request(), the api description which allows to send custom request to any slave. However, it requires to have also the specific function handler. There is a way to handle response from slave to your custom command using the [custom user handler function] (https://docs.espressif.com/projects/esp-modbus/en/latest/esp32/master_api_overview.html#id5) in your application. This function is executed by stack right before return from mbc_master_set_parameter() or mbc_master_get_parameter() functions. This user handler can allow you to get the command send/receive buffer for each transaction. For your new functions the parameter (err_type = EV_ERROR_EXECUTE_FUNCTION) because the handler will not be found in the standard function table. So, it is possible to implement your own custom function handler for the functionality to support the functions 0x13, 0x14. Note: the custom handler should not blocked for a long time, so it is better to send the required buffers to the file handling task using the queues, then return from the handler function ASAP. It is responsibility of your application to handle the command properly.

I think this approach could work for you.

~~Please investigate the above and let me know if this can work for you. ~~

UPDATE: I think the above will not be possible due to limitation of mbc_master_send_request() function and the mb_param_request_t. This can not be used to make the custom request for 0x13, 0x14. So, the possible way is to add the support for these custom commands.
the way to override sources of the component

@alisitsyn alisitsyn self-assigned this Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants