Async  1.5.0
AsyncSerial.h
Go to the documentation of this file.
1 
35 #ifndef SERIAL_INCLUDED
36 #define SERIAL_INCLUDED
37 
38 
39 /****************************************************************************
40  *
41  * System Includes
42  *
43  ****************************************************************************/
44 
45 #include <sigc++/sigc++.h>
46 #include <termios.h>
47 #include <unistd.h>
48 
49 #include <string>
50 
51 
52 /****************************************************************************
53  *
54  * Project Includes
55  *
56  ****************************************************************************/
57 
58 
59 
60 /****************************************************************************
61  *
62  * Local Includes
63  *
64  ****************************************************************************/
65 
66 
67 
68 /****************************************************************************
69  *
70  * Forward declarations
71  *
72  ****************************************************************************/
73 
74 
75 
76 /****************************************************************************
77  *
78  * Namespace
79  *
80  ****************************************************************************/
81 
82 namespace Async
83 {
84 
85 
86 /****************************************************************************
87  *
88  * Forward declarations of classes inside of the declared namespace
89  *
90  ****************************************************************************/
91 
92 class FdWatch;
93 class SerialDevice;
94 
95 
96 /****************************************************************************
97  *
98  * Defines & typedefs
99  *
100  ****************************************************************************/
101 
102 
103 
104 /****************************************************************************
105  *
106  * Exported Global Variables
107  *
108  ****************************************************************************/
109 
110 
111 
112 /****************************************************************************
113  *
114  * Class definitions
115  *
116  ****************************************************************************/
117 
129 class Serial : public sigc::trackable
130 {
131  public:
135  typedef enum
136  {
140  } Parity;
141 
145  typedef enum
146  {
150  } Flow;
151 
155  typedef enum
156  {
164  } Pin;
165 
169  static const int READ_BUFSIZE = 1024;
170 
171 
181  explicit Serial(const std::string& serial_port);
182 
186  ~Serial(void);
187 
204  bool setParams(int speed, Parity parity, int bits, int stop_bits,
205  Flow flow);
206 
221  bool open(bool flush=false);
222 
234  bool close(void);
235 
244  int write(const char *buf, size_t count)
245  {
246  return ::write(fd, buf, count);
247  }
248 
265  bool setCanonical(bool canonical);
266 
277  bool stopInput(bool stop);
278 
290  bool setPin(Pin pin, bool set);
291 
303  bool getPin(Pin pin, bool &is_set);
304 
315  sigc::signal<void, char*, int> charactersReceived;
316 
317 
318  protected:
319 
320  private:
321  const std::string serial_port;
322  bool canonical;
323 
324  int fd;
325  struct termios port_settings;
326  SerialDevice *dev;
327 
328 
329 }; /* class Serial */
330 
331 
332 } /* namespace */
333 
334 #endif /* SERIAL_INCLUDED */
335 
336 
337 
338 /*
339  * This file has not been truncated
340  */
341 
Use software (XON/XOFF) flow control.
Definition: AsyncSerial.h:149
Parity
A type that defines the possible choices for parity.
Definition: AsyncSerial.h:135
No flow control in use.
Definition: AsyncSerial.h:147
bool setParams(int speed, Parity parity, int bits, int stop_bits, Flow flow)
Setup the serial port communications parameters.
Use hardware flow control.
Definition: AsyncSerial.h:148
bool close(void)
Close a previously opened serial port.
A class for using asyncronous serial communications.
Definition: AsyncSerial.h:129
Pin
A type that defines the read/write pins in the serial port.
Definition: AsyncSerial.h:155
Output: Request To Send.
Definition: AsyncSerial.h:158
Parity not used.
Definition: AsyncSerial.h:137
bool getPin(Pin pin, bool &is_set)
Get the state of one of the input pins in the serial port.
Input: Clear To Send.
Definition: AsyncSerial.h:160
Input: Data Carrier Detect.
Definition: AsyncSerial.h:162
Use odd parity.
Definition: AsyncSerial.h:139
int write(const char *buf, size_t count)
Write data to the serial port.
Definition: AsyncSerial.h:244
bool setPin(Pin pin, bool set)
Set the state of one of the output pins in the serial port.
~Serial(void)
Destructor.
sigc::signal< void, char *, int > charactersReceived
A signal that is emitted when there is data to read.
Definition: AsyncSerial.h:315
Namespace for the asynchronous programming classes.
Input: Data Set Ready.
Definition: AsyncSerial.h:161
Output: Data Terminal Ready.
Definition: AsyncSerial.h:159
bool setCanonical(bool canonical)
Set or clear canonical mode.
static const int READ_BUFSIZE
The maximum number of characters that can be read at once.
Definition: AsyncSerial.h:169
Serial(const std::string &serial_port)
Constuctor.
Use even parity.
Definition: AsyncSerial.h:138
Input: Ring Indicate.
Definition: AsyncSerial.h:163
bool stopInput(bool stop)
Stop/start input of data.
Flow
A type that defines the possible choices for flow control.
Definition: AsyncSerial.h:145
bool open(bool flush=false)
Open the serial port.