Main Page   Class Hierarchy   Compound List   File List   Compound Members  

qextserialbase.h

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

Generated on Sat Jun 15 15:43:04 2002 for QextSerialPort by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001