Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.wpi.first.wpilibj
Class I2C

    java.lang.Object
      edu.wpi.first.wpilibj.SensorBase
          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, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond`

Constructor Summary
`I2C(DigitalModule module, int deviceAddress)` Constructor.

Method Summary
`boolean` | `addressOnly()` Attempt to address a device on the I2C bus.
`void` | `broadcast(int registerAddress, int data)` Send a broadcast write to all devices on the I2C bus.
`void` | `free()` Destructor.
`boolean` | `read(int registerAddress, int count, byte[] buffer)` Execute a read transaction with the device.
`void` | `setCompatabilityMode(boolean enable)` SetCompatabilityMode Enables bitwise clock skewing detection.
`boolean` | `transaction(byte[] dataToSend, int sendSize, byte[] dataReceived, int receiveSize)` Generic transaction.
`boolean` | `verifySensor(int registerAddress, int count, byte[] expected)` Verify that a device's registers contain expected values.
`boolean` | `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 connected.
    `deviceAddress` - The address of the device on the I2C bus.

Method Detail

### free

    public void free()

  Destructor.

  Overrides:
    `free` in class `SensorBase`

### transaction

    public boolean transaction(byte[] dataToSend,
                               int sendSize,
                               byte[] dataReceived,
                               int receiveSize)

  Generic transaction. This is a lower-level interface to the I2C hardware giving you more control over each transaction.

  Parameters:
    `dataToSend` - Buffer of data to send as part of the transaction.
    `sendSize` - Number of bytes to send as part of the transaction. [0..6]
    `dataReceived` - Buffer to read data into.
    `receiveSize` - Number of bytes to read from the device. [0..7]
  Returns:
    Transfer Aborted... false for success, true for aborted.

### addressOnly

    public boolean addressOnly()

  Attempt to address a device on the I2C bus. This allows you to figure out if there is a device on the I2C bus that responds to the address specified in the constructor.

  Returns:
    Transfer Aborted... false for success, true for aborted.

### write

    public boolean write(int registerAddress,
                         int data)

  Execute a write transaction with the device. Write a single 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 boolean read(int registerAddress,
                        int count,
                        byte[] buffer)

  Execute a read transaction with the device. 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.

  Parameters:
    `registerAddress` - The register to read first in the transaction.
    `count` - The number of bytes to read in the transaction. [1..7]
    `buffer` - A pointer to the array of bytes to store the data read from the device.
  Returns:
    Transfer Aborted... false for success, true for aborted.

### 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.

### setCompatabilityMode

    public void setCompatabilityMode(boolean enable)

  SetCompatabilityMode Enables bitwise clock skewing detection. This will reduce the I2C interface speed, but will allow you to communicate with devices that skew the clock at abnormal times. Compatability mode is enabled by default.

  Parameters:
    `enable` - Enable compatability mode for this sensor or not.

### 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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"