Repository navigation
Fix ReadFifoQueueResponse RTU frame size - #3093
Merged
janiversen merged 1 commit intoNov 23, 2026
Merged
Conversation
janiversen
requested changes
Nov 23, 2026
janiversen
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for catching this, clearly a bug, however I do believe your correction is incorrect, please revise.
janiversen
approved these changes
Nov 23, 2026
janiversen
left a comment
Collaborator
There was a problem hiding this comment.
Sorry for the confusion with "fifo count".
LGTM, Thanks.
| hi_byte = int(data[2]) | ||
| lo_byte = int(data[3]) | ||
| return ((hi_byte << 8) + lo_byte) + 4 | ||
| return ((hi_byte << 8) + lo_byte) + 6 |
Collaborator
There was a problem hiding this comment.
My review was too fast, 6 is correct because "byte count" includes "fifo count".
Collaborator
|
Verified as corrected in #3068 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Over RTU, the client drops every Read FIFO Queue (0x18) response as garbage, so
read_fifo_queuenever returns a result.Root cause
ReadFifoQueueResponse.x_calculateRtuFrameSizereturnsbyte_count + 4. The byte count field in this response is 2 bytes wide, so the RTU frame is dev_id (1) + function code (1) + byte count field (2) + byte_count + CRC (2) =byte_count + 6. Because the computed size is 2 bytes short,FramerRTU.decodereads the CRC from the wrong position, the CRC check fails, and the whole frame is thrown away ("Frame CRC check failed, possible garbage").The device frame from #2860 shows it:
10 18 00 0a 00 04 61 31 34 66 62 30 31 65 a9 46is 16 bytes with byte count 10. On currentdev,handleFramereturns(16, None)for it. A response built by pymodbus itself (buildFrame(ReadFifoQueueResponse([1, 2, 3, 4]))) is rejected the same way.Fix
Return
byte_count + 6.Tests
test_frame_sizenow expects 16 for the existing 12-byte test message (dev_id + function code + 12 bytes + CRC). The old value of 14 encoded the bug.FramerRTUand checks that it returns aReadFifoQueueResponsewith the right device id and values. Both assertions fail without the fix.ruff check,ruff format --check,pylint(10.00/10),zuban checkandcodespellare clean. The full pytest suite passes except the TLS/certificate tests and one logging test, which fail the same way on unmodifieddevin my Windows environment.