-
Notifications
You must be signed in to change notification settings - Fork 1k
BUGFIX?: self._header needs to be set to {} #599
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
Conversation
…ays be missed.
populateHeader() is called in isFrameReady() and checkFrame(). In isFrameReady,
populateHeader is only called 'if not self._header', and checkFrame is only called
'if isFrameReady()'.
Reset also sets self._header to {}.
|
Kudos, SonarCloud Quality Gate passed! |
|
Please, take a look at PR #608. It looks like they both a trying to fix the same issue in RTU framer. |
sfarbotka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at my comments
| """ | ||
| self._buffer = b'' | ||
| self._header = {'uid': 0x00, 'len': 0, 'crc': '0000'} | ||
| self._header = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests in test/test_framers.py have to be changed as well.
| """ | ||
| self._buffer = b'' | ||
| self._header = {'uid': 0x00, 'len': 0, 'crc': '0000'} | ||
| self._header = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like isFrameReady() can still work incorrectly in some conditions.
If framer instance receives incomplete frame with only first byte of some frame,
populateHeader() properly sets self._header['uid'] and then raises IndexError when trying to read second byte from buffer. After that isFrameReady() will not call populateHeader because self._header is not empty, but instead will fail on line return self._header and len(self._buffer) >= self._header['len'], as len key was not added to self._header
|
Yes I checked and it very much look like the same issue.. only solved better. I have not had time to check it yet... but it does look like it will solve my issue. |
self._header needs to be set to {}. If not, the first frame would always be missed.
populateHeader() is called in isFrameReady() and checkFrame(). In isFrameReady,
populateHeader is only called 'if not self._header', and checkFrame is only called
'if isFrameReady()'.
Reset also sets self._header to {}.
I did test with a async serial connection. Does fix my problem, was only checking for one answer.