Skip to content

Fix Read Fifo Query RTU Frame Size#2898

Merged
janiversen merged 3 commits intopymodbus-dev:devfrom
brambo123:dev
Feb 26, 2026
Merged

Fix Read Fifo Query RTU Frame Size#2898
janiversen merged 3 commits intopymodbus-dev:devfrom
brambo123:dev

Conversation

@brambo123
Copy link
Contributor

Found a small calculation error in the Read FIFO Query function.
This should fix it, unless a test fails again.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

Please correct the test harness as we cannot merge a PR without a greenwich CI.

@brambo123 brambo123 marked this pull request as draft February 26, 2026 17:06
@brambo123 brambo123 requested a review from janiversen February 26, 2026 17:06
@brambo123
Copy link
Contributor Author

brambo123 commented Feb 26, 2026

TEST_MESSAGE = b"\x00\n\x00\x04\x00\x01\x00\x02\x00\x03\x00\x04"

def test_read_fifo_queue_response_encode(self):
"""Test that the read fifo queue response can encode."""
message = TEST_MESSAGE
handle = ReadFifoQueueResponse([1, 2, 3, 4])
result = handle.encode()
assert result == message
def test_read_fifo_queue_response_decode(self):
"""Test that the read fifo queue response can decode."""
message = TEST_MESSAGE
handle = ReadFifoQueueResponse([1, 2, 3, 4])
handle.decode(message)
assert handle.values == [1, 2, 3, 4]
def test_frame_size(self):
"""Test that the read fifo queue response can decode."""
message = TEST_MESSAGE
result = ReadFifoQueueResponse.calculateRtuFrameSize(message)
assert result == 14

Can someone explain to me what input calculateRtuFrameSize should actually have?
I think it should have the full frame, including the device ID and function code.
But TEST_MESSAGE seems to only be the output of encode(), which I don't think is a full frame?

Edit:
I made a quick change to make it a full frame, and that seems to work.
But I'm not sure if it's correct, and it might not be the most prettiest way to do it.

Quick dirty test to fix test_frame_size
@brambo123 brambo123 marked this pull request as ready for review February 26, 2026 17:31
@janiversen
Copy link
Collaborator

I am confused about your question, check the code:

pymodbus/framer/rtu.py line 98.

why would you assume then encode generates what decode wants..it is used in 2 very different situations...but again just look at the code.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks.

@janiversen janiversen merged commit 81b6220 into pymodbus-dev:dev Feb 26, 2026
21 checks passed
@janiversen
Copy link
Collaborator

Just saw that the test file have a copy/paste error...all the references to bit/coil/discrete input should clearly have been to file...

This includes the class name.

Feel free to submit a follow up PR if you want to.

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