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

java.lang.ArrayIndexOutOfBoundsException when accessing coil index #87

Open paulorb opened 1 year ago

paulorb commented 1 year ago

When performing a read of coils

           val request = ReadCoilsRequest()
            request.serverAddress = 1
            request.startAddress = 0
            request.transactionId = 0
            request.quantity = 123
            val response = m.processRequest(request) as ReadCoilsResponse

When trying to get the value of an individual coil, it gives an exception java.lang.ArrayIndexOutOfBoundsException when accessing a specific coil index

println("test: ${response.modbusCoils.get(120)}")

As a workaround I am using the coils property (which is indicated to be deprecated)

println("test: ${response.coils.get(120)}")

kochedykov commented 7 months ago

Tested, it works. There is no OutOfBounds exception.