Package lib.custom

Class CustomCAN

java.lang.Object
lib.custom.CustomCAN
Direct Known Subclasses:
CANSensor, CustomNeoPixels

public class CustomCAN extends Object
This class allows sending and receiving of messages over CAN to a specific ID.
  • Field Details

    • messageID

      protected final int messageID
    • name

      protected final String name
  • Constructor Details

    • CustomCAN

      public CustomCAN(String name, int id)
      Constructor for a CustomCAN device. The name is local and for your convenience only. The id should be the same as the id programmed into the CAN device
      Parameters:
      name -
      id - ID of CAN device (0x600 to 0x700, corresponds to a Teensy)
  • Method Details

    • getName

      public String getName()
    • write

      public void write(byte[] data)
      Used to write data to the device.
      Parameters:
      data - Data to be written. Should be EXACTLY 8 bytes long ONLY.
    • writeSafely

      public void writeSafely(byte[] data)
      Used to write data to the device.
      Parameters:
      data - Data to be written. Should be EXACTLY 8 bytes long ONLY.
      Throws:
      edu.wpi.first.hal.util.UncleanStatusException
    • readBuffer

      protected byte[] readBuffer() throws CANMessageUnavailableException
      Read data as bytebuffer
      Returns:
      ByteBuffer containing CAN message, or null
      Throws:
      CANMessageUnavailableException - when no new message is available
    • readSafely

      public byte[] readSafely() throws CANMessageUnavailableException
      Reads data Also stops repeating the last message.
      Returns:
      byte[] (8 long)
      Throws:
      CANMessageUnavailableException
    • read

      public Optional<byte[]> read()
      Reads data, returning an empty Optional if there is no available message.
      Returns:
      Optional byte[]