Helper class to simplify interfacing with serial port hardware. More...
#include <igvc/SerialPort.h>
Public Member Functions | |
std::string | devicePath () |
Returns the path to the device this port is connected to. More... | |
bool | isOpen () |
Returns true if the serial port is connected and open. More... | |
char | read () |
Reads a single byte from the serial port. More... | |
char * | read (int numBytes) |
Reads numBytes bytes from the serial port. More... | |
std::string | readln () |
Reads bytes from the serial port until or is found. More... | |
SerialPort (std::string device, int baud) | |
The constructor takes in the path to the port (eg. "/dev/ttyUSB0") and a baud rate for the connection and opens the connection. More... | |
void | write (std::string msg) |
Writes the given string to the serial port. More... | |
void | write (char *buffer, int length) |
Writes the given array of chars to the serial port. More... | |
void | write (unsigned char *buffer, int length) |
Writes the given array of unsigned chars to the serial port. More... | |
~SerialPort () | |
Private Attributes | |
boost::asio::io_service | ioservice |
std::string | path |
boost::asio::serial_port | port |
Helper class to simplify interfacing with serial port hardware.
Definition at line 14 of file SerialPort.h.
SerialPort::SerialPort | ( | std::string | device, |
int | baud | ||
) |
The constructor takes in the path to the port (eg. "/dev/ttyUSB0") and a baud rate for the connection and opens the connection.
Definition at line 7 of file SerialPort.cpp.
SerialPort::~SerialPort | ( | ) |
Definition at line 31 of file SerialPort.cpp.
string SerialPort::devicePath | ( | ) |
Returns the path to the device this port is connected to.
Definition at line 98 of file SerialPort.cpp.
bool SerialPort::isOpen | ( | ) |
Returns true if the serial port is connected and open.
Definition at line 36 of file SerialPort.cpp.
char SerialPort::read | ( | ) |
Reads a single byte from the serial port.
Definition at line 58 of file SerialPort.cpp.
char * SerialPort::read | ( | int | numBytes | ) |
Reads numBytes bytes from the serial port.
Definition at line 74 of file SerialPort.cpp.
string SerialPort::readln | ( | ) |
Reads bytes from the serial port until
or is found.
Definition at line 84 of file SerialPort.cpp.
void SerialPort::write | ( | std::string | msg | ) |
Writes the given string to the serial port.
void SerialPort::write | ( | char * | buffer, |
int | length | ||
) |
Writes the given array of chars to the serial port.
Definition at line 47 of file SerialPort.cpp.
void SerialPort::write | ( | unsigned char * | buffer, |
int | length | ||
) |
Writes the given array of unsigned chars to the serial port.
Definition at line 52 of file SerialPort.cpp.
|
private |
Definition at line 55 of file SerialPort.h.
|
private |
Definition at line 57 of file SerialPort.h.
|
private |
Definition at line 56 of file SerialPort.h.