stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.29k stars 1.71k forks source link

Requering Delay To Read Bunch of RegisterAddress At a Time #664

Closed Mahalakshmi1298 closed 1 year ago

Mahalakshmi1298 commented 1 year ago

We were using libmodbus library and trying to read the bunch of register address from 40101 to 40513. ( data length = 414) since functional code was 40 (read holding register) we were using this below API to read data. int modbus_read_registers(modbus_t ctx, int addr, int nb, uint16_t dest);

case 1: Issue Case

   While using this below case we were facing problem to read all data at a time,

eg: modbus_read_registers(ctx, 100, 414, buff ); // regAdd : [ 101 - 1 ] LengthOfData to Read : [ ( 513 - 101 ) + 2 ]

case 2: Alternate Case

   Instead of the above case we were tried to read the register address with limited length and with delay that worked fine,   

eg: modbus_read_registers(ctx, 100, 50, buff ); sleep(1); modbus_read_registers(ctx, 150, 50, buff ); sleep(1);

Can Any one please give suggestion to use the modbus_read_registers() API to read data length greater than 500  without delay?
Ashwin-GB commented 1 year ago

I'm assuming this is about modbus rtu. The modbus message is limited to 256 bytes. It would not be possible to read 414 registers. You can still make some tweaks in the code and be able to read 414 registers provided you are in control of both master and slave devices.

stephane commented 1 year ago

Thank you @Ashwin-GB for your answer.