libcommonc++  0.7
SerialPort.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_SerialPort_hxx
24 #define __ccxx_SerialPort_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/Stream.h++>
28 #include <commonc++/String.h++>
29 
30 namespace ccxx {
31 
38 {
39  public:
40 
42  enum BaudRate { BaudOther = -1, Baud300 = 300, Baud600 = 600,
43  Baud1200 = 1200, Baud1800 = 1800, Baud2400 = 2400,
44  Baud4800 = 4800, Baud9600 = 9600, Baud19200 = 19200,
45  Baud38400 = 38400, Baud57600 = 57600,
46  Baud115200 = 115200, Baud230400 = 230400 };
47 
49  enum Parity { ParityOther = -1, ParityNone, ParityOdd, ParityEven,
50  ParityMark, ParitySpace };
51 
53  enum DataBits { DataBitsOther = -1, DataBits5 = 5, DataBits6 = 6,
54  DataBits7 = 7, DataBits8 = 8 };
55 
57  enum StopBits { StopBitsOther = -1, StopBits1 = 1, StopBits2 = 2,
58  StopBits1_5 = 3 };
59 
61  enum FlowControl { FlowOther = -1, FlowOff, FlowHardware, FlowXOnXOff };
62 
70  SerialPort(const String& device);
71 
73  virtual ~SerialPort();
74 
81  virtual void open();
82 
89  void flush();
90 
96  void setTimeout(timespan_ms_t timeout);
97 
105  void setBaudRate(BaudRate baud);
106 
115  BaudRate getBaudRate();
116 
124  void setParity(Parity parity);
125 
134  Parity getParity();
135 
143  void setDataBits(DataBits bits);
144 
153  DataBits getDataBits();
154 
162  void setStopBits(StopBits bits);
163 
172  StopBits getStopBits();
173 
182  void setFlowControl(FlowControl flow);
183 
192  FlowControl getFlowControl();
193 
201  void sendBreak(uint_t duration);
202 
204  inline String getDevice() const
205  { return(_device); }
206 
213  static BaudRate lookupBaudRate(uint_t baudRate);
214 
215  private:
216 
217  String _device;
218 
220 };
221 
222 } // namespace ccxx
223 
224 #endif // __ccxx_SerialPort_hxx
StopBits
Stop bits.
Definition: SerialPort.h++:57
A class representing a serial communications port.
Definition: SerialPort.h++:37
An unbuffered I/O stream.
Definition: Stream.h++:60
BaudRate
Baud rates.
Definition: SerialPort.h++:42
FlowControl
Flow control modes.
Definition: SerialPort.h++:61
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
Parity
Parity types.
Definition: SerialPort.h++:49
DataBits
Data bits per byte.
Definition: SerialPort.h++:53
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
int timespan_ms_t
A timespan expressed in milliseconds.
Definition: Integers.h++:104
String getDevice() const
Get the device for this serial port.
Definition: SerialPort.h++:204
Definition: AllocationMap.c++:25