![]() |
VectorNav C++ Library
|
Represents a cross-platform serial port. More...
#include <serialport.h>
Public Types | |
enum | StopBits { ONE_STOP_BIT, TWO_STOP_BITS } |
![]() | |
typedef void(* | DataReceivedHandler) (void *userData) |
Callback handler signature that can receive notification when new data has been received on the port. More... | |
Public Member Functions | |
SerialPort (const std::string &portName, uint32_t baudrate) | |
Creates a new SerialPort with the provided connection parameters. More... | |
virtual void | open () |
Opens the simple port. | |
virtual void | close () |
Closes the simple port. | |
virtual bool | isOpen () |
Indicates if the simple port is open. More... | |
virtual void | write (const char data[], size_t length) |
Writes out data to the simple port. More... | |
virtual void | read (char dataBuffer[], size_t numOfBytesToRead, size_t &numOfBytesActuallyRead) |
Allows reading data from the simple port. More... | |
virtual void | registerDataReceivedHandler (void *userData, DataReceivedHandler handler) |
Registers a callback method for notification when new data is received on the port. More... | |
virtual void | unregisterDataReceivedHandler () |
Unregisters the registered callback method. | |
uint32_t | baudrate () |
Returns the baudrate connected at. More... | |
std::string | port () |
Returns the port connected to. More... | |
void | changeBaudrate (uint32_t br) |
Changes the connected baudrate of the port. More... | |
StopBits | stopBits () |
Returns the stop bit configuration. More... | |
void | setStopBits (StopBits stopBits) |
Sets the stop bit configuration. More... | |
size_t | NumberOfReceiveDataDroppedSections () |
Indicates if the platforms supports event notifications. More... | |
Static Public Member Functions | |
static std::vector< std::string > | getPortNames () |
Returns a list of the names of all the available serial ports on the system. More... | |
static bool | determineIfPortIsOptimized (std::string portName) |
With regard to optimizing COM ports provided by FTDI drivers, this method will check if the COM port has been optimized. More... | |
static void | optimizePort (std::string portName) |
This will perform optimization of FTDI USB serial ports. More... | |
Represents a cross-platform serial port.
When the SerialPort if first created and the connection opened, the user will normally have to poll the method read to see if any new data is available on the serial port. However, if the user code registers a handler with the method registerDataReceivedHandler, the SerialPort object will start an internal thread that monitors the serial port for new data, and when new data is available, it will alert the user code through the callback handler. Then the user can call read to retrieve the data.
vn::xplat::SerialPort::SerialPort | ( | const std::string & | portName, |
uint32_t | baudrate | ||
) |
Creates a new SerialPort with the provided connection parameters.
[in] | portName | The name of the serial port. |
[in] | baudrate | The baudrate to open the serial port at. |
uint32_t vn::xplat::SerialPort::baudrate | ( | ) |
Returns the baudrate connected at.
void vn::xplat::SerialPort::changeBaudrate | ( | uint32_t | br | ) |
Changes the connected baudrate of the port.
[in] | br | The baudrate to change the port to. |
|
static |
With regard to optimizing COM ports provided by FTDI drivers, this method will check if the COM port has been optimized.
[in] | portName | The COM port name to check. |
true
if the COM port is optimized; otherwise false
.
|
static |
Returns a list of the names of all the available serial ports on the system.
|
virtual |
Indicates if the simple port is open.
true
if the serial port is open; otherwise false
. Implements vn::xplat::IPort.
size_t vn::xplat::SerialPort::NumberOfReceiveDataDroppedSections | ( | ) |
Indicates if the platforms supports event notifications.
Returns the number of dropped sections of received data.
|
static |
This will perform optimization of FTDI USB serial ports.
If calling this method on Windows, the process must have administrator privileges to write settings to the registry. Otherwise an
[in] | portName | The FTDI USB Serial Port to optimize. |
std::string vn::xplat::SerialPort::port | ( | ) |
Returns the port connected to.
|
virtual |
Allows reading data from the simple port.
[out] | dataBuffer | The data buffer to write the read data bytes to. |
[in] | numOfBytesToRead | The number of bytes to attempt reading from the simple port. |
[out] | numOfBytesActuallyRead | The number of bytes actually read from the simple port. |
Implements vn::xplat::IPort.
|
virtual |
Registers a callback method for notification when new data is received on the port.
[in] | userData | Pointer to user data, which will be provided to the callback method. |
[in] | handler | The callback method. |
Implements vn::xplat::IPort.
void vn::xplat::SerialPort::setStopBits | ( | StopBits | stopBits | ) |
Sets the stop bit configuration.
[in] | stopBits | The stop bit configuration. |
StopBits vn::xplat::SerialPort::stopBits | ( | ) |
Returns the stop bit configuration.
|
virtual |
Writes out data to the simple port.
[in] | data | The data array to write out. |
[in] | length | The length of the data array to write out. |
Implements vn::xplat::IPort.