Package edu.wpi.first.hal
Class CANAPIJNI
java.lang.Object
edu.wpi.first.hal.JNIWrapper
edu.wpi.first.hal.CANAPIJNI
public class CANAPIJNI extends JNIWrapper
CAN API HAL JNI Functions.
- See Also:
- "hal/CANAPI.h"
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description CANAPIJNI()
-
Method Summary
Modifier and Type Method Description static void
cleanCAN(int handle)
Frees a CAN device.static long
getCANPacketBaseTime()
Reads the current value of the millisecond-resolution timer that the CAN API functions use as a time base.static int
initializeCAN(int manufacturer, int deviceId, int deviceType)
Initializes a CAN device.static boolean
readCANPacketLatest(int handle, int apiId, CANData data)
Reads a CAN packet.static boolean
readCANPacketNew(int handle, int apiId, CANData data)
Reads a new CAN packet.static boolean
readCANPacketTimeout(int handle, int apiId, int timeoutMs, CANData data)
Reads a CAN packet.static void
stopCANPacketRepeating(int handle, int apiId)
Stops a repeating packet with a specific ID.static void
writeCANPacket(int handle, byte[] data, int apiId)
Writes a packet to the CAN device with a specific ID.static int
writeCANPacketNoThrow(int handle, byte[] data, int apiId)
Writes a packet to the CAN device with a specific ID without throwing on error.static void
writeCANPacketRepeating(int handle, byte[] data, int apiId, int repeatMs)
Writes a repeating packet to the CAN device with a specific ID.static int
writeCANPacketRepeatingNoThrow(int handle, byte[] data, int apiId, int repeatMs)
Writes a repeating packet to the CAN device with a specific ID without throwing on error.static void
writeCANRTRFrame(int handle, int length, int apiId)
Writes an RTR frame of the specified length to the CAN device with the specific ID.static int
writeCANRTRFrameNoThrow(int handle, int length, int apiId)
Writes an RTR frame of the specified length to the CAN device with the specific ID without throwing on error.
-
Constructor Details
-
Method Details
-
getCANPacketBaseTime
Reads the current value of the millisecond-resolution timer that the CAN API functions use as a time base.- Returns:
- Current value of timer used as a base time by the CAN API in milliseconds.
- See Also:
- "HAL_GetCANPacketBaseTime"
-
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:
manufacturer
- 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 handledata
- the data to write (0-8 bytes)apiId
- the ID to write (0-1023 bits)- See Also:
- "HAL_WriteCANPacket"
-
writeCANPacketRepeating
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 handledata
- the data to write (0-8 bytes)apiId
- the ID to write (0-1023)repeatMs
- 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 handlelength
- the length of data to request (0-8)apiId
- the ID to write (0-1023)- See Also:
- "HAL_WriteCANRTRFrame"
-
writeCANPacketNoThrow
Writes a packet to the CAN device with a specific ID without throwing on error.This ID is 10 bits.
- Parameters:
handle
- the CAN handledata
- the data to write (0-8 bytes)apiId
- the ID to write (0-1023 bits)- Returns:
- Error status variable. 0 on success.
- See Also:
- "HAL_WriteCANPacket"
-
writeCANPacketRepeatingNoThrow
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 handledata
- the data to write (0-8 bytes)apiId
- the ID to write (0-1023)repeatMs
- the period to repeat in ms- Returns:
- Error status variable. 0 on success.
- See Also:
- "HAL_WriteCANPacketRepeating"
-
writeCANRTRFrameNoThrow
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 handlelength
- the length of data to request (0-8)apiId
- the ID to write (0-1023)- 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 packet data (8 bytes)- 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 packet data (8 bytes)- Returns:
- true on success, false on error
- See Also:
- "HAL_ReadCANPacketLatest"
-
readCANPacketTimeout
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)timeoutMs
- the timeout time for the packetdata
- the packet data (8 bytes)- Returns:
- true on success, false on error
- See Also:
- "HAL_ReadCANPacketTimeout"
-