Chris@16
|
1 //
|
Chris@16
|
2 // serial_port_base.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
|
Chris@16
|
7 //
|
Chris@16
|
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ASIO_SERIAL_PORT_BASE_HPP
|
Chris@16
|
13 #define BOOST_ASIO_SERIAL_PORT_BASE_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
16 # pragma once
|
Chris@16
|
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
|
Chris@16
|
22 || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
23
|
Chris@16
|
24 #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
|
Chris@16
|
25 # include <termios.h>
|
Chris@16
|
26 #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
|
Chris@16
|
27
|
Chris@16
|
28 #include <boost/asio/detail/socket_types.hpp>
|
Chris@16
|
29 #include <boost/system/error_code.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
32 # define BOOST_ASIO_OPTION_STORAGE implementation_defined
|
Chris@16
|
33 #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
|
Chris@16
|
34 # define BOOST_ASIO_OPTION_STORAGE DCB
|
Chris@16
|
35 #else
|
Chris@16
|
36 # define BOOST_ASIO_OPTION_STORAGE termios
|
Chris@16
|
37 #endif
|
Chris@16
|
38
|
Chris@16
|
39 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
40
|
Chris@16
|
41 namespace boost {
|
Chris@16
|
42 namespace asio {
|
Chris@16
|
43
|
Chris@16
|
44 /// The serial_port_base class is used as a base for the basic_serial_port class
|
Chris@16
|
45 /// template so that we have a common place to define the serial port options.
|
Chris@16
|
46 class serial_port_base
|
Chris@16
|
47 {
|
Chris@16
|
48 public:
|
Chris@16
|
49 /// Serial port option to permit changing the baud rate.
|
Chris@16
|
50 /**
|
Chris@16
|
51 * Implements changing the baud rate for a given serial port.
|
Chris@16
|
52 */
|
Chris@16
|
53 class baud_rate
|
Chris@16
|
54 {
|
Chris@16
|
55 public:
|
Chris@16
|
56 explicit baud_rate(unsigned int rate = 0);
|
Chris@16
|
57 unsigned int value() const;
|
Chris@16
|
58 BOOST_ASIO_DECL boost::system::error_code store(
|
Chris@16
|
59 BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
60 boost::system::error_code& ec) const;
|
Chris@16
|
61 BOOST_ASIO_DECL boost::system::error_code load(
|
Chris@16
|
62 const BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
63 boost::system::error_code& ec);
|
Chris@16
|
64 private:
|
Chris@16
|
65 unsigned int value_;
|
Chris@16
|
66 };
|
Chris@16
|
67
|
Chris@16
|
68 /// Serial port option to permit changing the flow control.
|
Chris@16
|
69 /**
|
Chris@16
|
70 * Implements changing the flow control for a given serial port.
|
Chris@16
|
71 */
|
Chris@16
|
72 class flow_control
|
Chris@16
|
73 {
|
Chris@16
|
74 public:
|
Chris@16
|
75 enum type { none, software, hardware };
|
Chris@16
|
76 BOOST_ASIO_DECL explicit flow_control(type t = none);
|
Chris@16
|
77 type value() const;
|
Chris@16
|
78 BOOST_ASIO_DECL boost::system::error_code store(
|
Chris@16
|
79 BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
80 boost::system::error_code& ec) const;
|
Chris@16
|
81 BOOST_ASIO_DECL boost::system::error_code load(
|
Chris@16
|
82 const BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
83 boost::system::error_code& ec);
|
Chris@16
|
84 private:
|
Chris@16
|
85 type value_;
|
Chris@16
|
86 };
|
Chris@16
|
87
|
Chris@16
|
88 /// Serial port option to permit changing the parity.
|
Chris@16
|
89 /**
|
Chris@16
|
90 * Implements changing the parity for a given serial port.
|
Chris@16
|
91 */
|
Chris@16
|
92 class parity
|
Chris@16
|
93 {
|
Chris@16
|
94 public:
|
Chris@16
|
95 enum type { none, odd, even };
|
Chris@16
|
96 BOOST_ASIO_DECL explicit parity(type t = none);
|
Chris@16
|
97 type value() const;
|
Chris@16
|
98 BOOST_ASIO_DECL boost::system::error_code store(
|
Chris@16
|
99 BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
100 boost::system::error_code& ec) const;
|
Chris@16
|
101 BOOST_ASIO_DECL boost::system::error_code load(
|
Chris@16
|
102 const BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
103 boost::system::error_code& ec);
|
Chris@16
|
104 private:
|
Chris@16
|
105 type value_;
|
Chris@16
|
106 };
|
Chris@16
|
107
|
Chris@16
|
108 /// Serial port option to permit changing the number of stop bits.
|
Chris@16
|
109 /**
|
Chris@16
|
110 * Implements changing the number of stop bits for a given serial port.
|
Chris@16
|
111 */
|
Chris@16
|
112 class stop_bits
|
Chris@16
|
113 {
|
Chris@16
|
114 public:
|
Chris@16
|
115 enum type { one, onepointfive, two };
|
Chris@16
|
116 BOOST_ASIO_DECL explicit stop_bits(type t = one);
|
Chris@16
|
117 type value() const;
|
Chris@16
|
118 BOOST_ASIO_DECL boost::system::error_code store(
|
Chris@16
|
119 BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
120 boost::system::error_code& ec) const;
|
Chris@16
|
121 BOOST_ASIO_DECL boost::system::error_code load(
|
Chris@16
|
122 const BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
123 boost::system::error_code& ec);
|
Chris@16
|
124 private:
|
Chris@16
|
125 type value_;
|
Chris@16
|
126 };
|
Chris@16
|
127
|
Chris@16
|
128 /// Serial port option to permit changing the character size.
|
Chris@16
|
129 /**
|
Chris@16
|
130 * Implements changing the character size for a given serial port.
|
Chris@16
|
131 */
|
Chris@16
|
132 class character_size
|
Chris@16
|
133 {
|
Chris@16
|
134 public:
|
Chris@16
|
135 BOOST_ASIO_DECL explicit character_size(unsigned int t = 8);
|
Chris@16
|
136 unsigned int value() const;
|
Chris@16
|
137 BOOST_ASIO_DECL boost::system::error_code store(
|
Chris@16
|
138 BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
139 boost::system::error_code& ec) const;
|
Chris@16
|
140 BOOST_ASIO_DECL boost::system::error_code load(
|
Chris@16
|
141 const BOOST_ASIO_OPTION_STORAGE& storage,
|
Chris@16
|
142 boost::system::error_code& ec);
|
Chris@16
|
143 private:
|
Chris@16
|
144 unsigned int value_;
|
Chris@16
|
145 };
|
Chris@16
|
146
|
Chris@16
|
147 protected:
|
Chris@16
|
148 /// Protected destructor to prevent deletion through this type.
|
Chris@16
|
149 ~serial_port_base()
|
Chris@16
|
150 {
|
Chris@16
|
151 }
|
Chris@16
|
152 };
|
Chris@16
|
153
|
Chris@16
|
154 } // namespace asio
|
Chris@16
|
155 } // namespace boost
|
Chris@16
|
156
|
Chris@16
|
157 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
158
|
Chris@16
|
159 #undef BOOST_ASIO_OPTION_STORAGE
|
Chris@16
|
160
|
Chris@16
|
161 #include <boost/asio/impl/serial_port_base.hpp>
|
Chris@16
|
162 #if defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
163 # include <boost/asio/impl/serial_port_base.ipp>
|
Chris@16
|
164 #endif // defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
165
|
Chris@16
|
166 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
|
Chris@16
|
167 // || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
168
|
Chris@16
|
169 #endif // BOOST_ASIO_SERIAL_PORT_BASE_HPP
|