56 #include <boost/function.hpp>
57 #include <boost/thread/thread.hpp>
59 #define MAX_LENGTH 128
64 #define DEF_EXCEPTION(name, parent) \
65 class name : public parent { \
67 name(const char* msg) : parent(msg) {} \
149 bool config(
int baudrate_,
int databits_,
int startbits_,
int stopbits_,
int parity_,
int NLchar_);
161 void open(
const char * port_name,
int baud_rate = 115200);
184 int write(
const char * data,
int length = -1);
200 int read(
char * data,
int max_length,
int timeout = -1);
214 int readBytes(
char * data,
int length,
int timeout = -1);
228 int readLine(
char * data,
int length,
int timeout = -1);
241 bool readLine(std::string * data,
int timeout = -1);
256 bool readBetween(std::string * data,
char start,
char end,
int timeout = -1);
int baudRate()
Get the current baud rate.
void close()
Close the serial port.
void readThread()
Thread for a stream of read()
bool stream_paused_
Whether streaming is paused or not.
int readBytes(char *data, int length, int timeout=-1)
Read a fixed number of bytes from the serial port.
bool changebaudrate(int baudrate_)
bool writebyte(uint8_t byte)
boost::function< void(std::string *)> readLineCallback
Stream readLine callback boost function.
void readLineThread()
Thread for a stream of readLine(std::string*, int)
bool stream_stopped_
Whether streaming is stopped or not.
bool startReadStream(boost::function< void(char *, int)> f)
Start a stream of read()
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.
int flush()
Wrapper around tcflush.
int readLine(char *data, int length, int timeout=-1)
Read a line from the serial port.
int read(char *data, int max_length, int timeout=-1)
Read from 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.
bool config(int baudrate_, int databits_, int startbits_, int stopbits_, int parity_, int NLchar_)
boost::function< void(char *, int)> readCallback
Stream read callback boost function.
bool portOpen()
Check whether the port is open or not.
DEF_EXCEPTION(Exception, std::runtime_error)
A standard exception.
bool startReadLineStream(boost::function< void(std::string *)> f)
Start a stream of readLine(std::string*, int)
boost::function< void(std::string *)> readBetweenCallback
Stream readBetween callback boost function.
void stopStream()
Stop streaming.
int readbyte(uint8_t *read_byte)
struct termios ComParams newParams
bool startReadBetweenStream(boost::function< void(std::string *)> f, char start, char end)
Start a stream of readBetween()
tcflag_t selectbaud(int baudrate_)
void pauseStream()
Pause streaming.
boost::thread * stream_thread_
Stream thread.
void resumeStream()
Resume streaming.
void readBetweenThread(char start, char end)
Thread for a stream of readBetween()