Package me.autobot.lib.hardware.serial
Class SerialConnection
java.lang.Object
me.autobot.lib.hardware.Connection
me.autobot.lib.hardware.serial.SerialConnection
- Direct Known Subclasses:
SensorHubSerialConnection
Serial connection class.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSerialConnection(int baudRate, String commPort) Creates a new serial connection with the given baud rate and comm port. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDisables all serial connections.intGets the baud rate of the serial connection.Gets the comm port of the serial connection.protected voidonSerialData(byte[] data) Handles the serial data.booleanopen()Checks if the serial port is open.protected voidwrite(byte[] data) Writes the given data to the serial port.voidwrite(int[] data) Writes the given data to the serial port.
-
Field Details
-
serialVerboseLevel
public static int serialVerboseLevelVerbose level for serial errors. 0=none, 1=notify there's an error, 2=print stack trace
-
-
Constructor Details
-
SerialConnection
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:
writein classConnection- 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
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.
-