Oracle Java Wireless Client

com.oracle.deviceaccess.i2cbus
Interface I2CSlave

All Superinterfaces:
Peripheral

public interface I2CSlave
extends Peripheral

The I2CSlave interface provides methods for sending and receiving data to/from an I2C slave device.

Each I2C slave device is identified by a numerical ID and by a name.
An I2CSlave instance can be acquired by a call to I2CManager.getSlave(int) or I2CManager.getSlave(java.lang.String).

On an I2C bus, data is transferred between the I2C master device and an I2C slave device through single or combined messages:

Single Messages
The I2C master reads data from an I2C slave. An application can read from an I2C slave using one of the read() methods.
The I2C master writes data to an I2C slave. An application can write to an I2C slave using one of the write() methods.
Combined Messages Messages
The I2C master issues at least two reads and/or writes to one or more slaves. An application can write to then read from the same I2C slave in a single transaction (the most common use case) using one of the writeThenRead() methods.

When writing only, the data received from the I2C slave will be ignored/discarded. When reading only, dummy data will be sent to the slave.
When exchanging data, the most significant bytes of data are stored at the lower index (that is first) in the sending and receiving byte buffers.

When the data exchange is over, an application should call the I2CSlave.close() method to release the I2C slave. Any further attempt to transmit/write or receive/read to/from an I2C slave which has been released will result in a PeripheralNotAvailableException been thrown.

Note that the appropriate I2C clock frequency... for exchanging data with a particular I2C slave device are set by the platform.

See Also:
I2CManager, I2CPermission, PeripheralNotAvailableException

Method Summary
 int read()
          Reads one byte of data from this slave device.
 int read(byte[] rxBuf, int rxOff, int rxLen)
          Reads up to rxLen bytes of data from this slave device into an array of bytes.
 int read(int rxSkip, byte[] rxBuf, int rxOff, int rxLen)
          Reads up to rxLen bytes of data from this slave device into an array of bytes skipping the first rxSkip bytes read.
 void write(byte[] txBuf, int txOff, int txLen)
          Writes to this slave device txLen bytes from buffer txBuf.
 void write(int txData)
          Writes one byte to this slave device.
 int writeThenRead(byte[] txBuf, int txOff, int txLen, byte[] rxBuf, int rxOff, int rxLen)
          Writes to this slave device up to txLen bytes from the buffer txBuf then reads into the buffer rxBuf up to rxLen bytes from this slave device.
 int writeThenRead(byte[] txBuf, int txOff, int txLen, int rxSkip, byte[] rxBuf, int rxOff, int rxLen)
          Writes to this slave device up to txLen bytes from the buffer txBuf then reads into the buffer rxBuf up to rxLen bytes from this slave device skipping the first rxSkip bytes read.
 
Methods inherited from interface com.oracle.deviceaccess.Peripheral
close, getID, getName
 

Method Detail

read

int read()
         throws java.io.IOException,
                PeripheralNotAvailableException
Reads one byte of data from this slave device. The byte is returned as an int in the range 0 to 255.

Returns:
the unsigned 8-bit value read.
Throws:
java.io.IOException - if an I/O error occurs.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

read

int read(byte[] rxBuf,
         int rxOff,
         int rxLen)
         throws java.io.IOException,
                PeripheralNotAvailableException
Reads up to rxLen bytes of data from this slave device into an array of bytes.

Parameters:
rxBuf - the buffer into which the data is read.
rxOff - the offset in rxBuf where to start copying the bytes read.
rxLen - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer.
Throws:
java.io.IOException - if an IO error occurred.
java.lang.NullPointerException - If rxBuf is null.
java.lang.IndexOutOfBoundsException - rxOff or rxLen points or results in pointing outside rxBuf.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

read

int read(int rxSkip,
         byte[] rxBuf,
         int rxOff,
         int rxLen)
         throws java.io.IOException,
                PeripheralNotAvailableException
Reads up to rxLen bytes of data from this slave device into an array of bytes skipping the first rxSkip bytes read.

