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

Allow asynchron usage #28

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Conversation

TobiasSchaffner
Copy link

This series of patches was created to be able to use minimalmodbus asynchronously without breaking the current interface. It was taking care of that tests are green at every commit.

When working asynchronous we do not want to wait for the data after sending the request. We will most of the time wait for a select to return later.

To make this work the write and read operations had to be separated up to the _genericCommand method.
If the switch asynchron is set the _genericCommand method will return after sending the request without waiting for the response.

When changing large methods I seized the moment to break them into hand able peaces. This sometime leads to many parameters moved around. In my opinion we should think about a shared object holding at least some of the data that is moved around frequently.

Example:
In my case I am now able to inherit from Instrument overwriting the constructor and setting my parameters as needed. Especially I am setting a transport object as serial.

On write I call the _genericCommand method and save the parameters.

In the data_received callback I call _extractPayload and _calculateReturn as normally used in _genericCommand when working synchronously.

Tobias Schaffner added 18 commits April 23, 2018 15:06
 * Move the constants to file header for more flexibility
The extraction of the slave payload is moved from _performCommand to
genericCommand. This way the communication is the last step of _performCommand
and it will be easyer to split this into write and read.
After the split of _performCommand into separate read and write methods the
_performCommand method can be savely removed.
After the split of read and write the communicate method was left for
testing. Fix tests and remove the method.
With this change the _genericCommand function will be able to decide which
slave the request should be send to.
If the asynchron switch is set minimalmodbus will return after writing to the
serial transport. This gives us the possibility to handle the read asynchron
with a callback.

If working asynchon the user will still have to call _extractPayload and
_checkResponse on the received data.
@pyhys pyhys added this to the 2.0 milestone Jul 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants