Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymodbus/pdu/file_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def x_calculateRtuFrameSize(cls, data: bytes) -> int:
"""Calculate the size of the message."""
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".


def __init__(
self, values: list[int] | None = None, dev_id: int = 1, transaction_id: int = 0
Expand Down
10 changes: 9 additions & 1 deletion test/pdu/test_file_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import pytest

from pymodbus.exceptions import ModbusException
from pymodbus.framer import FramerRTU
from pymodbus.pdu import DecodePDU
from pymodbus.pdu.file_message import (
FileRecord,
ReadFifoQueueRequest,
Expand Down Expand Up @@ -64,9 +66,15 @@ def test_frame_size(self):
"""Test that the read fifo queue response can decode."""
message = TEST_MESSAGE
assert (
ReadFifoQueueResponse.x_calculateRtuFrameSize(b"\x00\x18" + message) == 14
ReadFifoQueueResponse.x_calculateRtuFrameSize(b"\x00\x18" + message) == 16
)
assert ReadFifoQueueRequest.x_calculateRtuFrameSize(b"") == 6
frame = bytes.fromhex("1018000a00046131346662303165a946")
used_len, pdu = FramerRTU(DecodePDU(False)).handleFrame(frame, 0, 0)
assert used_len == len(frame)
assert isinstance(pdu, ReadFifoQueueResponse)
assert pdu.dev_id == 0x10
assert pdu.values == [0x6131, 0x3466, 0x6230, 0x3165]

# -----------------------------------------------------------------------#
# File Record
Expand Down
Loading