Connection
Connection

The Connection object that is used for communication.

Serial
static Connection Serial(
const std::string &port,
uint32 baudRate 921600
)

A static function for creating a Connection object with a <SerialConnection> implementation.  A connection with the specified port will be established.

Parameters
port
const std::string&

The actual string name of the COM port (ex. "COM26")

baudRate
uint32

The baud rate at which to open the COM port (default of 921600)

Returns

A Connection object created with a <SerialConnection> implementation.

Exceptions
TcpIp
static Connection TcpIp(
const std::string &serverAddress,
uint16 serverPort
)

A static function for creating a Connection object with a <TcpIpConnection> implementation.  A connection with the specified address/port will be established.

Parameters
serverAddress
const std::string&

The server address (domain name or ip address) to connect to.

serverPort
uint16

The server port to connect to.

Returns

A Connection object created with a <TcpIpConnection> implementation.

Exceptions
UnixSocket
static Connection UnixSocket(
const std::string &path
)

A generator function for Connection objects with a <UnixSocketConnection> implementation (Unix builds only).  A connection with the specified path will be established.

Parameters
path
const std::string&

The a path to the unix socket

Returns

The generated Connection object.

Exceptions
description
std::string description()

Gets a description of the connection as a string.

Returns

A description of the connection.

disconnect
void disconnect()

Closes the current connection.

reconnect
void reconnect()

Reopens a connection that has been disconnected.

Exceptions
Error_InvalidSerialPort

the specified com port is invalid.

Error_InvalidTcpServer

the specified server address and/or server port is invalid.

Error_InvalidUnixSocket

failed to connect to the specified unix socket path.

Error_Connection

failed to get or set com port parameters

write
void write(
const Bytes &bytes
)

Writes the given bytes to the connection.

Parameters
bytes
const Bytes&

The bytes to write.

Exceptions
writeStr
void writeStr(
const std::string &bytes
)

Writes the given string (containing bytes) to the connection.

Parameters
bytes
const std::string&

The string of bytes to write.

Exceptions
rawByteMode
void rawByteMode(
bool enable
)

Puts the connection into "Raw Byte Mode."  "Raw Byte Mode" stops the data from being sent/parsed from any attached devices (BaseStation, InertialNode, etc.)  and instead sends all data into a raw circular data buffer that can be accessed by calling getRawBytes on this Connection object.  Disabling this mode will start sending all data back to the previous attached device, if still available.

Parameters
enable
bool

whether to enable raw byte mode (true), or disable raw byte mode (false).

Exceptions
getRawBytes
Bytes getRawBytes(
uint32 timeout 0,
uint32 maxBytes 0
)

Gets the raw bytes that are available that have been collected when the Connection is in "Raw Byte Mode."  If the Connection has not been put into "Raw Byte Mode" by calling rawByteMode, no data can be retrieved from this function.

Parameters
timeout
uint32

the timeout, in milliseconds, to wait for the data if necessary (default of 0).

maxBytes
uint32

The maximum number of bytes to return. If this is 0 (default), all bytes will be returned.

Returns

A Bytes vector containing all of the raw bytes that are available.

Exceptions
getRawBytesStr
std::string getRawBytesStr(
uint32 timeout 0,
uint32 maxBytes 0
)

Gets the raw bytes that are available that have been collected when the Connection is in "Raw Byte Mode" as a string.  If the Connection has not been put into "Raw Byte Mode" by calling rawByteMode, no data can be retrieved from this function.

Parameters
timeout
uint32

the timeout, in milliseconds, to wait for the data if necessary (default of 0).

maxBytes
uint32

The maximum number of bytes to return. If this is 0 (default), all bytes will be returned.

Returns

A string containing all of the raw bytes that are available.

Exceptions