Parameters:
rxSkip - the number of read bytes that must be ignored/skipped before filling in the rxBuf buffer.
rxBuf - the buffer into which the data is read.
rxOff - the offset in rxBuf where to start copying the bytes read.
rxLen - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer.
Throws:
java.io.IOException - if an IO error occurred.
java.lang.NullPointerException - If rxBuf is null.
java.lang.IndexOutOfBoundsException - rxOff or rxLen points or results in pointing outside rxBuf.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

write

void write(int txData)
           throws java.io.IOException,
                  PeripheralNotAvailableException
Writes one byte to this slave device. The eight low-order bits of the argument data are written. The 24 high-order bits of txData are ignored.

Parameters:
txData - the byte to be written
Throws:
java.io.IOException - if an I/O error occurred
PeripheralNotAvailableException

write

void write(byte[] txBuf,
           int txOff,
           int txLen)
           throws java.io.IOException,
                  PeripheralNotAvailableException
Writes to this slave device txLen bytes from buffer txBuf.

Parameters:
txBuf - the buffer containing the bytes to write.
txOff - the offset in txBuf of the first byte to write.
txLen - the number of bytes from txBuf to write.
Throws:
java.io.IOException - if an IO error occurred.
java.lang.NullPointerException - If txBuf is null.
java.lang.IndexOutOfBoundsException - txOff or txLen points or results in pointing outside txBuf.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

writeThenRead

int writeThenRead(byte[] txBuf,
                  int txOff,
                  int txLen,
                  byte[] rxBuf,
                  int rxOff,
                  int rxLen)
                  throws java.io.IOException,
                         PeripheralNotAvailableException
Writes to this slave device up to txLen bytes from the buffer txBuf then reads into the buffer rxBuf up to rxLen bytes from this slave device.

This uses a combined message form of I2C communication where a command is written to the I2C slave device and corresponding response is read.

Parameters:
txBuf - the buffer containing the bytes to write (usually an address or command).
txOff - the offset in txBuf of the first byte to write.
txLen - the number of bytes from txBuf to write.
rxBuf - the buffer into which the data is read.
rxOff - the offset in rxBuf where to start copying the bytes read.
rxLen - the number of bytes to read.
Returns:
the total number of bytes read into the buffer rxBuf.
Throws:
java.io.IOException - if an IO error occurred.
java.lang.NullPointerException - If txBuf or rxBuf is null.
java.lang.IndexOutOfBoundsException - txOff, txLen, rxOff or rxLen points or results in pointing outside txBuf or rxBuf.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

writeThenRead

int writeThenRead(byte[] txBuf,
                  int txOff,
                  int txLen,
                  int rxSkip,
                  byte[] rxBuf,
                  int rxOff,
                  int rxLen)
                  throws java.io.IOException,
                         PeripheralNotAvailableException
Writes to this slave device up to txLen bytes from the buffer txBuf then reads into the buffer rxBuf up to rxLen bytes from this slave device skipping the first rxSkip bytes read.

This uses a combined message form of I2C communication where a command is written to the I2C slave device and corresponding response is read.

Parameters:
txBuf - the buffer containing the bytes to write (usually an address or command).
txOff - the offset in txBuf of the first byte to write.
txLen - the number of bytes from txBuf to write.
rxSkip - the number of read bytes that must be ignored/skipped before filling in the rxBuf buffer.
rxBuf - the buffer into which the data is read.
rxOff - the offset in rxBuf where to start copying the bytes read.
rxLen - the number of bytes to read.
Returns:
the total number of bytes read into the buffer rxBuf.
Throws:
java.io.IOException - if an IO error occurred.
java.lang.NullPointerException - If txBuf or rxBuf is null.
java.lang.IndexOutOfBoundsException - txOff, txLen, rxOff or rxLen points or results in pointing outside txBuf or rxBuf.
PeripheralNotAvailableException - if the peripheral is not currently available (has been released).

Oracle Java Wireless Client

Copyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.