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

Fix mask write register #961

Merged
merged 5 commits into from
Jul 14, 2022

Conversation

floitsch
Copy link
Contributor

According to the spec the "Mask Write Register" function ands the
or-mask with ~and-mask.

See section 6.16 of the specification (v1.1b3):

Result = (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask))

According to the spec the "Mask Write Register" function ands the
or-mask with ~and-mask.

See section 6.16 of the specification (v1.1b3):
```
Result = (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask))
```
@floitsch
Copy link
Contributor Author

I couldn't really find a place to add a test. If you let me know where that should go I can try to add it.

@floitsch floitsch changed the title Fix mask write register. Fix mask write register Jul 14, 2022
@janiversen
Copy link
Collaborator

please add a test in the test directory.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change is correct, I will approve as soon as a couple of tests are added.

@floitsch
Copy link
Contributor Author

Can you point me to the file that tests the behavior of the functions?

@janiversen
Copy link
Collaborator

look in the test directory! the file names tells what the file test. You are also welcome to add a new file.

@floitsch
Copy link
Contributor Author

I did look in the test directory, but could not find one test that tests the behavior of the server;
something like "write" and then check that a "read" finds the correct value.
Without your help I'm assuming that there aren't any tests for this.
I will try to write a simple one for this change.

@janiversen
Copy link
Collaborator

I never said there were tests specifically for masks, on the contrary I asked you to add tests.

@janiversen
Copy link
Collaborator

You could actually just search for the función call.

@floitsch
Copy link
Contributor Author

I know where the test for the mask is: test_mask_write_register_request_execute.
However, it uses a mock context that discards the values.

I was assuming that there is a test somewhere where the behavior of the server is tested. Something that makes sure that write_coil, followed by a read_coil does actually read the value of the coil without affecting neighboring coils. Stuff like this.
It seems like that's not the case, so I will try to write something myself.

@dhoomakethu
Copy link
Contributor

We do not have functional tests in place yet to test the behaviour of both server and client. For now unit tests should suffice. Thanks for the PR.

@floitsch
Copy link
Contributor Author

I have added a test.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for modifying a single test, this however does not seem sufficient to test the and/or functionally.

@floitsch
Copy link
Contributor Author

The test uses the 4 nibbles of the 16-bit values to test the combinations:

  • and_mask=0, or_mask=0
  • and_mask=F, or_mask=0
  • and_mask=0, or_mask=F
  • and_mask=F, or_mask=F

That should cover all possible mask possibilities.

@janiversen
Copy link
Collaborator

Thanks for your contribution (I just added a comment copying your explanation).

We hope you are motivated to do more patches, an easy one, but also a bit bigger is to

  • search for :param
  • control the :param against the actual parameters
  • in case of differences update :param
    This will enhance the documentation quite a lot, so a much needed feature.

@janiversen janiversen merged commit 24ed776 into pymodbus-dev:dev Jul 14, 2022
@floitsch
Copy link
Contributor Author

Thanks for merging.

I'm not really a Python coder, and there is plenty to do on our open-source project, so I doubt I will find time to contribute here.
But a good idea to suggest other contribution opportunities.

@floitsch floitsch deleted the floitsch/fix_mask_write branch July 15, 2022 12:28
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants