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
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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

    Methods inherited from class java.lang.Object

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

    • initializeCAN

      public static int initializeCAN(int busId, 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:
      busId - the bus ID
      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, int apiId, byte[] data, int dataLength, int flags)
      Writes a packet to the CAN device with a specific ID.

      This ID is 10 bits.

      Parameters:
      handle - the CAN handle
      apiId - the ID to write (0-1023 bits)
      data - the data to send.
      dataLength - the length of data to send
      flags - 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 handle
      apiId - the ID to write (0-1023)
      data - the data to send.
      dataLength - the length of data to send
      flags - the message flags
      repeatMs - the period to repeat in ms
      See Also:
      • "HAL_WriteCANPacketRepeating"
    • writeCANRTRFrame

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

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

      Parameters:
      handle - the CAN handle
      apiId - the ID to write (0-1023)
      data - the data to send.
      dataLength - the length of data to send
      flags - 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 handle
      apiId - the ID to write (0-1023 bits)
      data - the data to send.
      dataLength - the length of data to send
      flags - 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 handle
      apiId - the ID to write (0-1023)
      data - the data to send.
      dataLength - the length of data to send
      flags - the message flags
      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 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 handlee
      apiId - the ID to write (0-1023)
      data - the data to send.
      dataLength - the length of data to send
      flags - the message flags
      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, CANReceiveMessage 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 received message
      Returns:
      true on success, false on error
      See Also:
      • "HAL_ReadCANPacketNew"
    • readCANPacketLatest

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