Skip to content

Fix ReadFifoQueueResponse RTU frame size - #3093

Merged
janiversen merged 1 commit into
pymodbus-dev:devfrom
anubhavlal07:fix/fifo-rtu-frame-size
Nov 23, 2026
Merged

janiversen merged 1 commit into
pymodbus-dev:devfrom
anubhavlal07:fix/fifo-rtu-frame-size

Conversation

@anubhavlal07

Copy link
Copy Markdown
Contributor

Over RTU, the client drops every Read FIFO Queue (0x18) response as garbage, so read_fifo_queue never returns a result.

Root cause
ReadFifoQueueResponse.x_calculateRtuFrameSize returns byte_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.decode reads 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 46 is 16 bytes with byte count 10. On current dev, handleFrame returns (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_size now expects 16 for the existing 12-byte test message (dev_id + function code + 12 bytes + CRC). The old value of 14 encoded the bug.
  • The same test now also decodes the real device frame from read_fifo_queue not working #2860 through FramerRTU and checks that it returns a ReadFifoQueueResponse with the right device id and values. Both assertions fail without the fix.
  • ruff check, ruff format --check, pylint (10.00/10), zuban check and codespell are clean. The full pytest suite passes except the TLS/certificate tests and one logging test, which fail the same way on unmodified dev in my Windows environment.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, clearly a bug, however I do believe your correction is incorrect, please revise.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review was too fast, 6 is correct because "byte count" includes "fifo count".

@janiversen
janiversen merged commit 3228a6e into pymodbus-dev:dev Nov 23, 2026
16 checks passed
@janiversen

janiversen commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Verified as corrected in #3068

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants