Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
273 stars 57 forks source link

I2C writeRead method compares written to writeOffset instead of writeSize #388

Closed kasperski12 closed 4 days ago

kasperski12 commented 1 week ago

Hi all I think that there is bug in default implementation of writeRead method in I2c.java

default int writeRead(byte[] writeBuffer, int writeSize, int writeOffset, byte[] readBuffer, int readSize,
        int readOffset) {
        return execute(() -> {
            int written = write(writeBuffer, writeOffset, writeSize);
            if (written != writeOffset)
                throw new IllegalStateException(
                    "Expected to write " + writeOffset + " bytes but only wrote " + written + " bytes");
            return read(readBuffer, readOffset, readSize);
        });
    }

The if conditions compares written to writeOffset instead of writeSize which is the number of bytes to write.

eitch commented 5 days ago

Thanks, good catch! There really was wrong! It will be fixed in the next release!

FDelporte commented 4 days ago

Included in 2.7.0