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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

PeterBorisenko opened this issue · comments

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
    };
  1. 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));
}
  1. Try to poll device:
BatchResults<Integer> res= batchRead(master, batch);
  1. 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.