Class SerialPortJNI
- See Also:
-
- "SerialPort.h"
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.hal.JNIWrapper
JNIWrapper.Helper -
Method Summary
Modifier and TypeMethodDescriptionstatic voidserialClear(int handle) Clears the receive buffer of the serial port.static voidserialClose(int handle) Closes a serial port.static voidserialDisableTermination(int handle) Disables a termination character for reads.static voidserialEnableTermination(int handle, char terminator) Sets the termination character that terminates a read.static voidserialFlush(int handle) Flushes the serial write buffer out to the port.static intserialGetBytesReceived(int handle) Gets the number of bytes currently in the read buffer.static intserialInitializePort(byte port) Initializes a serial port.static intserialInitializePortDirect(byte port, String portName) Initializes a serial port with a direct name.static intserialRead(int handle, byte[] buffer, int count) Reads data from the serial port.static voidserialSetBaudRate(int handle, int baud) Sets the baud rate of a serial port.static voidserialSetDataBits(int handle, byte bits) Sets the number of data bits on a serial port.static voidserialSetFlowControl(int handle, byte flow) Sets the flow control mode of a serial port.static voidserialSetParity(int handle, byte parity) Sets the number of parity bits on a serial port.static voidserialSetReadBufferSize(int handle, int size) Sets the size of the read buffer.static voidserialSetStopBits(int handle, byte stopBits) Sets the number of stop bits on a serial port.static voidserialSetTimeout(int handle, double timeout) Sets the minimum serial read timeout of a port.static voidserialSetWriteBufferSize(int handle, int size) Sets the size of the write buffer.static voidserialSetWriteMode(int handle, byte mode) Sets the write mode on a serial port.static intserialWrite(int handle, byte[] buffer, int count) Writes data to the serial port.Methods inherited from class edu.wpi.first.hal.JNIWrapper
forceLoad, suppressUnused
-
Method Details
-
serialInitializePort
Initializes a serial port.The channels are either the onboard RS232, the MXP UART, or 2 USB ports. The top port is USB1, the bottom port is USB2.
- Parameters:
port- the serial port to initialize- Returns:
- Serial Port Handle
- See Also:
-
- "HAL_InitializeSerialPort"
-
serialInitializePortDirect
Initializes a serial port with a direct name.This name is the /dev name for a specific port. Note these are not always consistent between roboRIO reboots.
- Parameters:
port- the serial port to initializeportName- the dev port name- Returns:
- Serial Port Handle
- See Also:
-
- "HAL_InitializeSerialPortDirect"
-
serialSetBaudRate
Sets the baud rate of a serial port.Any value between 0 and 0xFFFFFFFF may be used. Default is 9600.
- Parameters:
handle- the serial port handlebaud- the baud rate to set- See Also:
-
- "HAL_SetSerialBaudRate"
-
serialSetDataBits
Sets the number of data bits on a serial port.Defaults to 8.
- Parameters:
handle- the serial port handlebits- the number of data bits (5-8)- See Also:
-
- "HAL_SetSerialDataBits"
-
serialSetParity
Sets the number of parity bits on a serial port.Valid values are: 0: None (default) 1: Odd 2: Even 3: Mark - Means exists and always 1 4: Space - Means exists and always 0
- Parameters:
handle- the serial port handleparity- the parity bit mode (see remarks for valid values)- See Also:
-
- "HAL_SetSerialParity"
-
serialSetStopBits
Sets the number of stop bits on a serial port.Valid values are: 10: One stop bit (default) 15: One and a half stop bits 20: Two stop bits
- Parameters:
handle- the serial port handlestopBits- the stop bit value (see remarks for valid values)- See Also:
-
- "HAL_SetSerialStopBits"
-
serialSetWriteMode
Sets the write mode on a serial port.Valid values are: 1: Flush on access 2: Flush when full (default)
- Parameters:
handle- the serial port handlemode- the mode to set (see remarks for valid values)- See Also:
-
- "HAL_SetSerialWriteMode"
-
serialSetFlowControl
Sets the flow control mode of a serial port.Valid values are: 0: None (default) 1: XON-XOFF 2: RTS-CTS 3: DTR-DSR
- Parameters:
handle- the serial port handleflow- the mode to set (see remarks for valid values)- See Also:
-
- "HAL_SetSerialFlowControl"
-
serialSetTimeout
Sets the minimum serial read timeout of a port.- Parameters:
handle- the serial port handletimeout- the timeout in milliseconds- See Also:
-
- "HAL_SetSerialTimeout"
-
serialEnableTermination
Sets the termination character that terminates a read.By default this is disabled.
- Parameters:
handle- the serial port handleterminator- the termination character to set- See Also:
-
- "HAL_EnableSerialTermination"
-
serialDisableTermination
Disables a termination character for reads.- Parameters:
handle- the serial port handle- See Also:
-
- "HAL_DisableSerialTermination"
-
serialSetReadBufferSize
Sets the size of the read buffer.- Parameters:
handle- the serial port handlesize- the read buffer size- See Also:
-
- "HAL_SetSerialReadBufferSize"
-
serialSetWriteBufferSize
Sets the size of the write buffer.- Parameters:
handle- the serial port handlesize- the write buffer size- See Also:
-
- "HAL_SetSerialWriteBufferSize"
-
serialGetBytesReceived
Gets the number of bytes currently in the read buffer.- Parameters:
handle- the serial port handle- Returns:
- the number of bytes in the read buffer
- See Also:
-
- "HAL_GetSerialBytesReceived"
-
serialRead
Reads data from the serial port.Will wait for either timeout (if set), the termination char (if set), or the count to be full. Whichever one comes first.
- Parameters:
handle- the serial port handlebuffer- the buffer in which to store bytes readcount- the number of bytes maximum to read- Returns:
- the number of bytes actually read
- See Also:
-
- "HAL_ReadSerial"
-
serialWrite
Writes data to the serial port.- Parameters:
handle- the serial port handlebuffer- the buffer to writecount- the number of bytes to write from the buffer- Returns:
- the number of bytes actually written
- See Also:
-
- "HAL_WriteSerial"
-
serialFlush
Flushes the serial write buffer out to the port.- Parameters:
handle- the serial port handle- See Also:
-
- "HAL_FlushSerial"
-
serialClear
Clears the receive buffer of the serial port.- Parameters:
handle- the serial port handle- See Also:
-
- "HAL_ClearSerial"
-
serialClose
Closes a serial port.- Parameters:
handle- the serial port handle to close- See Also:
-
- "HAL_CloseSerial"
-