Serial Scol plugin
BufferedAsyncSerial.h
1/*
2 * File: BufferedAsyncSerial.h
3 * Author: Terraneo Federico
4 * Distributed under the Boost Software License, Version 1.0.
5 * Created on January 6, 2011, 3:31 PM
6 */
7
8#ifndef BUFFEREDASYNCSERIAL_H
9#define BUFFEREDASYNCSERIAL_H
10
11#ifndef ANDROID
12#include "AsyncSerial.h"
13
15{
16public:
18
30 BufferedAsyncSerial(const std::string& devname, unsigned int baud_rate,
31 boost::asio::serial_port_base::parity opt_parity =
32 boost::asio::serial_port_base::parity(
33 boost::asio::serial_port_base::parity::none),
34 boost::asio::serial_port_base::character_size opt_csize =
35 boost::asio::serial_port_base::character_size(8),
36 boost::asio::serial_port_base::flow_control opt_flow =
37 boost::asio::serial_port_base::flow_control(
38 boost::asio::serial_port_base::flow_control::none),
39 boost::asio::serial_port_base::stop_bits opt_stop =
40 boost::asio::serial_port_base::stop_bits(
41 boost::asio::serial_port_base::stop_bits::one));
42
49 size_t read(char *data, size_t size);
50
55 std::vector<char> read();
56
64 std::string readString();
65
75 std::string readStringUntil(const std::string delim = "\n");
76
78
79private:
80
84 void readCallback(const char *data, size_t len);
85
93 static std::vector<char>::iterator findStringInVector(std::vector<char>& v,
94 const std::string& s);
95
96 std::vector<char> readQueue;
97 boost::mutex readQueueMutex;
98};
99
100#else //Android
101#include <boost/thread.hpp>
102
104{
105public:
107
119 BufferedAsyncSerial(const std::string& devname);
120
122
123 void writeString(const std::string& s);
124
125 bool connect();
126 void disconnect();
127
128 void cbThread();
129private:
130 std::string mPort;
131 bool mConnected;
132 bool mEnable;
133 boost::thread mThread;
134
135 void readData();
136};
137#endif
138
139#endif //BUFFEREDASYNCSERIAL_H
void writeString(const std::string &s)
std::string readStringUntil(const std::string delim="\n")
BufferedAsyncSerial(const std::string &devname, unsigned int baud_rate, boost::asio::serial_port_base::parity opt_parity=boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none), boost::asio::serial_port_base::character_size opt_csize=boost::asio::serial_port_base::character_size(8), boost::asio::serial_port_base::flow_control opt_flow=boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none), boost::asio::serial_port_base::stop_bits opt_stop=boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one))
std::vector< char > read()