DCL 4.0
Loading...
Searching...
No Matches
SerialPort.h
Go to the documentation of this file.
1#ifndef __DCL_SERIAL_PORT_H__
2#define __DCL_SERIAL_PORT_H__ 20110223
3
4#ifndef __DCL_CONFIG_H__
5#include <dcl/Config.h>
6#endif
7
8#if __DCL_WINDOWS
9 #define B1200 CBR_1200
10 #define B2400 CBR_2400
11 #define B4800 CBR_4800
12 #define B9600 CBR_9600
13 #define B19200 CBR_19200
14 #define B38400 CBR_38400
15 #define B57600 CBR_57600
16 #define B115200 CBR_115200
17#else
18 #include <termios.h>
19#endif
20
21#ifndef __DCL_POLL_ABLE_H__
22#include <dcl/PollAble.h>
23#endif
24
25__DCL_BEGIN_NAMESPACE
26
27#if __DCL_WINDOWS
28 class SerialPollThread;
29#endif
30
51class DCLCAPI SerialPort : public PollAble
52{
53 DECLARE_CLASSINFO(SerialPort)
54public:
55 virtual ~SerialPort();
56
61 SerialPort(const String& _path, int _oflags,
62 size_t _inQueue = 4096, size_t _outQueue = 4096
64
73 void open(const String& _path, int _oflags,
74 size_t _inQueue = 4096, size_t _outQueue = 4096
76
77 enum BaudRate
78 {
79 BR_1200 = B1200,
80 BR_2400 = B2400,
81 BR_4800 = B4800,
82 BR_9600 = B9600,
83 BR_19200 = B19200,
84 BR_38400 = B38400,
85 BR_57600 = B57600,
86 BR_115200 = B115200
87 };
88
89 enum ByteSize
90 {
91 BS_8NO, // 8Bit, No parity
92 BS_7EVEN, // 7Bit, Even parity
93 BS_7ODD // 7Bit, Odd parity
94 };
95
96 enum StopBits
97 {
98 SB_1, // 1 Stop bits
99 SB_2 // 2 Stop bits
100 };
101
102 enum FlowControl
103 {
104 FC_NONE,
105 FC_RTSCTS, // Hardware
106 FC_XONXOFF // Software
107 };
108
117 void setAttributes(
118 BaudRate _baudRate = BR_38400, ByteSize _byteSize = BS_8NO,
119 StopBits _stopBits = SB_1, FlowControl _flowControl = FC_NONE
121
122 enum PurgeFlag
123 {
124 PURGE_RX = 0x0001,
125 PURGE_TX = 0x0002
126 };
127
131 void purge(int _flags) __DCL_THROWS1(IOException*);
132
133protected:
138 virtual bool onEvent(short _revents, PollThread* _pPollThread)
140
141#if __DCL_WINDOWS
142private:
143 // SerialPollThread에 의해 사용된다.
144 DWORD __revents;
145 OVERLAPPED __overlapped;
146
147 bool waitCommEvent();
148
149 friend SerialPollThread;
150#endif
151
152public:
158 static bool access(const String& _path);
159};
160
161#if __DCL_WINDOWS
162 #undef B1200
163 #undef B2400
164 #undef B4800
165 #undef B9600
166 #undef B19200
167 #undef B38400
168 #undef B57600
169 #undef B115200
170#endif
171
172__DCL_END_NAMESPACE
173
174#endif // __DCL_SERIAL_PORT_H__
#define DCLCAPI
Definition Config.h:100
#define __DCL_THROWS1(e)
Definition Config.h:167
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
__DCL_BEGIN_NAMESPACE typedef PollThread SerialPollThread
void open(const String &_path, int _oflags=READONLY, int _mode=0666) __DCL_THROWS1(IOException *)
Definition File.cpp:77
friend class PollThread
Definition PollAble.h:38
virtual bool onEvent(short _revents, PollThread *_pPollThread) __DCL_THROWS1(IOException *)
static bool access(const String &_path)