Rewrite Tornado AsyncModbusSerialClient - #533 #537
Merged
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 is a major rewrite for
pymodbus.client.asynchronous.tornado.AsyncModbusSerialClientclass. In addition, thepymodbus.exceptions.TimeOutExceptionclass has been added.Existing tests have been fixed but the new flow is not covered with any additional test cases yet.
There are two differences with details described in #533:
First, there is more error handling. It still doesn't catch every write error but works better when waiting for serial data. In case of fd error it closes stream and returns
ModbusIOExceptionto the app. This happens when serial port disappears (for instance removing USB device). App should try to reopen serial port after that.Another change in this PR is that the receive part of master resets the
self.last_frame_endnow too. AFAIK it is important when using common half duplex serial bus like RS-485 where all slaves see all frames from each other. Otherwise reply from one slave and next request form master could be too close and some slaves might not like that. One slave usually works fine without that but with multiple slaves it becomes important.My test setup with 19200 baud shows that python part is so fast that some more time is still needed to be wait before sending a new request and this change fixes that too. With slower speeds this becomes even more useful.
Some of these changes would be nice to have in sync client also in the future. Especially the timing part could be more general for both clients.