espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.91k stars 7.09k forks source link

The freemodbus stack does not support bulk payload of 150 registers for write request with function code(16) 0x10 (IDFGH-12811) #13787

Open BestBot7 opened 1 month ago

BestBot7 commented 1 month ago

Answers checklist.

General issue report

I have a slave device which supports writing 150 registers at once which is around 300 bytes. I have framed a modbus request which is greater than 300 bytes including slave ID, function code, register start address, number of registers, number of bytes, data and CRC and sent it to the modbus slave device using standard modbus master template code. In standard documentations it is mentioned that the modbus can support writing multiple registers of 123 registers at once. Is there any way to that can support the bulk and huge payload of writing multiple registers?

alisitsyn commented 1 month ago

The maximum buffer for the frame is 256 bytes = absolute maximum is 128 registers but the max number of holding registers to read/write is not 128. From the spec:

"The quantity of registers to be read, combined with all the other fields in the expected response, must not exceed the allowable length of Modbus messages: 256 bytes.". If we take into account the standard fields of Modbus the maximum number of register to read with FC=0x03 drops to 125 registers.

The limitations is hard coded in the stack and for now it is not planned to extend the limit of registers to support non standard slaves. However, it is pretty simple to override in your custom project. This feature will be part of esp-modbus stack v2.