Trade equipment common library. 1.0.0
qextserialbase.h
1#ifndef _QEXTSERIALBASE_H_
2#define _QEXTSERIALBASE_H_
3
4#include <qobject.h>
5#include <qiodevice.h>
6#include <qfile.h>
7#include "teglobal.h"
8
9#ifdef QT_THREAD_SUPPORT
10#include <qthread.h>
11#endif
12
13/*if all warning messages are turned off, flag portability warnings to be turned off as well*/
14#ifdef _TTY_NOWARN_
15#define _TTY_NOWARN_PORT_
16#endif
17
18/*QT3 changed some return types in QIODevice - these typedefs will retain compatibility with
19 earlier versions*/
20#ifdef QTVER_PRE_30
21typedef uint Offset;
22typedef int Q_LONG;
23#else
24
25/*Some compilers (VC++) don't inherit this typedef from QIODevice.h - copied here*/
26#ifdef _MSC_VER
27#ifdef QT_LARGE_FILE_SUPPORT
28 typedef off_t Offset;
29#else
30 typedef Q_ULONG Offset;
31#endif //_MSC_VER
32#endif //QT_LARGE_FILE_SUPPORT
33#endif //QTVER_PRE_30
34
35/*macros for thread support*/
36#ifdef QT_THREAD_SUPPORT
37#define LOCK_MUTEX() mutex->lock()
38#define UNLOCK_MUTEX() mutex->unlock()
39#else
40#define LOCK_MUTEX()
41#define UNLOCK_MUTEX()
42#endif
43
44/*macros for warning messages*/
45#ifdef _TTY_NOWARN_PORT_
46#define TTY_PORTABILITY_WARNING(s)
47#else
48#define TTY_PORTABILITY_WARNING(s) qWarning(s)
49#endif
50#ifdef _TTY_NOWARN_
51#define TTY_WARNING(s)
52#else
53#define TTY_WARNING(s) qWarning(s)
54#endif
55
56
57/*simple MIN macro - evaluates to the smaller of the 2 members*/
58#define MIN(a,b) (((a)<(b))?(a):(b))
59
60/*limit of length of port name, not including NULL terminator*/
61#define PORT_NAME_SIZE_LIMIT 80
62
63/*line status constants*/
64#define LS_CTS 0x01
65#define LS_DSR 0x02
66#define LS_DCD 0x04
67#define LS_RI 0x08
68#define LS_RTS 0x10
69#define LS_DTR 0x20
70#define LS_ST 0x40
71#define LS_SR 0x80
72
73/*error constants*/
74#define E_NO_ERROR 0
75#define E_INVALID_FD 1
76#define E_NO_MEMORY 2
77#define E_CAUGHT_NON_BLOCKED_SIGNAL 3
78#define E_PORT_TIMEOUT 4
79#define E_INVALID_DEVICE 5
80#define E_BREAK_CONDITION 6
81#define E_FRAMING_ERROR 7
82#define E_IO_ERROR 8
83#define E_BUFFER_OVERRUN 9
84#define E_RECEIVE_OVERFLOW 10
85#define E_RECEIVE_PARITY_ERROR 11
86#define E_TRANSMIT_OVERFLOW 12
87#define E_READ_FAILED 13
88#define E_WRITE_FAILED 14
89
90/*enums for port settings*/
91typedef enum _NamingConvention {
92 WIN_NAMES,
93 IRIX_NAMES,
94 HPUX_NAMES,
95 SUN_NAMES,
96 LINUX_NAMES,
97 DIGITAL_NAMES
98} NamingConvention;
99
100typedef enum _FlowType {
101 FLOW_NOTSET,
102 FLOW_OFF,
103 FLOW_HARDWARE,
104 FLOW_XONXOFF
105} FlowType;
106
107typedef enum _ParityType {
108 PAR_NOTSET,
109 PAR_NONE,
110 PAR_ODD,
111 PAR_EVEN,
112 PAR_MARK, //WINDOWS ONLY
113 PAR_SPACE
114} ParityType;
115
116typedef enum _DataBitsType {
117 DATA_NOTSET,
118 DATA_5,
119 DATA_6,
120 DATA_7,
121 DATA_8
122} DataBitsType;
123
124typedef enum _StopBitsType {
125 STOP_NOTSET,
126 STOP_1,
127 STOP_1_5, //WINDOWS ONLY
128 STOP_2
129} StopBitsType;
130
131typedef enum _BaudRateType {
132 BAUD_NOTSET,
133 BAUD50, //POSIX ONLY
134 BAUD75, //POSIX ONLY
135 BAUD110,
136 BAUD134, //POSIX ONLY
137 BAUD150, //POSIX ONLY
138 BAUD200, //POSIX ONLY
139 BAUD300,
140 BAUD600,
141 BAUD1200,
142 BAUD1800, //POSIX ONLY
143 BAUD2400,
144 BAUD4800,
145 BAUD9600,
146 BAUD14400, //WINDOWS ONLY
147 BAUD19200,
148 BAUD38400,
149 BAUD56000, //WINDOWS ONLY
150 BAUD57600,
151 BAUD76800, //POSIX ONLY
152 BAUD115200,
153 BAUD128000, //WINDOWS ONLY
154 BAUD256000 //WINDOWS ONLY
155} BaudRateType;
156
157/*structure to contain port settings*/
158typedef struct _PortSettings {
159 FlowType FlowControl;
160 ParityType Parity;
161 DataBitsType DataBits;
162 StopBitsType StopBits;
163 BaudRateType BaudRate;
164 unsigned long Timeout_Sec;
165 unsigned long Timeout_Millisec;
166} PortSettings;
167
168class LIB_EXPORT QextSerialBase:public QIODevice {
169public:
171 QextSerialBase(const char* name);
172 virtual ~QextSerialBase();
173 virtual void construct(void);
174 virtual const char* name() const;
175 virtual void setName(const char* name);
176 virtual bool open(int mode=0)=0;
177 virtual bool open(const char* name);
178 virtual void close()=0;
179 virtual void flush()=0;
180 virtual Offset size() const=0;
181 virtual Q_LONG readLine(char *data, Q_ULONG maxlen);
182 virtual int getch()=0;
183 virtual int putch(int)=0;
184 virtual int ungetch(int);
185 virtual bool atEnd() const;
186 virtual void setFlowControl(FlowType)=0;
187 virtual FlowType flowControl() const;
188 virtual void setParity(ParityType)=0;
189 virtual ParityType parity() const;
190 virtual void setDataBits(DataBitsType)=0;
191 virtual DataBitsType dataBits() const;
192 virtual void setStopBits(StopBitsType)=0;
193 virtual StopBitsType stopBits() const;
194 virtual void setBaudRate(BaudRateType)=0;
195 virtual BaudRateType baudRate() const;
196 virtual bool isOpen() const;
197 virtual unsigned long lastError() const;
198 virtual void setDtr(bool set=true)=0;
199 virtual void setRts(bool set=true)=0;
200 virtual unsigned long lineStatus(void)=0;
201 virtual int bytesWaiting()=0;
202 virtual void translateError(unsigned long)=0;
203 virtual void setTimeout(unsigned long, unsigned long)=0;
204 virtual bool isOpen(void);
205
206#ifdef QTVER_PRE_30
207 virtual Q_LONG readBlock(char *data, uint maxlen)=0;
208 virtual Q_LONG writeBlock(const char *data, uint len)=0;
209#else
210 virtual Q_LONG readBlock(char *data, unsigned long maxlen)=0;
211 virtual Q_LONG writeBlock(const char *data, unsigned long len)=0;
212#endif
213
214protected:
215 bool portOpen;
216 unsigned long lastErr;
217 char portName[PORT_NAME_SIZE_LIMIT+1];
218 PortSettings Settings;
219
220#ifdef QT_THREAD_SUPPORT
221 static unsigned long refCount;
222 static QMutex* mutex;
223#endif
224};
225
226#endif
virtual bool atEnd() const
Definition qextserialbase.cpp:86
virtual FlowType flowControl() const
Definition qextserialbase.cpp:141
virtual const char * name() const
Definition qextserialbase.cpp:243
virtual ParityType parity() const
Definition qextserialbase.cpp:150
virtual void setName(const char *name)
Definition qextserialbase.cpp:77
virtual Q_LONG readLine(char *data, Q_ULONG maxlen)
Definition qextserialbase.cpp:101
virtual StopBitsType stopBits() const
Definition qextserialbase.cpp:168
virtual BaudRateType baudRate() const
Definition qextserialbase.cpp:177
QextSerialBase()
Definition qextserialbase.cpp:21
virtual bool isOpen() const
Definition qextserialbase.cpp:185
virtual int ungetch(int)
Definition qextserialbase.cpp:129
virtual unsigned long lastError() const
Definition qextserialbase.cpp:235
virtual void construct(void)
Definition qextserialbase.cpp:253
virtual DataBitsType dataBits() const
Definition qextserialbase.cpp:159
Definition qextserialbase.h:158