kochedykov / jlibmodbus

JLibModbus - is an implementation of the Modbus protocol v1.1b in java language. Java modbus library. It works. Welcome.
http://kochedykov.github.io/jlibmodbus/
Apache License 2.0
307 stars 128 forks source link

Problem of register value type #85

Closed neutralhy closed 9 months ago

neutralhy commented 1 year ago

previous issue #64 I think this fix causes serious problems

The individual register size of Modbus is 2 bytes, but due to the modified code, it operates as 4 bytes. For example, if the quantity set in the slave is 10, even if the master makes a request with setQuantity(10), the value of getQuantity() is 5 under the modified code, and the data that should be read by 2 bytes are combined into 4 bytes and read.

Therefore, it must revert to the previous code.

static public int[] BeToIntArray(byte[] bytes) { int[] dst = new int[bytes.length / 2]; for (int i = 0, j = 0; i < dst.length; i++, j += 2) dst[i] = ((bytes[j] & 0xff) << 8) | (bytes[j + 1] & 0xff); return dst; }

kochedykov commented 9 months ago

Commit 502d0cef0594be95345520c5b629fadb71e1e993