Class CANBus

java.lang.Object
com.ctre.phoenix6.CANBus
All Implemented Interfaces:
Cloneable, Comparable<CANBus>

public class CANBus extends Object implements Cloneable, Comparable<CANBus>
Class for getting information about an available CAN bus.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Contains status information about a CAN bus.
    static enum 
    Possible states of the CAN bus.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new CAN bus using the default for the system: "can_s2" on Systemcore "can0" on Linux "*" on Windows
    CANBus(String canbus)
    Creates a new CAN bus with the given name.
    CANBus(CANPort canPort)
    Creates a new CAN bus for one of the native Systemcore/Motioncore buses.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    int
    Compares the two CAN bus names.
    boolean
    equals(Object other)
     
    final String
    Get the name used to construct this CAN bus.
    Get the name used to construct this CAN bus as UTF-8 bytes, including null termination.
    Gets the status of the CAN bus, including the bus utilization and the error counters.
    int
     
    final boolean
    Gets whether the network is CAN FD.
     

    Methods inherited from class Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CANBus

      public CANBus()
      Creates a new CAN bus using the default for the system:
      • "can_s2" on Systemcore
      • "can0" on Linux
      • "*" on Windows
    • CANBus

      public CANBus(String canbus)
      Creates a new CAN bus with the given name.

      For the native Systemcore/Motioncore CAN buses, use CANBus(CANPort) instead.

      Parameters:
      canbus - Name of the CAN bus. Possible CAN bus strings are:
      • "can_s0" to "can_s4" for the native Systemcore CAN buses
      • "can_d0" to "can_d19" for the Motioncore CAN buses
      • CANivore name or serial number
      • SocketCAN interface (non-FRC Linux only)
      • "*" for any CANivore seen by the program
      • empty string (default) to select the default for the system:
        • "can_s2" on Systemcore
        • "can0" on Linux
        • "*" on Windows
    • CANBus

      public CANBus(CANPort canPort)
      Creates a new CAN bus for one of the native Systemcore/Motioncore buses.

      For the CANivore and non-FRC SocketCAN interfaces, use CANBus(String) instead.

      Parameters:
      canPort - The Systemcore/Motioncore CAN port
  • Method Details

    • getName

      public final String getName()
      Get the name used to construct this CAN bus.
      Returns:
      Name of the CAN bus
    • getNameUTF8Bytes

      public final MemorySegment getNameUTF8Bytes()
      Get the name used to construct this CAN bus as UTF-8 bytes, including null termination. This is only used for FFI; robot code should call getName() instead.
      Returns:
      Name of the CAN bus as UTF-8 bytes
    • isNetworkFD

      public final boolean isNetworkFD()
      Gets whether the network is CAN FD.
      Returns:
      True if the network is CAN FD
    • getStatus

      public final CANBus.CANBusStatus getStatus()
      Gets the status of the CAN bus, including the bus utilization and the error counters.

      This can block for up to 0.001 seconds (1 ms).

      Returns:
      Status of the CAN bus
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • clone

      public CANBus clone()
      Overrides:
      clone in class Object
    • compareTo

      public int compareTo(CANBus other)
      Compares the two CAN bus names.
      Specified by:
      compareTo in interface Comparable<CANBus>
      Parameters:
      other - The CANBus to be compared
      Returns:
      The result of calling String.compareTo(String) on the names of the two CAN buses