Skip to content

Commit

Permalink
fix modbus reading issue when the number of registers to read is bigg…
Browse files Browse the repository at this point in the history
…er than the maximum number of registers per modbus request
  • Loading branch information
Nedi11 authored and nielsbasjes committed Jul 22, 2024
1 parent d8907ff commit 1210014
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ public void setMaxRegistersPerModbusRequest(int newMaxRegistersPerModbusRequest)

public byte[] getRawRegisterBytes(int base, int len) throws ModbusException {
byte[] bytes = new byte[len * 2];

int newBase=base;
int i = 0;
int remaining = len;
while (remaining > 0) {
int readSize = Math.min(remaining, maxRegistersPerModbusRequest);
remaining -= readSize;
final InputRegister[] registers = read(base, readSize);
final InputRegister[] registers = read(newBase, readSize);
newBase=base+readSize;
for (InputRegister register : registers) {
byte[] registerBytes = register.toBytes();
bytes[i++] = registerBytes[0];
Expand Down

0 comments on commit 1210014

Please sign in to comment.