Package org.joshvm.j2me.dio.i2cbus

Interfaces and classes for I2C (Inter-Integrated Circuit Bus) device access.

See: Description

Package org.joshvm.j2me.dio.i2cbus Description

Interfaces and classes for I2C (Inter-Integrated Circuit Bus) device access.

The functionalities supported by this API are those of an I2C master.

In order to communicate with a specific slave device, an application should first open and obtain an I2CDevice instance for the I2C slave device the application wants to exchange data with, using its numeric ID, name, type (interface) and/or properties:

Using its ID
 I2CDevice slave = (I2CDevice) DeviceManager.open(3);
 
Using its name and interface
 I2CDevice slave = DeviceManager.open("ADC1", I2CDevice.class, null);
 
Once the device opened, the application can exchange data with the I2C slave device using methods of the I2CDevice interface such as the write method.
 slave.write(sndBuf, 0, 1);
 
When the data exchange is over, the application should call the I2CDevice.close method to close the I2C slave device.
 slave.close();
 
The following sample code gives an example of using the I2C API to communicate with an I2C slave device:
 try (I2CDevice slave = DeviceManager.open("LED_CONTROLLER", I2CDevice.class, null)) {
     ByteBuffer stopCmd = ByteBuffer.wrap(LED_STOP_COMMAND);
     ByteBuffer offCmd = ByteBuffer.wrap(LED_OFF_COMMAND);
     ByteBuffer onCmd = ByteBuffer.wrap(LED_ON_COMMAND);
     // Clear all status of the 'LED' slave device
     slave.write(ByteBuffer.wrap(stopCmd));
     slave.write(ByteBuffer.wrap(offCmd));

     for (int i = 0; i < LED_LOOP_COUNT; i++) {
         // turning 'LED' on and keeping it on for 1500ms
         slave.write(ByteBuffer.wrap(onCmd));
         try {
             Thread.sleep(LED_BLINK_TIME);
         } catch (InterruptedException ex) {
         }

         // turning 'LED' off keeping it off for 1500ms
         slave.write(ByteBuffer.wrap(offCmd));
         try {
             Thread.sleep(LED_BLINK_TIME);
         } catch (InterruptedException ex) {
         }
     }
 } catch (IOException ioe) {
     // handle exception
 }
 

The preceding example is using a try-with-resources statement; the I2CDevice.close method is automatically invoked by the platform at the end of the statement.

Information about the I2C-bus specification can be found at http://www.nxp.com/documents/user_manual/UM10204.pdf.

Unless otherwise noted, permission and security checks that may cause a SecurityException to be thrown must be performed in priority to any other checks or operations once performed the checking of the input parameters from which the permission target names and action lists are retrieved and assembled.

Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

Since:
1.0