MangoAutomation / modbus4j

A high-performance and ease-of-use implementation of the Modbus protocol written in Java. Supports ASCII, RTU, TCP, and UDP transports as slave or master, automatic request partitioning and response data type parsing.
GNU General Public License v3.0
881 stars 370 forks source link

The doPartition method works incorrectly based on wrong assumption that register ranges doesn't have gaps #42

Open PeterBorisenko opened 3 years ago

PeterBorisenko commented 3 years ago

To Reproduce Steps to reproduce the behavior:

  1. Use the following data offsets with RegisterRange.HOLDING_REGISTER
    private int initDataOffsets[]= {
            0x0710, // device name
            0x0711, // device name
            0x0712, // device name
            0x0780, // loads count
            0x1200, // phases num
    };
  2. Create batch read request
    BatchRead<Integer> batch = new BatchRead<Integer>();
    for (int i= 0; i < initDataOffsets.length; i++) {
    batch.addLocator(i, new ModbusLocator(16, RegisterRange.HOLDING_REGISTER, initDataOffsets[i],
    DataType.TWO_BYTE_INT_UNSIGNED, (byte) 0));
    }
  3. Try to poll device:
    BatchResults<Integer> res= batchRead(master, batch);
  4. If device doesn't have registers between 0x0712 and 0x0780 defined, there will be an error and res will be null.

Expected behavior List<ReadFunctionGroup<K>> functionGroups must be 3 here. But has 2.