2010 FRC Java API


edu.wpi.first.wpilibj
Class I2C

java.lang.Object
  extended by edu.wpi.first.wpilibj.SensorBase
      extended by edu.wpi.first.wpilibj.I2C

public class I2C
extends SensorBase

I2C bus interface class. This class is intended to be used by sensor (and other I2C device) drivers. It probably should not be used directly. It is constructed by calling DigitalModule::GetI2C() on a DigitalModule object.


Field Summary
 
Fields inherited from class edu.wpi.first.wpilibj.SensorBase
kAnalogChannels, kAnalogModules, kChassisSlots, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond
 
Constructor Summary
I2C(DigitalModule module, int deviceAddress)
          Constructor.
 
Method Summary
 void broadcast(int registerAddress, int data)
          Send a broadcast write to all devices on the I2C bus.
protected  void free()
          Destructor.
 void read(int registerAddress, int count, byte[] buffer)
          Execute a read transaction with the device.
 boolean verifySensor(int registerAddress, int count, byte[] expected)
          Verify that a device's registers contain expected values.
 void write(int registerAddress, int data)
          Execute a write transaction with the device.
 
Methods inherited from class edu.wpi.first.wpilibj.SensorBase
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

I2C

public I2C(DigitalModule module,
           int deviceAddress)
Constructor.

Parameters:
module - The Digital Module to which the device is conneted.
deviceAddress - The address of the device on the I2C bus.
Method Detail

free

protected void free()
Destructor.

Overrides:
free in class SensorBase

write

public void write(int registerAddress,
                  int data)
Execute a write transaction with the device. Write a byte to a register on a device and wait until the transaction is complete.

Parameters:
registerAddress - The address of the register on the device to be written.
data - The byte to write to the register on the device.

read

public void read(int registerAddress,
                 int count,
                 byte[] buffer)
Execute a read transaction with the device. Read 1, 2, 3, or 4 bytes from a device. Most I2C devices will auto-increment the register pointer internally allowing you to read up to 4 consecutive registers on a device in a single transaction.

Parameters:
registerAddress - The register to read first in the transaction.
count - The number of bytes to read in the transaction.
buffer - A pointer to the array of bytes to store the data read from the device.

broadcast

public void broadcast(int registerAddress,
                      int data)
Send a broadcast write to all devices on the I2C bus. This is not currently implemented!

Parameters:
registerAddress - The register to write on all devices on the bus.
data - The value to write to the devices.

verifySensor

public boolean verifySensor(int registerAddress,
                            int count,
                            byte[] expected)
Verify that a device's registers contain expected values. Most devices will have a set of registers that contain a known value that can be used to identify them. This allows an I2C device driver to easily verify that the device contains the expected value.

Parameters:
registerAddress - The base register to start reading from the device.
count - The size of the field to be verified.
expected - A buffer containing the values expected from the device.
Returns:
true if the sensor was verified to be connected

2010 FRC Java API


Copyright © 2006-2009 Sun Microsystems, Inc. All Rights Reserved.