Example #1
0
  /**
   * Execute a read transaction with the device.
   *
   * <p>Read 1 to 7 bytes from a device. Most I2C devices will auto-increment the register pointer
   * internally allowing you to read up to 7 consecutive registers on a device in a single
   * transaction.
   *
   * @param registerAddress The register to read first in the transaction.
   * @param count The number of bytes to read in the transaction. [1..7]
   * @param buffer A pointer to the array of bytes to store the data read from the device.
   * @return Transfer Aborted... false for success, true for aborted.
   */
  public boolean read(int registerAddress, int count, byte[] buffer) {
    BoundaryException.assertWithinBounds(count, 1, 7);
    if (buffer == null) {
      throw new NullPointerException("Null return buffer was given");
    }
    byte[] registerAddressArray = new byte[1];
    registerAddressArray[0] = (byte) registerAddress;

    return transaction(registerAddressArray, registerAddressArray.length, buffer, count);
  }
Example #2
0
  /**
   * Execute a read only transaction with the device.
   *
   * <p>Read 1 to 7 bytes from a device. This method does not write any data to prompt the device.
   *
   * @param buffer A pointer to the array of bytes to store the data read from the device.
   * @param count The number of bytes to read in the transaction. [1..7]
   * @return Transfer Aborted... false for success, true for aborted.
   */
  public boolean readOnly(byte[] buffer, int count) {
    BoundaryException.assertWithinBounds(count, 1, 7);
    if (buffer == null) {
      throw new NullPointerException("Null return buffer was given");
    }

    ByteBuffer dataReceivedBuffer = ByteBuffer.allocateDirect(count);

    int retVal =
        I2CJNI.i2CRead(
            (byte) m_port.getValue(), (byte) m_deviceAddress, dataReceivedBuffer, (byte) count);
    dataReceivedBuffer.get(buffer);
    return retVal < 0;
  }