qextserialbase.h

00001 #ifndef _QEXTSERIALBASE_H_
00002 #define _QEXTSERIALBASE_H_
00003 
00004 #include <qobject.h>
00005 #include <qiodevice.h>
00006 #include <qfile.h>
00007 #include "teglobal.h"
00008 
00009 #ifdef QT_THREAD_SUPPORT
00010 #include <qthread.h>
00011 #endif
00012 
00013 /*if all warning messages are turned off, flag portability warnings to be turned off as well*/
00014 #ifdef _TTY_NOWARN_
00015 #define _TTY_NOWARN_PORT_
00016 #endif
00017 
00018 /*QT3 changed some return types in QIODevice - these typedefs will retain compatibility with 
00019   earlier versions*/
00020 #ifdef QTVER_PRE_30
00021 typedef uint Offset;
00022 typedef int Q_LONG;
00023 #else
00024 
00025 /*Some compilers (VC++) don't inherit this typedef from QIODevice.h - copied here*/
00026 #ifdef _MSC_VER
00027 #ifdef QT_LARGE_FILE_SUPPORT
00028     typedef off_t Offset;
00029 #else
00030     typedef Q_ULONG Offset;
00031 #endif //_MSC_VER
00032 #endif //QT_LARGE_FILE_SUPPORT
00033 #endif //QTVER_PRE_30
00034 
00035 /*macros for thread support*/
00036 #ifdef QT_THREAD_SUPPORT
00037 #define LOCK_MUTEX() mutex->lock()
00038 #define UNLOCK_MUTEX() mutex->unlock()
00039 #else
00040 #define LOCK_MUTEX() 
00041 #define UNLOCK_MUTEX() 
00042 #endif
00043 
00044 /*macros for warning messages*/
00045 #ifdef _TTY_NOWARN_PORT_
00046 #define TTY_PORTABILITY_WARNING(s) 
00047 #else
00048 #define TTY_PORTABILITY_WARNING(s) qWarning(s)
00049 #endif
00050 #ifdef _TTY_NOWARN_
00051 #define TTY_WARNING(s)
00052 #else
00053 #define TTY_WARNING(s) qWarning(s)
00054 #endif
00055 
00056 
00057 /*simple MIN macro - evaluates to the smaller of the 2 members*/
00058 #define MIN(a,b) (((a)<(b))?(a):(b))
00059 
00060 /*limit of length of port name, not including NULL terminator*/
00061 #define PORT_NAME_SIZE_LIMIT 80
00062 
00063 /*line status constants*/
00064 #define LS_CTS  0x01
00065 #define LS_DSR  0x02
00066 #define LS_DCD  0x04
00067 #define LS_RI   0x08
00068 #define LS_RTS  0x10
00069 #define LS_DTR  0x20
00070 #define LS_ST   0x40
00071 #define LS_SR   0x80
00072 
00073 /*error constants*/
00074 #define E_NO_ERROR                   0
00075 #define E_INVALID_FD                 1
00076 #define E_NO_MEMORY                  2
00077 #define E_CAUGHT_NON_BLOCKED_SIGNAL  3
00078 #define E_PORT_TIMEOUT               4
00079 #define E_INVALID_DEVICE             5
00080 #define E_BREAK_CONDITION            6
00081 #define E_FRAMING_ERROR              7
00082 #define E_IO_ERROR                   8
00083 #define E_BUFFER_OVERRUN             9
00084 #define E_RECEIVE_OVERFLOW          10
00085 #define E_RECEIVE_PARITY_ERROR      11
00086 #define E_TRANSMIT_OVERFLOW         12
00087 #define E_READ_FAILED               13
00088 #define E_WRITE_FAILED              14
00089 
00090 /*enums for port settings*/
00091 typedef enum _NamingConvention {
00092     WIN_NAMES,
00093     IRIX_NAMES,
00094     HPUX_NAMES,
00095     SUN_NAMES,
00096     LINUX_NAMES,
00097     DIGITAL_NAMES
00098 } NamingConvention;
00099 
00100 typedef enum _FlowType {
00101     FLOW_NOTSET,
00102     FLOW_OFF, 
00103     FLOW_HARDWARE, 
00104     FLOW_XONXOFF
00105 } FlowType;
00106 
00107 typedef enum _ParityType {
00108     PAR_NOTSET,
00109     PAR_NONE, 
00110     PAR_ODD,
00111     PAR_EVEN, 
00112     PAR_MARK,               //WINDOWS ONLY
00113     PAR_SPACE
00114 } ParityType;
00115 
00116 typedef enum _DataBitsType {
00117     DATA_NOTSET,
00118     DATA_5,
00119     DATA_6,
00120     DATA_7,
00121     DATA_8
00122 } DataBitsType;
00123 
00124 typedef enum _StopBitsType {
00125     STOP_NOTSET,
00126     STOP_1, 
00127     STOP_1_5,               //WINDOWS ONLY
00128     STOP_2
00129 } StopBitsType;
00130 
00131 typedef enum _BaudRateType {
00132     BAUD_NOTSET,
00133     BAUD50,                //POSIX ONLY
00134     BAUD75,                //POSIX ONLY
00135     BAUD110,
00136     BAUD134,               //POSIX ONLY
00137     BAUD150,               //POSIX ONLY
00138     BAUD200,               //POSIX ONLY
00139     BAUD300,
00140     BAUD600,
00141     BAUD1200,
00142     BAUD1800,              //POSIX ONLY
00143     BAUD2400,
00144     BAUD4800,
00145     BAUD9600,
00146     BAUD14400,             //WINDOWS ONLY
00147     BAUD19200,
00148     BAUD38400,
00149     BAUD56000,             //WINDOWS ONLY
00150     BAUD57600,
00151     BAUD76800,             //POSIX ONLY
00152     BAUD115200, 
00153     BAUD128000,            //WINDOWS ONLY
00154     BAUD256000             //WINDOWS ONLY
00155 } BaudRateType; 
00156 
00157 /*structure to contain port settings*/
00158 typedef struct _PortSettings {
00159     FlowType FlowControl;
00160     ParityType Parity;
00161     DataBitsType DataBits;
00162     StopBitsType StopBits;
00163     BaudRateType BaudRate;
00164     unsigned long Timeout_Sec;
00165     unsigned long Timeout_Millisec;
00166 } PortSettings;
00167 
00168 class LIB_EXPORT QextSerialBase:public QIODevice {
00169 public:
00170     QextSerialBase();
00171     QextSerialBase(const char* name);
00172     virtual ~QextSerialBase();
00173     virtual void construct(void);
00174     virtual const char* name() const;
00175     virtual void setName(const char* name);
00176     virtual bool open(int mode=0)=0;
00177     virtual bool open(const char* name);
00178     virtual void close()=0;
00179     virtual void flush()=0;
00180     virtual Offset size() const=0;
00181     virtual int readLine(char *data, uint maxlen);
00182     virtual int getch()=0;
00183     virtual int putch(int)=0;
00184     virtual int ungetch(int);
00185     virtual bool atEnd() const;
00186     virtual void setFlowControl(FlowType)=0;
00187     virtual FlowType flowControl() const;
00188     virtual void setParity(ParityType)=0;
00189     virtual ParityType parity() const;
00190     virtual void setDataBits(DataBitsType)=0;
00191     virtual DataBitsType dataBits() const;
00192     virtual void setStopBits(StopBitsType)=0;
00193     virtual StopBitsType stopBits() const;
00194     virtual void setBaudRate(BaudRateType)=0;
00195     virtual BaudRateType baudRate() const;
00196     virtual bool isOpen() const;
00197     virtual unsigned long lastError() const;
00198     virtual void setDtr(bool set=true)=0;
00199     virtual void setRts(bool set=true)=0;
00200     virtual unsigned long lineStatus(void)=0;
00201     virtual int bytesWaiting()=0;
00202     virtual void translateError(unsigned long)=0;
00203     virtual void setTimeout(unsigned long, unsigned long)=0;
00204     virtual bool isOpen(void);
00205 
00206 #ifdef QTVER_PRE_30
00207     virtual Q_LONG readBlock(char *data, uint maxlen)=0;
00208     virtual Q_LONG writeBlock(const char *data, uint len)=0;
00209 #else
00210     virtual Q_LONG readBlock(char *data, unsigned long maxlen)=0;
00211     virtual Q_LONG writeBlock(const char *data, unsigned long len)=0;
00212 #endif
00213 
00214 protected:
00215     bool portOpen;
00216     unsigned long lastErr;
00217     char portName[PORT_NAME_SIZE_LIMIT+1];
00218     PortSettings Settings;
00219 
00220 #ifdef QT_THREAD_SUPPORT
00221     static unsigned long refCount;
00222     static QMutex* mutex;
00223 #endif
00224 };
00225 
00226 #endif

Документация по Общая библиотека для работы с торговым оборудованием.. Последние изменения: Sun Jul 2 23:37:24 2006. Создано системой  doxygen 1.4.7