Package edu.wpi.first.hal
Class CANAPIJNI
java.lang.Object
edu.wpi.first.hal.JNIWrapper
edu.wpi.first.hal.CANAPIJNI
CAN API HAL JNI Functions.
- See Also:
-
- "hal/CANAPI.h"
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.hal.JNIWrapper
JNIWrapper.Helper
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
cleanCAN
(int handle) Frees a CAN device.static int
initializeCAN
(int busId, int manufacturer, int deviceId, int deviceType) Initializes a CAN device.static boolean
readCANPacketLatest
(int handle, int apiId, CANReceiveMessage data) Reads a CAN packet.static boolean
readCANPacketNew
(int handle, int apiId, CANReceiveMessage data) Reads a new CAN packet.static boolean
readCANPacketTimeout
(int handle, int apiId, CANReceiveMessage data, int timeoutMs) Reads a CAN packet.static void
stopCANPacketRepeating
(int handle, int apiId) Stops a repeating packet with a specific ID.static void
writeCANPacket
(int handle, int apiId, byte[] data, int dataLength, int flags) Writes a packet to the CAN device with a specific ID.static int
writeCANPacketNoThrow
(int handle, int apiId, byte[] data, int dataLength, int flags) Writes a packet to the CAN device with a specific ID without throwing on error.static void
writeCANPacketRepeating
(int handle, int apiId, byte[] data, int dataLength, int flags, int repeatMs) Writes a repeating packet to the CAN device with a specific ID.static int
writeCANPacketRepeatingNoThrow
(int handle, int apiId, byte[] data, int dataLength, int flags, int repeatMs) Writes a repeating packet to the CAN device with a specific ID without throwing on error.static void
writeCANRTRFrame
(int handle, int apiId, byte[] data, int dataLength, int flags) Writes an RTR frame of the specified length to the CAN device with the specific ID.static int
writeCANRTRFrameNoThrow
(int handle, int apiId, byte[] data, int dataLength, int flags) Writes an RTR frame of the specified length to the CAN device with the specific ID without throwing on error.Methods inherited from class edu.wpi.first.hal.JNIWrapper
forceLoad, suppressUnused
-
Method Details
-
initializeCAN
Initializes a CAN device.These follow the FIRST standard CAN layout. https://docs.wpilib.org/en/stable/docs/software/can-devices/can-addressing.html
- Parameters:
busId
- the bus IDmanufacturer
- the can manufacturerdeviceId
- the device ID (0-63)deviceType
- the device type- Returns:
- the created CAN handle
- See Also:
-
- "HAL_InitializeCAN"
-
cleanCAN
Frees a CAN device.- Parameters:
handle
- the CAN handle- See Also:
-
- "HAL_CleanCAN"
-
writeCANPacket
Writes a packet to the CAN device with a specific ID.This ID is 10 bits.
- Parameters:
handle
- the CAN handleapiId
- the ID to write (0-1023 bits)data
- the data to send.dataLength
- the length of data to sendflags
- the message flags- See Also:
-
- "HAL_WriteCANPacket"
-
writeCANPacketRepeating
public static void writeCANPacketRepeating(int handle, int apiId, byte[] data, int dataLength, int flags, int repeatMs) Writes a repeating packet to the CAN device with a specific ID.This ID is 10 bits.
The RoboRIO will automatically repeat the packet at the specified interval
- Parameters:
handle
- the CAN handleapiId
- the ID to write (0-1023)data
- the data to send.dataLength
- the length of data to sendflags
- the message flagsrepeatMs
- the period to repeat in ms- See Also:
-
- "HAL_WriteCANPacketRepeating"
-
writeCANRTRFrame
Writes an RTR frame of the specified length to the CAN device with the specific ID.By spec, the length must be equal to the length sent by the other device, otherwise behavior is unspecified.
- Parameters:
handle
- the CAN handleapiId
- the ID to write (0-1023)data
- the data to send.dataLength
- the length of data to sendflags
- the message flags- See Also:
-
- "HAL_WriteCANRTRFrame"
-
writeCANPacketNoThrow
public static int writeCANPacketNoThrow(int handle, int apiId, byte[] data, int dataLength, int flags) Writes a packet to the CAN device with a specific ID without throwing on error.This ID is 10 bits.
- Parameters:
handle
- the CAN handleapiId
- the ID to write (0-1023 bits)data
- the data to send.dataLength
- the length of data to sendflags
- the message flags- Returns:
- Error status variable. 0 on success.
- See Also:
-
- "HAL_WriteCANPacket"
-
writeCANPacketRepeatingNoThrow
public static int writeCANPacketRepeatingNoThrow(int handle, int apiId, byte[] data, int dataLength, int flags, int repeatMs) Writes a repeating packet to the CAN device with a specific ID without throwing on error.This ID is 10 bits.
The RoboRIO will automatically repeat the packet at the specified interval
- Parameters:
handle
- the CAN handleapiId
- the ID to write (0-1023)data
- the data to send.dataLength
- the length of data to sendflags
- the message flagsrepeatMs
- the period to repeat in ms- Returns:
- Error status variable. 0 on success.
- See Also:
-
- "HAL_WriteCANPacketRepeating"
-
writeCANRTRFrameNoThrow
public static int writeCANRTRFrameNoThrow(int handle, int apiId, byte[] data, int dataLength, int flags) Writes an RTR frame of the specified length to the CAN device with the specific ID without throwing on error.By spec, the length must be equal to the length sent by the other device, otherwise behavior is unspecified.
- Parameters:
handle
- the CAN handleeapiId
- the ID to write (0-1023)data
- the data to send.dataLength
- the length of data to sendflags
- the message flags- Returns:
- Error status variable. 0 on success.
- See Also:
-
- "HAL_WriteCANRTRFrame"
-
stopCANPacketRepeating
Stops a repeating packet with a specific ID.This ID is 10 bits.
- Parameters:
handle
- the CAN handleapiId
- the ID to stop repeating (0-1023)- See Also:
-
- "HAL_StopCANPacketRepeating"
-
readCANPacketNew
Reads a new CAN packet.This will only return properly once per packet received. Multiple calls without receiving another packet will return false.
- Parameters:
handle
- the CAN handleapiId
- the ID to read (0-1023)data
- the received message- Returns:
- true on success, false on error
- See Also:
-
- "HAL_ReadCANPacketNew"
-
readCANPacketLatest
Reads a CAN packet. The will continuously return the last packet received, without accounting for packet age.- Parameters:
handle
- the CAN handleapiId
- the ID to read (0-1023)data
- the received message- Returns:
- true on success, false on error
- See Also:
-
- "HAL_ReadCANPacketLatest"
-
readCANPacketTimeout
public static boolean readCANPacketTimeout(int handle, int apiId, CANReceiveMessage data, int timeoutMs) Reads a CAN packet. The will return the last packet received until the packet is older then the requested timeout. Then it will return false.- Parameters:
handle
- the CAN handleapiId
- the ID to read (0-1023)data
- the received messagetimeoutMs
- the timeout time for the packet- Returns:
- true on success, false on error
- See Also:
-
- "HAL_ReadCANPacketTimeout"
-