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 execution of actions for WriteMultipleRegistersRequest and WriteMultipleCoilsRequest #2158

Open
krogozinski opened this issue Apr 11, 2024 Discussed in #2157 · 14 comments

Comments

@krogozinski
Copy link

Discussed in #2157

Originally posted by krogozinski April 10, 2024
I have a requirement to define custom actions for WriteMultipleRegistersRequest and WriteMultipleCoilsRequest. This is for testing the Modbus client on a new hardware project.

To the best of my understanding, actions (custom or built-in) for writes to the server seem to only be performed for WriteSingleCoilRequest and WriteSingleRegisterRequest, and not WriteMultipleRegistersRequest and WriteMultipleCoilsRequest.

The proposal is to add the capability of executing actions for WriteMultipleRegistersRequest and WriteMultipleCoilsRequest.

@janiversen
Copy link
Collaborator

I am all in favor of the idea, the problem as I see it is to implement actions for setValues !

I suggest to amend the actions to include the function code and a boolean for set/set, but the is just a thought not a demand.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@krogozinski
Copy link
Author

Still working on this. Should have a PR soon.

@janiversen
Copy link
Collaborator

Any progress ?

@krogozinski
Copy link
Author

krogozinski commented Jun 22, 2024 via email

@krogozinski
Copy link
Author

Would it be beneficial to implement a solution where:

  • existing user-defined custom actions can remain unchanged?
  • existing default behaviour remains unchanged i.e. custom actions are only executed by the simulator for requests that call getValues()?

If so, I would suggest some additional optional configuration for custom actions. Please see an example snippet below of a possible configuration that adds "triggers". These allow specification of the applicable function codes and the access types where the custom action should be executed.

# ...
{"addr": 2305,
    "action": "my_custom_action",
    "kwargs": {
        "triggers": [
            {"func_code": 6, "access_types": ["set"]},
            {"func_code": 16, "access_types": "default"},  # get only
            {"func_code": 22, "access_types": ["get", "set"]},
        ]
    }
},
# ...

If the "triggers" are not specified, existing behaviour is maintained. The custom action is only executed for requests that calls getValues().

The function code and access type (get/set) for the current request can be passed to the action method in the keyword arguments. This will allow existing user-defined custom actions to remain unchanged.

@janiversen
Copy link
Collaborator

The simulator configuration is overdue to be replaced by something simpler, not sure triggers goes in that direction, but pull requests are always welcome (most likely if you want something implemented it's up to you to do it).

@janiversen
Copy link
Collaborator

Seems this is no longer an issue and no PR have been presented. Closing for now.

@krogozinski
Copy link
Author

@janiversen apologies for the lack of activity; travel and subsequent sickness have slowed my progress.

It seems that I was a day too late. If possible, could you please see my draft PR #2255? The tests are passing and I have a proposed solution which does nor further complicate configuration.

There are opportunities to refactor if you find my general approach is acceptable.

@janiversen janiversen reopened this Jul 22, 2024
@janiversen
Copy link
Collaborator

No problem, I will take a look later.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@krogozinski
Copy link
Author

Documentation and example update are almost done. Would you prefer that I issue the PR to "dev" or "wait3.8.0", considering my proposal has API changes?

@janiversen
Copy link
Collaborator

I will do that once you have marked the PR as ready.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

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

2 participants