Package lib.custom
Class CustomCAN
java.lang.Object
lib.custom.CustomCAN
- Direct Known Subclasses:
CANSensor,CustomNeoPixels
This class allows sending and receiving of messages over CAN to a specific
ID.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetName()Optional<byte[]>read()Reads data, returning an empty Optional if there is no available message.protected byte[]Read data as bytebufferbyte[]Reads data Also stops repeating the last message.voidwrite(byte[] data) Used to write data to the device.voidwriteSafely(byte[] data) Used to write data to the device.
-
Field Details
-
messageID
protected final int messageID -
name
-
-
Constructor Details
-
CustomCAN
Constructor for a CustomCAN device. The name is local and for your convenience only. The id should be the same as the id programmed into the CAN device- Parameters:
name-id- ID of CAN device (0x600 to 0x700, corresponds to a Teensy)
-
-
Method Details
-
getName
-
write
public void write(byte[] data) Used to write data to the device.- Parameters:
data- Data to be written. Should be EXACTLY 8 bytes long ONLY.
-
writeSafely
public void writeSafely(byte[] data) Used to write data to the device.- Parameters:
data- Data to be written. Should be EXACTLY 8 bytes long ONLY.- Throws:
edu.wpi.first.hal.util.UncleanStatusException
-
readBuffer
Read data as bytebuffer- Returns:
- ByteBuffer containing CAN message, or null
- Throws:
CANMessageUnavailableException- when no new message is available
-
readSafely
Reads data Also stops repeating the last message.- Returns:
- byte[] (8 long)
- Throws:
CANMessageUnavailableException
-
read
Reads data, returning an empty Optional if there is no available message.- Returns:
- Optional byte[]
-