22#include "vrpn_Configure.h"
36 typedef int file_handle_type;
41 vrpn_SER_PARITY parity = vrpn_SER_PARITY_NONE);
54 void open(
const char *portname,
long baud,
int charsize = 8,
55 vrpn_SER_PARITY parity = vrpn_SER_PARITY_NONE);
67 int write(std::string
const &buffer);
68 int write(
const unsigned char *buffer,
int bytes);
76 int read_available_characters(
unsigned char *buffer,
int count);
85 struct timeval &timeout);
118 void assign_rts(
bool set);
135 void requiresOpen()
const;
141 file_handle_type _comm;
147 : std::logic_error(
"Tried to open a serial port that was already open.")
154 : std::logic_error(
"Tried to use a serial port that was not yet open.")
161 : std::runtime_error(
162 "Received an error when trying to open serial port.")
169 : std::runtime_error(
170 "Received an error when trying to close serial port.")
177 : std::runtime_error(
"Failed to modify serial port RTS status.")
184 : std::runtime_error(
"Failure on serial port read.")
191 : std::runtime_error(
"Failure on serial port write.")
198 : std::runtime_error(
"Failure on serial port flush.")
205 : std::runtime_error(
"Failure on serial port drain.")
210inline bool vrpn_SerialPort::is_open()
const {
return _comm != -1; }
212inline void vrpn_SerialPort::assign_rts(
bool set)
222inline void vrpn_SerialPort::requiresOpen()
const
A simple class wrapping the functionality of vrpn_Serial.h with RAII, object-orientation,...
定义 vrpn_SerialPort.h:34
int read_available_characters(unsigned char *buffer, int count, struct timeval &timeout)
Read available characters from input buffer, and wait up to the indicated timeout for those remaining...
void flush_output_buffer()
Throw out any characters (do not send) within the output buffer.
void drain_output_buffer()
Wait until all of the characters in the output buffer are sent, then return.
~vrpn_SerialPort()
Destructor - closes port if open.
void close()
Close the serial port.
void flush_input_buffer()
Throw out any characters within the input buffer.
std::string read_available_characters(int count, struct timeval &timeout)
Read available characters from input buffer, and wait up to the indicated timeout for those remaining...
std::string read_available_characters(int count=-1)
Read available characters from input buffer, up to indicated count (or -1 for no limit)
vrpn_SerialPort(const char *portname, long baud, int charsize=8, vrpn_SER_PARITY parity=vrpn_SER_PARITY_NONE)
Construct and open port
vrpn_SerialPort()
Construct without opening
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...