public class I2C extends SensorBase
This class is intended to be used by sensor (and other I2C device) drivers. It probably should not be used directly.
Modifier and Type | Class and Description |
---|---|
static class |
I2C.Port |
kAnalogInputChannels, kAnalogOutputChannels, kDigitalChannels, kPCMModules, kPDPChannels, kPDPModules, kPwmChannels, kRelayChannels, kSolenoidChannels, kSystemClockTicksPerMicrosecond
Constructor and Description |
---|
I2C(I2C.Port port,
int deviceAddress)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addressOnly()
Attempt to address a device on the I2C bus.
|
void |
free()
Destructor.
|
boolean |
read(int registerAddress,
int count,
byte[] buffer)
Execute a read transaction with the device.
|
boolean |
read(int registerAddress,
int count,
java.nio.ByteBuffer buffer)
Execute a read transaction with the device.
|
boolean |
readOnly(byte[] buffer,
int count)
Execute a read only transaction with the device.
|
boolean |
readOnly(java.nio.ByteBuffer buffer,
int count)
Execute a read only transaction with the device.
|
boolean |
transaction(byte[] dataToSend,
int sendSize,
byte[] dataReceived,
int receiveSize)
Generic transaction.
|
boolean |
transaction(java.nio.ByteBuffer dataToSend,
int sendSize,
java.nio.ByteBuffer 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.
|
boolean |
writeBulk(byte[] data)
Execute a write transaction with the device.
|
boolean |
writeBulk(java.nio.ByteBuffer data,
int size)
Execute a write transaction with the device.
|
checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPDPChannel, checkPDPModule, checkPWMChannel, checkRelayChannel, checkSolenoidChannel, checkSolenoidModule, getDefaultSolenoidModule, setDefaultSolenoidModule
public void free()
free
in class SensorBase
public boolean transaction(byte[] dataToSend, int sendSize, byte[] dataReceived, int receiveSize)
This is a lower-level interface to the I2C hardware giving you more control over each transaction.
dataToSend
- Buffer of data to send as part of the transaction.sendSize
- Number of bytes to send as part of the transaction.dataReceived
- Buffer to read data into.receiveSize
- Number of bytes to read from the device.public boolean transaction(java.nio.ByteBuffer dataToSend, int sendSize, java.nio.ByteBuffer dataReceived, int receiveSize)
This is a lower-level interface to the I2C hardware giving you more control over each transaction.
dataToSend
- Buffer of data to send as part of the transaction. Must be allocated using
ByteBuffer.allocateDirect().sendSize
- Number of bytes to send as part of the transaction.dataReceived
- Buffer to read data into. Must be allocated using ByteBuffer.allocateDirect(int)
.receiveSize
- Number of bytes to read from the device.public boolean addressOnly()
This allows you to figure out if there is a device on the I2C bus that responds to the address specified in the constructor.
public boolean write(int registerAddress, int data)
Write a single byte to a register on a device and wait until the transaction is complete.
registerAddress
- The address of the register on the device to be written.data
- The byte to write to the register on the device.public boolean writeBulk(byte[] data)
Write multiple bytes to a register on a device and wait until the transaction is complete.
data
- The data to write to the device.public boolean writeBulk(java.nio.ByteBuffer data, int size)
Write multiple bytes to a register on a device and wait until the transaction is complete.
data
- The data to write to the device. Must be created using ByteBuffer.allocateDirect().public boolean read(int registerAddress, int count, byte[] buffer)
Read bytes from a device. Most I2C devices will auto-increment the register pointer internally allowing you to read consecutive registers on a device in a single transaction.
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.public boolean read(int registerAddress, int count, java.nio.ByteBuffer buffer)
Read bytes from a device. Most I2C devices will auto-increment the register pointer internally allowing you to read consecutive registers on a device in a single transaction.
registerAddress
- The register to read first in the transaction.count
- The number of bytes to read in the transaction.buffer
- A buffer to store the data read from the device. Must be created using
ByteBuffer.allocateDirect().public boolean readOnly(byte[] buffer, int count)
Read bytes from a device. This method does not write any data to prompt the device.
buffer
- A pointer to the array of bytes to store the data read from the device.count
- The number of bytes to read in the transaction.public boolean readOnly(java.nio.ByteBuffer buffer, int count)
Read bytes from a device. This method does not write any data to prompt the device.
buffer
- A pointer to the array of bytes to store the data read from the device. Must be
created using ByteBuffer.allocateDirect().count
- The number of bytes to read in the transaction.public boolean verifySensor(int registerAddress, int count, byte[] expected)
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.
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.