WPILibC++
2018.4.1-20180820040250-1165-g0b8f4b5
|
Driver for the RS-232 serial port on the roboRIO. More...
#include <SerialPort.h>
Public Member Functions | |
SerialPort (int baudRate, Port port=kOnboard, int dataBits=8, Parity parity=kParity_None, StopBits stopBits=kStopBits_One) | |
Create an instance of a Serial Port class. More... | |
SerialPort (int baudRate, const wpi::Twine &portName, Port port=kOnboard, int dataBits=8, Parity parity=kParity_None, StopBits stopBits=kStopBits_One) | |
Create an instance of a Serial Port class. More... | |
SerialPort (const SerialPort &)=delete | |
SerialPort & | operator= (const SerialPort &)=delete |
void | SetFlowControl (FlowControl flowControl) |
Set the type of flow control to enable on this port. More... | |
void | EnableTermination (char terminator= '\n') |
Enable termination and specify the termination character. More... | |
void | DisableTermination () |
Disable termination behavior. | |
int | GetBytesReceived () |
Get the number of bytes currently available to read from the serial port. More... | |
int | Read (char *buffer, int count) |
Read raw bytes out of the buffer. More... | |
int | Write (const char *buffer, int count) |
Write raw bytes to the buffer. More... | |
int | Write (wpi::StringRef buffer) |
Write raw bytes to the buffer. More... | |
void | SetTimeout (double timeout) |
Configure the timeout of the serial port. More... | |
void | SetReadBufferSize (int size) |
Specify the size of the input buffer. More... | |
void | SetWriteBufferSize (int size) |
Specify the size of the output buffer. More... | |
void | SetWriteBufferMode (WriteBufferMode mode) |
Specify the flushing behavior of the output buffer. More... | |
void | Flush () |
Force the output buffer to be written to the port. More... | |
void | Reset () |
Reset the serial port driver to a known state. More... | |
![]() | |
ErrorBase (const ErrorBase &)=delete | |
ErrorBase & | operator= (const ErrorBase &)=delete |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () const |
Retrieve the current error. More... | |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual void | SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (const ErrorBase &rhs) const |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Additional Inherited Members | |
![]() | |
static void | SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
static void | SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
static const Error & | GetGlobalError () |
Retrieve the current global error. | |
![]() | |
Error | m_error |
Driver for the RS-232 serial port on the roboRIO.
The current implementation uses the VISA formatted I/O mode. This means that all traffic goes through the fomatted buffers. This allows the intermingled use of Printf(), Scanf(), and the raw buffer accessors Read() and Write().
More information can be found in the NI-VISA User Manual here: http://www.ni.com/pdf/manuals/370423a.pdf and the NI-VISA Programmer's Reference Manual here: http://www.ni.com/pdf/manuals/370132c.pdf
frc::SerialPort::SerialPort | ( | int | baudRate, |
Port | port = kOnboard , |
||
int | dataBits = 8 , |
||
Parity | parity = kParity_None , |
||
StopBits | stopBits = kStopBits_One |
||
) |
Create an instance of a Serial Port class.
baudRate | The baud rate to configure the serial port. |
port | The physical port to use |
dataBits | The number of data bits per transfer. Valid values are between 5 and 8 bits. |
parity | Select the type of parity checking to use. |
stopBits | The number of stop bits to use as defined by the enum StopBits. |
frc::SerialPort::SerialPort | ( | int | baudRate, |
const wpi::Twine & | portName, | ||
Port | port = kOnboard , |
||
int | dataBits = 8 , |
||
Parity | parity = kParity_None , |
||
StopBits | stopBits = kStopBits_One |
||
) |
Create an instance of a Serial Port class.
baudRate | The baud rate to configure the serial port. |
port | The physical port to use |
portName | The direct port name to use |
dataBits | The number of data bits per transfer. Valid values are between 5 and 8 bits. |
parity | Select the type of parity checking to use. |
stopBits | The number of stop bits to use as defined by the enum StopBits. |
void frc::SerialPort::EnableTermination | ( | char | terminator = '\n' | ) |
Enable termination and specify the termination character.
Termination is currently only implemented for receive. When the the terminator is recieved, the Read() or Scanf() will return fewer bytes than requested, stopping after the terminator.
terminator | The character to use for termination. |
void frc::SerialPort::Flush | ( | ) |
Force the output buffer to be written to the port.
This is used when SetWriteBufferMode() is set to kFlushWhenFull to force a flush before the buffer is full.
int frc::SerialPort::GetBytesReceived | ( | ) |
Get the number of bytes currently available to read from the serial port.
int frc::SerialPort::Read | ( | char * | buffer, |
int | count | ||
) |
Read raw bytes out of the buffer.
buffer | Pointer to the buffer to store the bytes in. |
count | The maximum number of bytes to read. |
void frc::SerialPort::Reset | ( | ) |
Reset the serial port driver to a known state.
Empty the transmit and receive buffers in the device and formatted I/O.
void frc::SerialPort::SetFlowControl | ( | FlowControl | flowControl | ) |
Set the type of flow control to enable on this port.
By default, flow control is disabled.
void frc::SerialPort::SetReadBufferSize | ( | int | size | ) |
Specify the size of the input buffer.
Specify the amount of data that can be stored before data from the device is returned to Read or Scanf. If you want data that is recieved to be returned immediately, set this to 1.
It the buffer is not filled before the read timeout expires, all data that has been received so far will be returned.
size | The read buffer size. |
void frc::SerialPort::SetTimeout | ( | double | timeout | ) |
Configure the timeout of the serial port.
This defines the timeout for transactions with the hardware. It will affect reads and very large writes.
timeout | The number of seconds to to wait for I/O. |
void frc::SerialPort::SetWriteBufferMode | ( | WriteBufferMode | mode | ) |
Specify the flushing behavior of the output buffer.
When set to kFlushOnAccess, data is synchronously written to the serial port after each call to either Printf() or Write().
When set to kFlushWhenFull, data will only be written to the serial port when the buffer is full or when Flush() is called.
mode | The write buffer mode. |
void frc::SerialPort::SetWriteBufferSize | ( | int | size | ) |
Specify the size of the output buffer.
Specify the amount of data that can be stored before being transmitted to the device.
size | The write buffer size. |
int frc::SerialPort::Write | ( | const char * | buffer, |
int | count | ||
) |
Write raw bytes to the buffer.
buffer | Pointer to the buffer to read the bytes from. |
count | The maximum number of bytes to write. |
int frc::SerialPort::Write | ( | wpi::StringRef | buffer | ) |
Write raw bytes to the buffer.
Use Write({data, len}) to get a buffer that is shorter than the length of the string.
buffer | StringRef to the buffer to read the bytes from. |