Class SerialConnection

java.lang.Object
me.autobot.lib.hardware.Connection
me.autobot.lib.hardware.serial.SerialConnection
Direct Known Subclasses:
SensorHubSerialConnection

public class SerialConnection extends Connection
Serial connection class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    Verbose level for serial errors.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SerialConnection(int baudRate, String commPort)
    Creates a new serial connection with the given baud rate and comm port.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Disables all serial connections.
    int
    Gets the baud rate of the serial connection.
    Gets the comm port of the serial connection.
    protected void
    onSerialData(byte[] data)
    Handles the serial data.
    boolean
    Checks if the serial port is open.
    protected void
    write(byte[] data)
    Writes the given data to the serial port.
    void
    write(int[] data)
    Writes the given data to the serial port.

    Methods inherited from class java.lang.Object

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

    • serialVerboseLevel

      public static int serialVerboseLevel
      Verbose level for serial errors. 0=none, 1=notify there's an error, 2=print stack trace
  • Constructor Details

    • SerialConnection

      public SerialConnection(int baudRate, String commPort)
      Creates a new serial connection with the given baud rate and comm port.
      Parameters:
      baudRate - The baud rate of the serial connection.
      commPort - The comm port of the serial connection.
  • Method Details

    • disableConnections

      public static void disableConnections()
      Disables all serial connections.
    • onSerialData

      protected void onSerialData(byte[] data)
      Handles the serial data.
      Parameters:
      data - The data to handle.
    • write

      protected void write(byte[] data)
      Writes the given data to the serial port.
      Overrides:
      write in class Connection
      Parameters:
      data - The data to write to the serial port.
    • write

      public void write(int[] data)
      Writes the given data to the serial port.
      Parameters:
      data - The data to write to the serial port.
    • open

      public boolean open()
      Checks if the serial port is open.
      Returns:
      True if the port is open, false otherwise.
    • getCommPort

      public String getCommPort()
      Gets the comm port of the serial connection.
      Returns:
      The comm port of the serial connection.
    • getBaudRate

      public int getBaudRate()
      Gets the baud rate of the serial connection.
      Returns:
      The baud rate of the serial connection.