WPILibC++  2020.3.2
SerialPort.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include "hal/Types.h"
13 
20 // clang-format off
21 HAL_ENUM(HAL_SerialPort) {
22  HAL_SerialPort_Onboard = 0,
23  HAL_SerialPort_MXP = 1,
24  HAL_SerialPort_USB1 = 2,
25  HAL_SerialPort_USB2 = 3
26 };
27 // clang-format on
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
41 HAL_SerialPortHandle HAL_InitializeSerialPort(HAL_SerialPort port,
42  int32_t* status);
43 
53 HAL_SerialPortHandle HAL_InitializeSerialPortDirect(HAL_SerialPort port,
54  const char* portName,
55  int32_t* status);
56 
63 int HAL_GetSerialFD(HAL_SerialPortHandle handle, int32_t* status);
64 
73 void HAL_SetSerialBaudRate(HAL_SerialPortHandle handle, int32_t baud,
74  int32_t* status);
75 
84 void HAL_SetSerialDataBits(HAL_SerialPortHandle handle, int32_t bits,
85  int32_t* status);
86 
100 void HAL_SetSerialParity(HAL_SerialPortHandle handle, int32_t parity,
101  int32_t* status);
102 
114 void HAL_SetSerialStopBits(HAL_SerialPortHandle handle, int32_t stopBits,
115  int32_t* status);
116 
127 void HAL_SetSerialWriteMode(HAL_SerialPortHandle handle, int32_t mode,
128  int32_t* status);
129 
142 void HAL_SetSerialFlowControl(HAL_SerialPortHandle handle, int32_t flow,
143  int32_t* status);
144 
151 void HAL_SetSerialTimeout(HAL_SerialPortHandle handle, double timeout,
152  int32_t* status);
153 
162 void HAL_EnableSerialTermination(HAL_SerialPortHandle handle, char terminator,
163  int32_t* status);
164 
170 void HAL_DisableSerialTermination(HAL_SerialPortHandle handle, int32_t* status);
171 
178 void HAL_SetSerialReadBufferSize(HAL_SerialPortHandle handle, int32_t size,
179  int32_t* status);
180 
187 void HAL_SetSerialWriteBufferSize(HAL_SerialPortHandle handle, int32_t size,
188  int32_t* status);
189 
196 int32_t HAL_GetSerialBytesReceived(HAL_SerialPortHandle handle,
197  int32_t* status);
198 
209 int32_t HAL_ReadSerial(HAL_SerialPortHandle handle, char* buffer, int32_t count,
210  int32_t* status);
211 
220 int32_t HAL_WriteSerial(HAL_SerialPortHandle handle, const char* buffer,
221  int32_t count, int32_t* status);
222 
228 void HAL_FlushSerial(HAL_SerialPortHandle handle, int32_t* status);
229 
235 void HAL_ClearSerial(HAL_SerialPortHandle handle, int32_t* status);
236 
242 void HAL_CloseSerial(HAL_SerialPortHandle handle, int32_t* status);
243 #ifdef __cplusplus
244 } // extern "C"
245 #endif
246 
HAL_EnableSerialTermination
void HAL_EnableSerialTermination(HAL_SerialPortHandle handle, char terminator, int32_t *status)
Sets the termination character that terminates a read.
HAL_SetSerialTimeout
void HAL_SetSerialTimeout(HAL_SerialPortHandle handle, double timeout, int32_t *status)
Sets the minimum serial read timeout of a port.
HAL_SetSerialWriteMode
void HAL_SetSerialWriteMode(HAL_SerialPortHandle handle, int32_t mode, int32_t *status)
Sets the write mode on a serial port.
HAL_CloseSerial
void HAL_CloseSerial(HAL_SerialPortHandle handle, int32_t *status)
Closes a serial port.
HAL_SetSerialParity
void HAL_SetSerialParity(HAL_SerialPortHandle handle, int32_t parity, int32_t *status)
Sets the number of parity bits on a serial port.
HAL_SetSerialWriteBufferSize
void HAL_SetSerialWriteBufferSize(HAL_SerialPortHandle handle, int32_t size, int32_t *status)
Sets the size of the write buffer.
HAL_SetSerialBaudRate
void HAL_SetSerialBaudRate(HAL_SerialPortHandle handle, int32_t baud, int32_t *status)
Sets the baud rate of a serial port.
HAL_ClearSerial
void HAL_ClearSerial(HAL_SerialPortHandle handle, int32_t *status)
Clears the receive buffer of the serial port.
HAL_ReadSerial
int32_t HAL_ReadSerial(HAL_SerialPortHandle handle, char *buffer, int32_t count, int32_t *status)
Reads data from the serial port.
HAL_InitializeSerialPortDirect
HAL_SerialPortHandle HAL_InitializeSerialPortDirect(HAL_SerialPort port, const char *portName, int32_t *status)
Initializes a serial port with a direct name.
HAL_SetSerialDataBits
void HAL_SetSerialDataBits(HAL_SerialPortHandle handle, int32_t bits, int32_t *status)
Sets the number of data bits on a serial port.
HAL_DisableSerialTermination
void HAL_DisableSerialTermination(HAL_SerialPortHandle handle, int32_t *status)
Disables a termination character for reads.
HAL_SetSerialReadBufferSize
void HAL_SetSerialReadBufferSize(HAL_SerialPortHandle handle, int32_t size, int32_t *status)
Sets the size of the read buffer.
HAL_SetSerialFlowControl
void HAL_SetSerialFlowControl(HAL_SerialPortHandle handle, int32_t flow, int32_t *status)
Sets the flow control mode of a serial port.
HAL_InitializeSerialPort
HAL_SerialPortHandle HAL_InitializeSerialPort(HAL_SerialPort port, int32_t *status)
Initializes a serial port.
HAL_GetSerialFD
int HAL_GetSerialFD(HAL_SerialPortHandle handle, int32_t *status)
Gets the raw serial port file descriptor from a handle.
HAL_WriteSerial
int32_t HAL_WriteSerial(HAL_SerialPortHandle handle, const char *buffer, int32_t count, int32_t *status)
Writes data to the serial port.
HAL_SetSerialStopBits
void HAL_SetSerialStopBits(HAL_SerialPortHandle handle, int32_t stopBits, int32_t *status)
Sets the number of stop bits on a serial port.
HAL_FlushSerial
void HAL_FlushSerial(HAL_SerialPortHandle handle, int32_t *status)
Flushes the serial write buffer out to the port.
HAL_GetSerialBytesReceived
int32_t HAL_GetSerialBytesReceived(HAL_SerialPortHandle handle, int32_t *status)
Gets the number of bytes currently in the read buffer.