Skip to content

Conversation

@frawau
Copy link

@frawau frawau commented Jan 29, 2021

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.

…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 {}.
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sfarbotka
Copy link

Please, take a look at PR #608. It looks like they both a trying to fix the same issue in RTU framer.

Copy link

@sfarbotka sfarbotka left a 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 = {}

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 = {}

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

@dhoomakethu
Copy link
Contributor

@frawau Please check #608 and see if that fixes the issue.

@frawau
Copy link
Author

frawau commented Mar 2, 2021

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.

@dhoomakethu
Copy link
Contributor

@frawau The changes in #608 is merged in to #605. I will be closing this PR. If you think the changes do not fix your issue, please feel free to re-open this.

@dhoomakethu dhoomakethu closed this Mar 2, 2021
@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