43 #include <boost/function.hpp>
44 #include <boost/thread/thread.hpp>
46 #define MAX_LENGTH 128
51 #define DEF_EXCEPTION(name, parent) \
52 class name : public parent { \
54 name(const char* msg) : parent(msg) {} \
86 void open(
const char * port_name,
int baud_rate = 115200);
109 int write(
const char * data,
int length = -1);
121 int read(
char * data,
int max_length,
int timeout = -1);
135 int readBytes(
char * data,
int length,
int timeout = -1);
149 int readLine(
char * data,
int length,
int timeout = -1);
162 bool readLine(std::string * data,
int timeout = -1);
176 bool readBetween(std::string * data,
char start,
char end,
int timeout = -1);
bool startReadBetweenStream(boost::function< void(std::string *)> f, char start, char end)
Start a stream of readBetween()
bool stream_stopped_
Whether streaming is stopped or not.
int baudRate()
Get the current baud rate.
void stopStream()
Stop streaming.
C++ serial port class for ROS.
void readBetweenThread(char start, char end)
Thread for a stream of readBetween()
bool portOpen()
Check whether the port is open or not.
int readBytes(char *data, int length, int timeout=-1)
Read a fixed number of bytes from the serial port.
DEF_EXCEPTION(Exception, std::runtime_error)
A standard exception.
void open(const char *port_name, int baud_rate=115200)
Open the serial port.
int write(const char *data, int length=-1)
Write to the port.
bool readBetween(std::string *data, char start, char end, int timeout=-1)
Read from the serial port between a start char and an end char.
boost::function< void(char *, int)> readCallback
Stream read callback boost function.
bool startReadStream(boost::function< void(char *, int)> f)
Start a stream of read()
void close()
Close the serial port.
int read(char *data, int max_length, int timeout=-1)
Read from the port.
void readThread()
Thread for a stream of read()
bool stream_paused_
Whether streaming is paused or not.
boost::function< void(std::string *)> readLineCallback
Stream readLine callback boost function.
boost::function< void(std::string *)> readBetweenCallback
Stream readBetween callback boost function.
void resumeStream()
Resume streaming.
int flush()
Wrapper around tcflush.
bool startReadLineStream(boost::function< void(std::string *)> f)
Start a stream of readLine(std::string*, int)
void readLineThread()
Thread for a stream of readLine(std::string*, int)
boost::thread * stream_thread_
Stream thread.
int readLine(char *data, int length, int timeout=-1)
Read a line from the serial port.
void pauseStream()
Pause streaming.