Package frclib.robotcore
Class FrcSerialPortDevice
java.lang.Object
trclib.robotcore.TrcSerialBusDevice
frclib.robotcore.FrcSerialPortDevice
This class implements a platform dependent serial port device (UART). It extends TrcSerialBusDevice to provide
asynchronous request queue support and creates the SerialPort device using WPILib.
-
Nested Class Summary
Nested classes/interfaces inherited from class trclib.robotcore.TrcSerialBusDevice
TrcSerialBusDevice.Request
-
Field Summary
Fields inherited from class trclib.robotcore.TrcSerialBusDevice
instanceName, tracer
-
Constructor Summary
ConstructorsConstructorDescriptionFrcSerialPortDevice
(String instanceName, int baudRate, int dataBits, edu.wpi.first.wpilibj.SerialPort.Parity parity, edu.wpi.first.wpilibj.SerialPort.StopBits stopBits, boolean useRequestQueue) Constructor: Creates an instance of the object.FrcSerialPortDevice
(String instanceName, edu.wpi.first.wpilibj.SerialPort.Port port, int baudRate, boolean useRequestQueue) Constructor: Creates an instance of the object.FrcSerialPortDevice
(String instanceName, edu.wpi.first.wpilibj.SerialPort.Port port, int baudRate, int dataBits, edu.wpi.first.wpilibj.SerialPort.Parity parity, edu.wpi.first.wpilibj.SerialPort.StopBits stopBits, boolean useRequestQueue) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
readData
(int address, int length) This method is called to read data from the device with the specified length.int
writeData
(int address, byte[] buffer, int length) This method is called to write data to the device with the specified data buffer and length.Methods inherited from class trclib.robotcore.TrcSerialBusDevice
asyncRead, asyncRead, asyncRead, asyncRead, asyncRead, asyncWrite, asyncWrite, asyncWrite, isEnabled, preemptiveWrite, sendByteCommand, sendWordCommand, setEnabled, syncRead, syncRead, syncWrite, syncWrite, toString
-
Constructor Details
-
FrcSerialPortDevice
public FrcSerialPortDevice(String instanceName, edu.wpi.first.wpilibj.SerialPort.Port port, int baudRate, int dataBits, edu.wpi.first.wpilibj.SerialPort.Parity parity, edu.wpi.first.wpilibj.SerialPort.StopBits stopBits, boolean useRequestQueue) Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.port
- specifies the serial port (on-board or on the MXP).baudRate
- specifies the serial baud rate.dataBits
- specifies the number of data bits.parity
- specifies the parity type.stopBits
- specifies the number of stop bits.useRequestQueue
- specifies true to use a request queue, false otherwise.
-
FrcSerialPortDevice
public FrcSerialPortDevice(String instanceName, int baudRate, int dataBits, edu.wpi.first.wpilibj.SerialPort.Parity parity, edu.wpi.first.wpilibj.SerialPort.StopBits stopBits, boolean useRequestQueue) Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.baudRate
- specifies the serial baud rate.dataBits
- specifies the number of data bits.parity
- specifies the parity type.stopBits
- specifies the number of stop bits.useRequestQueue
- specifies true to use a request queue, false otherwise.
-
FrcSerialPortDevice
public FrcSerialPortDevice(String instanceName, edu.wpi.first.wpilibj.SerialPort.Port port, int baudRate, boolean useRequestQueue) Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name.port
- specifies the serial port (on-board or on the MXP).baudRate
- specifies the serial baud rate.useRequestQueue
- specifies true to use a request queue, false otherwise.
-
-
Method Details
-
readData
public byte[] readData(int address, int length) This method is called to read data from the device with the specified length.- Specified by:
readData
in classTrcSerialBusDevice
- Parameters:
address
- specifies the data address if any (not applicable for SerialPort).length
- specifies the number of bytes to read. If zero, read all that has been received.- Returns:
- a byte array containing the data read.
-
writeData
public int writeData(int address, byte[] buffer, int length) This method is called to write data to the device with the specified data buffer and length.- Specified by:
writeData
in classTrcSerialBusDevice
- Parameters:
address
- specifies the data address if any (not applicable for SerialPort).buffer
- specifies the buffer containing the data to be written to the device.length
- specifies the number of bytes to write.- Returns:
- number of bytes written.
-