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

    Nested classes/interfaces inherited from class edu.wpi.first.hal.JNIWrapper

    JNIWrapper.Helper
  • 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.

    Methods inherited from class edu.wpi.first.hal.JNIWrapper

    forceLoad, suppressUnused

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getCANPacketBaseTime

      public static long 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

      public static int initializeCAN​(int manufacturer, int deviceId, int deviceType)
      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 manufacturer
      deviceId - the device ID (0-63)
      deviceType - the device type
      Returns:
      the created CAN handle
      See Also:
      "HAL_InitializeCAN"
    • cleanCAN

      public static void cleanCAN​(int handle)
      Frees a CAN device.
      Parameters:
      handle - the CAN handle
      See Also:
      "HAL_CleanCAN"
    • writeCANPacket

      public static void writeCANPacket​(int handle, byte[] data, int apiId)
      Writes a packet to the CAN device with a specific ID.

      This ID is 10 bits.

      Parameters:
      handle - the CAN handle
      data - the data to write (0-8 bytes)
      apiId - the ID to write (0-1023 bits)
      See Also:
      "HAL_WriteCANPacket"
    • writeCANPacketRepeating

      public static void writeCANPacketRepeating​(int handle, byte[] data, int apiId, 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 handle
      data - 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

      public 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.

      By spec, the length must be equal to the length sent by the other device, otherwise behavior is unspecified.

      Parameters:
      handle - the CAN handle
      length - the length of data to request (0-8)
      apiId - the ID to write (0-1023)
      See Also:
      "HAL_WriteCANRTRFrame"
    • writeCANPacketNoThrow

      public static int writeCANPacketNoThrow​(int handle, byte[] data, int apiId)
      Writes a packet to the CAN device with a specific ID without throwing on error.

      This ID is 10 bits.

      Parameters:
      handle - the CAN handle
      data - 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

      public 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.

      This ID is 10 bits.

      The RoboRIO will automatically repeat the packet at the specified interval

      Parameters:
      handle - the CAN handle
      data - 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

      public 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.

      By spec, the length must be equal to the length sent by the other device, otherwise behavior is unspecified.

      Parameters:
      handle - the CAN handle
      length - 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

      public static void stopCANPacketRepeating​(int handle, int apiId)
      Stops a repeating packet with a specific ID.

      This ID is 10 bits.

      Parameters:
      handle - the CAN handle
      apiId - the ID to stop repeating (0-1023)
      See Also:
      "HAL_StopCANPacketRepeating"
    • readCANPacketNew

      public static boolean readCANPacketNew​(int handle, int apiId, CANData data)
      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 handle
      apiId - the ID to read (0-1023)
      data - the packet data (8 bytes)
      Returns:
      true on success, false on error
      See Also:
      "HAL_ReadCANPacketNew"
    • readCANPacketLatest

      public static boolean readCANPacketLatest​(int handle, int apiId, CANData data)
      Reads a CAN packet. The will continuously return the last packet received, without accounting for packet age.
      Parameters:
      handle - the CAN handle
      apiId - the ID to read (0-1023)
      data - the packet data (8 bytes)
      Returns:
      true on success, false on error
      See Also:
      "HAL_ReadCANPacketLatest"
    • readCANPacketTimeout

      public static boolean readCANPacketTimeout​(int handle, int apiId, int timeoutMs, CANData data)
      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 handle
      apiId - the ID to read (0-1023)
      timeoutMs - the timeout time for the packet
      data - the packet data (8 bytes)
      Returns:
      true on success, false on error
      See Also:
      "HAL_ReadCANPacketTimeout"