Skip to content

Commit e9484ab

Browse files
theobarkerhjaniversen
authored andcommitted
Correct the calculation of the PDU size in bytes. Rather than determined empirically, used https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf page 32.
1 parent 650c1fc commit e9484ab

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pymodbus/file_message.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,16 @@ def execute(self, context): # NOSONAR pylint: disable=unused-argument,no-self-u
140140

141141
def get_response_pdu_size(self):
142142
"""
143-
Func_code (1 byte) + Byte Count(1 byte) + Byte Count2 (1 byte) + Reference Type (1 byte) + registers to read for file
143+
Func_code (1 byte) + Response Byte Count(1 byte) +
144+
N * (File Response Byte Count (1 byte) + Reference Type (1 byte) + 2 * registers to read for file record)
145+
where N = record sub-request count.
144146
:return:
145147
"""
148+
self.count = 0
146149
for record in self.records:
147-
self.count+=record.record_length
150+
self.count+= record.record_length * 2 + 2 if record.record_length else 0
148151

149-
return 4 + self.count
152+
return 2 + self.count
150153

151154
class ReadFileRecordResponse(ModbusResponse):
152155
"""Read file record response.

0 commit comments

Comments
 (0)