Class TrcI2cDevice

java.lang.Object
trclib.robotcore.TrcI2cDevice

public abstract class TrcI2cDevice extends Object
This class implements a platform independent I2C device. Typically, this class is extended by a platform dependent I2C device class. The platform dependent I2C device class must implement the abstract methods required by this class. The abstract methods allow this class to perform platform independent operations on the I2C device.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    The client of this class provides this interface if it wants to be notified when a read or write operation has been completed.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TrcI2cDevice(String instanceName)
    Constructor: Creates an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract byte[]
    This method retrieves the data read from the device.
    abstract boolean
    This method checks if the I2C port is in write mode.
    abstract boolean
    This method checks if the I2C port is ready for bus transaction.
    void
    read(int regAddress, int length)
    This method queues the read request.
    void
    read(int regAddress, int length, TrcI2cDevice.CompletionHandler handler)
    This method queues the read request.
    void
    read(int regAddress, int length, TrcI2cDevice.CompletionHandler handler, double timeout)
    This method queues the read request.
    void
    sendByteCommand(int regAddress, byte command)
    This method sends a byte command to the device.
    abstract void
    sendReadCommand(int regAddress, int length)
    This method sends a read command to the device.
    void
    sendWordCommand(int regAddress, short command)
    This method sends a 16-bit command to the device.
    abstract void
    sendWriteCommand(int regAddress, int length, byte[] data)
    This method sends a write command to the device.
    This method returns the instance name of the device.
    void
    write(int regAddress, int length, byte[] writeBuffer)
    This method queues the write request.
    void
    write(int regAddress, int length, byte[] writeBuffer, TrcI2cDevice.CompletionHandler handler)
    This method queues the write request.
    void
    write(int regAddress, int length, byte[] writeBuffer, TrcI2cDevice.CompletionHandler handler, double timeout)
    This method queues the write request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • tracer

      public final TrcDbgTrace tracer
    • instanceName

      protected final String instanceName
  • Constructor Details

    • TrcI2cDevice

      public TrcI2cDevice(String instanceName)
      Constructor: Creates an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
  • Method Details

    • isPortReady

      public abstract boolean isPortReady()
      This method checks if the I2C port is ready for bus transaction.
      Returns:
      true if port is ready, false otherwise.
    • isPortInWriteMode

      public abstract boolean isPortInWriteMode()
      This method checks if the I2C port is in write mode.
      Returns:
      true if port is in write mode, false otherwise.
    • sendReadCommand

      public abstract void sendReadCommand(int regAddress, int length)
      This method sends a read command to the device.
      Parameters:
      regAddress - specifies the register address.
      length - specifies the number of bytes to read.
    • sendWriteCommand

      public abstract void sendWriteCommand(int regAddress, int length, byte[] data)
      This method sends a write command to the device.
      Parameters:
      regAddress - specifies the register address.
      length - specifies the number of bytes to write.
      data - specifies the data buffer containing the data to write to the device.
    • getData

      public abstract byte[] getData()
      This method retrieves the data read from the device.
      Returns:
      byte array containing the data read.
    • toString

      public String toString()
      This method returns the instance name of the device.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • read

      public void read(int regAddress, int length, TrcI2cDevice.CompletionHandler handler, double timeout)
      This method queues the read request.
      Parameters:
      regAddress - specifies the register address to read from.
      length - specifies the number of bytes to read.
      handler - specifies the completion handler to call when done. Can be null if none needed.
      timeout - specifies the timeout for the operation in seconds.
    • read

      public void read(int regAddress, int length, TrcI2cDevice.CompletionHandler handler)
      This method queues the read request.
      Parameters:
      regAddress - specifies the register address to read from.
      length - specifies the number of bytes to read.
      handler - specifies the completion handler to call when done. Can be null if none needed.
    • read

      public void read(int regAddress, int length)
      This method queues the read request.
      Parameters:
      regAddress - specifies the register address to read from.
      length - specifies the number of bytes to read.
    • write

      public void write(int regAddress, int length, byte[] writeBuffer, TrcI2cDevice.CompletionHandler handler, double timeout)
      This method queues the write request.
      Parameters:
      regAddress - specifies the register address to write to.
      length - specifies the number of bytes to read.
      writeBuffer - specifies the buffer containing the data to be written to the device.
      handler - specifies the completion handler to call when done. Can be null if none needed.
      timeout - specifies the timeout for the operation in seconds.
    • write

      public void write(int regAddress, int length, byte[] writeBuffer, TrcI2cDevice.CompletionHandler handler)
      This method queues the write request.
      Parameters:
      regAddress - specifies the register address to write to.
      length - specifies the number of bytes to read.
      writeBuffer - specifies the buffer containing the data to be written to the device.
      handler - specifies the completion handler to call when done. Can be null if none needed.
    • write

      public void write(int regAddress, int length, byte[] writeBuffer)
      This method queues the write request.
      Parameters:
      regAddress - specifies the register address to write to.
      length - specifies the number of bytes to read.
      writeBuffer - specifies the buffer containing the data to be written to the device.
    • sendByteCommand

      public void sendByteCommand(int regAddress, byte command)
      This method sends a byte command to the device.
      Parameters:
      regAddress - specifies the register address to write to.
      command - specifies the command byte.
    • sendWordCommand

      public void sendWordCommand(int regAddress, short command)
      This method sends a 16-bit command to the device.
      Parameters:
      regAddress - specifies the register address to write to.
      command - specifies the 16-bit command.