Package frclib.robotcore
Class FrcI2cDevice
java.lang.Object
trclib.robotcore.TrcSerialBusDevice
frclib.robotcore.FrcI2cDevice
This class implements a platform dependent I2C device. It extends TrcSerialBusDevice to provide asynchronous
request queue support and creates the I2C device using WPILib.
-
Nested Class Summary
Nested classes/interfaces inherited from class trclib.robotcore.TrcSerialBusDevice
TrcSerialBusDevice.Request
-
Field Summary
Fields inherited from class trclib.robotcore.TrcSerialBusDevice
instanceName, tracer
-
Constructor Summary
ConstructorsConstructorDescriptionFrcI2cDevice
(String instanceName, int devAddress, boolean useRequestQueue) Constructor: Creates an instance of the object.FrcI2cDevice
(String instanceName, edu.wpi.first.wpilibj.I2C.Port port, int devAddress, boolean useRequestQueue) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
readData
(int address, int length) This method is called to read data from the device with the specified length.int
writeData
(int address, byte[] buffer, int length) This method is called to write data to the device with the specified data buffer and length.Methods inherited from class trclib.robotcore.TrcSerialBusDevice
asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncWrite, asyncWrite, asyncWrite, isEnabled, preemptiveWrite, sendByteCommand, sendWordCommand, setEnabled, syncRead, syncRead, syncWrite, syncWrite, toString
-
Constructor Details
-
FrcI2cDevice
public FrcI2cDevice(String instanceName, edu.wpi.first.wpilibj.I2C.Port port, int devAddress, boolean useRequestQueue) Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.port
- specifies the I2C port the device is connected to.devAddress
- specifies the address of the device on the I2C bus.useRequestQueue
- specifies true to use a request queue, false otherwise.
-
FrcI2cDevice
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.devAddress
- specifies the address of the device on the I2C bus.useRequestQueue
- specifies true to use a request queue, false otherwise.
-
-
Method Details
-
readData
public byte[] readData(int address, int length) This method is called to read data from the device with the specified length.- Specified by:
readData
in classTrcSerialBusDevice
- Parameters:
address
- specifies the I2C register address to read from if any.length
- specifies the number of bytes to read.- Returns:
- a byte array containing the data read.
-
writeData
public int writeData(int address, byte[] buffer, int length) This method is called to write data to the device with the specified data buffer and length.- Specified by:
writeData
in classTrcSerialBusDevice
- Parameters:
address
- specifies the I2C register address to write to if any.buffer
- specifies the buffer containing the data to be written to the device.length
- specifies the number of bytes to write.- Returns:
- number of bytes written.
-