Class CANBus

java.lang.Object
com.ctre.phoenix6.CANBus

public class CANBus extends Object
Class for getting information about an available CAN bus.
  • Constructor Details

    • CANBus

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

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

      For the native roboRIO CAN bus, use roboRIO() instead.

      Parameters:
      canbus - Name of the CAN bus. Possible CAN bus strings are:
      • "rio" for the native roboRIO CAN bus
      • 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:
        • "rio" on roboRIO
        • "can0" on Linux
        • "*" on Windows
    • CANBus

      public CANBus(String canbus, String hootFilepath)
      Creates a new CAN bus with the given name, and loads an associated hoot file for replay (equivalent to HootReplay.loadFile(java.lang.String)).

      Only one hoot log may be replayed at a time. As a result, only one CAN bus should be constructed with a hoot file.

      When using relative paths, the file path is typically relative to the top-level folder of the robot project.

      For the native roboRIO CAN bus, use roboRIO(String) instead.

      Parameters:
      canbus - Name of the CAN bus. Possible CAN bus strings are:
      • "rio" for the native roboRIO CAN bus
      • 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:
        • "rio" on roboRIO
        • "can0" on Linux
        • "*" on Windows
      hootFilepath - Path and name of the hoot file to load
  • Method Details

    • roboRIO

      public static CANBus roboRIO()
      Creates a new CAN bus for the native roboRIO bus.
      Returns:
      The native roboRIO CAN bus
    • roboRIO

      public static CANBus roboRIO(String hootFilepath)
      Creates a new CAN bus for the native roboRIO bus, and loads an associated hoot file for replay (equivalent to HootReplay.loadFile(java.lang.String)).

      Only one hoot log may be replayed at a time. As a result, only one CAN bus should be constructed with a hoot file.

      When using relative paths, the file path is typically relative to the top-level folder of the robot project.

      Parameters:
      hootFilepath - Path and name of the hoot file to load
      Returns:
      The native roboRIO CAN bus
    • getName

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

      public final boolean isNetworkFD()
      Gets whether the network is CAN FD.
      Returns:
      True if the network is CAN FD
    • 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).

      This function refreshes and returns a cached object.

      Returns:
      Status of the CAN bus
    • toString

      public String toString()
      Overrides:
      toString in class Object