arduino-libraries / ArduinoModbus

240 stars 116 forks source link

Multiple holding register write limitation in one cycle. #85

Open mirzafahad opened 2 years ago

mirzafahad commented 2 years ago

I am using the library to create a modbus-rtu slave device that has more than 50 holding registers. The master device tries to write to all the holding registers in one instruction. But the way the library works, you cannot go beyond 30 holding registers (in one cycle).

I traced the issue in modbus-rtu.cpp at line 1266, where it is waiting for all the bytes to be available.

For 50 holding registers, it will be 100-bytes. But the HardwareSerial library has a buffer size of 64. So, ctx_rtu->rs485->available(); (line 1266) always times out waiting for 100-bytes.

IMHO, the modbus library should have its own buffer where it can store the data from the serial buffer and not depend on the HardwareSerial library's buffer. Because according to Modbus standard I should have been able to write at most 123 holding registers in one cycle.

Let me know if that's a valid assumption.

ospin-chris commented 9 months ago

ran into same issue using https://github.com/epsilonrt/modbus-serial library, i could only write 27 registers, i found your issue which located the problem to the HW serial buffer size, thanks. I'm using PlatformIO with a Teensy41, in my platformio.ini file i added the line build_flags = -D SERIAL1_RX_BUFFER_SIZE=256 and it solved the problem for me, maybe it helps you too...