AsyncSerial.h
Go to the documentation of this file.
1 /*
2  * File: AsyncSerial.h
3  * Author: Terraneo Federico
4  * Distributed under the Boost Software License, Version 1.0.
5  * Created on September 7, 2009, 10:46 AM
6  */
7 
8 #ifndef ASYNCSERIAL_H
9 #define ASYNCSERIAL_H
10 
11 #include <vector>
12 #include <boost/asio.hpp>
13 #include <boost/bind.hpp>
14 #include <boost/thread.hpp>
15 #include <boost/utility.hpp>
16 #include <boost/function.hpp>
17 #include <boost/shared_array.hpp>
18 
22 class AsyncSerialImpl;
23 
28 class AsyncSerial : private boost::noncopyable
29 {
30 public:
31  AsyncSerial();
32 
45  const std::string& devname, unsigned int baud_rate,
46  boost::asio::serial_port_base::parity opt_parity =
47  boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none),
48  boost::asio::serial_port_base::character_size opt_csize = boost::asio::serial_port_base::character_size(8),
49  boost::asio::serial_port_base::flow_control opt_flow =
50  boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none),
51  boost::asio::serial_port_base::stop_bits opt_stop =
52  boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));
53 
65  void open(const std::string& devname, unsigned int baud_rate,
66  boost::asio::serial_port_base::parity opt_parity =
67  boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none),
68  boost::asio::serial_port_base::character_size opt_csize = boost::asio::serial_port_base::character_size(8),
69  boost::asio::serial_port_base::flow_control opt_flow =
70  boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none),
71  boost::asio::serial_port_base::stop_bits opt_stop =
72  boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));
73 
77  bool isOpen() const;
78 
82  bool errorStatus() const;
83 
88  void close();
89 
95  void write(const char* data, size_t size);
96 
101  void write(const std::vector<char>& data);
102 
109  void writeString(const std::string& s);
110 
111  virtual ~AsyncSerial() = 0;
112 
116  static const int readBufferSize = 1024;
117 
118 private:
123  void doRead();
124 
129  void readEnd(const boost::system::error_code& error, size_t bytes_transferred);
130 
136  void doWrite();
137 
143  void writeEnd(const boost::system::error_code& error);
144 
148  void doClose();
149 
151 
152 protected:
157  void setErrorStatus(bool e);
158 
162  void setReadCallback(const boost::function<void(const char*, size_t)>& callback);
163 
169  void clearReadCallback();
170 };
171 
178 {
179 public:
181 
194  const std::string& devname, unsigned int baud_rate,
195  boost::asio::serial_port_base::parity opt_parity =
196  boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none),
197  boost::asio::serial_port_base::character_size opt_csize = boost::asio::serial_port_base::character_size(8),
198  boost::asio::serial_port_base::flow_control opt_flow =
199  boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none),
200  boost::asio::serial_port_base::stop_bits opt_stop =
201  boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));
202 
209  void setCallback(const boost::function<void(const char*, size_t)>& callback);
210 
215  void clearCallback();
216 
217  virtual ~CallbackAsyncSerial();
218 };
219 
220 #endif // ASYNCSERIAL_H
bool errorStatus() const
void writeString(const std::string &s)
XmlRpcServer s
void doClose()
static const int readBufferSize
Definition: AsyncSerial.h:116
void setErrorStatus(bool e)
virtual ~AsyncSerial()=0
void writeEnd(const boost::system::error_code &error)
void setReadCallback(const boost::function< void(const char *, size_t)> &callback)
void open(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))
Definition: AsyncSerial.cpp:84
void write(const char *data, size_t size)
void readEnd(const boost::system::error_code &error, size_t bytes_transferred)
void clearReadCallback()
bool isOpen() const
void doWrite()
boost::shared_ptr< AsyncSerialImpl > pimpl
Definition: AsyncSerial.h:150


xiaoqiang_driver
Author(s): Xie fusheng
autogenerated on Mon Jun 10 2019 15:53:12