Async 1.8.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
82namespace Async
83{
84
85
86/****************************************************************************
87 *
88 * Forward declarations of classes inside of the declared namespace
89 *
90 ****************************************************************************/
91
92class FdWatch;
93class 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
129class Serial : public sigc::trackable
130{
131 public:
141
145 typedef enum
146 {
151
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
A class for using asyncronous serial communications.
bool open(bool flush=false)
Open the serial port.
Flow
A type that defines the possible choices for flow control.
@ FLOW_NONE
No flow control in use.
@ FLOW_HW
Use hardware flow control.
@ FLOW_XONOFF
Use software (XON/XOFF) flow control.
Serial(const std::string &serial_port)
Constuctor.
bool setParams(int speed, Parity parity, int bits, int stop_bits, Flow flow)
Setup the serial port communications parameters.
bool close(void)
Close a previously opened serial port.
sigc::signal< void, char *, int > charactersReceived
A signal that is emitted when there is data to read.
~Serial(void)
Destructor.
Pin
A type that defines the read/write pins in the serial port.
@ PIN_DTR
Output: Data Terminal Ready.
@ PIN_NONE
No pin.
@ PIN_CTS
Input: Clear To Send.
@ PIN_DCD
Input: Data Carrier Detect.
@ PIN_RI
Input: Ring Indicate.
@ PIN_RTS
Output: Request To Send.
@ PIN_DSR
Input: Data Set Ready.
int write(const char *buf, size_t count)
Write data to the serial port.
Parity
A type that defines the possible choices for parity.
@ PARITY_ODD
Use odd parity.
@ PARITY_NONE
Parity not used.
@ PARITY_EVEN
Use even parity.
bool setPin(Pin pin, bool set)
Set the state of one of the output pins in the serial port.
static const int READ_BUFSIZE
The maximum number of characters that can be read at once.
bool stopInput(bool stop)
Stop/start input of data.
bool setCanonical(bool canonical)
Set or clear canonical mode.
bool getPin(Pin pin, bool &is_set)
Get the state of one of the input pins in the serial port.
Namespace for the asynchronous programming classes.