public class CAN extends Object implements Closeable
No packets that can be sent gets blocked by the RoboRIO, so all methods work identically in all robot modes.
All methods are thread safe, however the CANData object passed into the read methods and the byte[] passed into the write methods need to not be modified for the duration of their respective calls.
Modifier and Type | Field and Description |
---|---|
static int |
kTeamDeviceType |
static int |
kTeamManufacturer |
Constructor and Description |
---|
CAN(int deviceId)
Create a new CAN communication interface with the specific device ID.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the CAN communication.
|
boolean |
readPacketLatest(int apiId,
CANData data)
Read a CAN packet.
|
boolean |
readPacketNew(int apiId,
CANData data)
Read a new CAN packet.
|
boolean |
readPacketTimeout(int apiId,
int timeoutMs,
CANData data)
Read a CAN packet.
|
boolean |
readPeriodicPacket(int apiId,
int timeoutMs,
int periodMs,
CANData data)
Read a CAN packet.
|
void |
stopPacketRepeating(int apiId)
Stop a repeating packet with a specific ID.
|
void |
writePacket(byte[] data,
int apiId)
Write a packet to the CAN device with a specific ID.
|
void |
writePacketRepeating(byte[] data,
int apiId,
int repeatMs)
Write a repeating packet to the CAN device with a specific ID.
|
public static final int kTeamManufacturer
public static final int kTeamDeviceType
public CAN(int deviceId)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void writePacket(byte[] data, int apiId)
data
- The data to write (8 bytes max)apiId
- The API ID to write.public void writePacketRepeating(byte[] data, int apiId, int repeatMs)
data
- The data to write (8 bytes max)apiId
- The API ID to write.repeatMs
- The period to repeat the packet at.public void stopPacketRepeating(int apiId)
apiId
- The API ID to stop repeatingpublic boolean readPacketNew(int apiId, CANData data)
apiId
- The API ID to read.data
- Storage for the received data.public boolean readPacketLatest(int apiId, CANData data)
apiId
- The API ID to read.data
- Storage for the received data.public boolean readPacketTimeout(int apiId, int timeoutMs, CANData data)
apiId
- The API ID to read.timeoutMs
- The timeout time for the packetdata
- Storage for the received data.public boolean readPeriodicPacket(int apiId, int timeoutMs, int periodMs, CANData data)
apiId
- The API ID to read.timeoutMs
- The timeout time for the packetperiodMs
- The usual period for the packetdata
- Storage for the received data.