Eneboo - Documentación para desarrolladores
src/serialport/qextserialport.h
Ir a la documentación de este archivo.
00001 
00002 #ifndef _QEXTSERIALPORT_H_
00003 #define _QEXTSERIALPORT_H_
00004 
00005 #include "qiodevice.h"
00006 #include "qfile.h"
00007 #include "qvaluestack.h"
00008 
00009 #ifdef Q_WS_WIN
00010         #include <windows.h>
00011 #else
00012         #include <cstdlib>
00013         #include <unistd.h>
00014         #include <termios.h>
00015         #include <sys/ioctl.h>
00016 
00017         /*ensure handling of CRTSCTS constant*/
00018         #ifdef CNEW_RTSCTS
00019                 #ifndef CRTSCTS
00020                         #define CRTSCTS CNEW_RTSCTS
00021                 #endif
00022         #else
00023                 #ifndef CRTSCTS
00024                         #define CRTSCTS     0
00025                 #endif
00026         #endif
00027 #endif
00028 
00029 #ifdef _QESP_LOGTRACE_
00030         #define QESP_LOGTRACE(i) qWarning("["+Name+"] QextSerialPort::"+i);
00031 #else
00032         #define QESP_LOGTRACE(i)
00033 #endif
00034 
00035 class QextSerialPort
00036  : public QIODevice
00037 {
00038 public:
00039         enum BaudRateType
00040         {
00041                 BAUD50,      //POSIX ONLY
00042                 BAUD75,      //POSIX ONLY
00043                 BAUD110,
00044                 BAUD134,     //POSIX ONLY
00045                 BAUD150,     //POSIX ONLY
00046                 BAUD200,     //POSIX ONLY
00047                 BAUD300,
00048                 BAUD600,
00049                 BAUD1200,
00050                 BAUD1800,    //POSIX ONLY
00051                 BAUD2400,
00052                 BAUD4800,
00053                 BAUD9600,
00054                 BAUD14400,   //WINDOWS ONLY
00055                 BAUD19200,
00056                 BAUD38400,
00057                 BAUD56000,   //WINDOWS ONLY
00058                 BAUD57600,
00059                 BAUD76800,   //POSIX ONLY
00060                 BAUD115200,
00061                 BAUD128000,  //WINDOWS ONLY
00062                 BAUD256000   //WINDOWS ONLY
00063         };
00064 
00065         enum DataBitsType
00066         {
00067                 DATA_5,      //only for compatibility
00068                 DATA_6,
00069                 DATA_7,
00070                 DATA_8
00071         };
00072 
00073         enum ParityType
00074         {
00075                 PAR_NONE,
00076                 PAR_ODD,
00077                 PAR_EVEN,
00078                 PAR_MARK,    //WINDOWS ONLY
00079                 PAR_SPACE    //WINDOWS directly, POSIX simulated
00080         };
00081 
00082         enum StopBitsType
00083         {
00084                 STOP_1,
00085                 STOP_1_5,    //WINDOWS ONLY
00086                 STOP_2
00087         };
00088 
00089         enum FlowType
00090         {
00091                 FLOW_OFF,
00092                 FLOW_HARDWARE,
00093                 FLOW_XONXOFF
00094         };
00095 
00096         /*structure to contain port settings*/
00097         struct PortSettings
00098         {
00099                 BaudRateType BaudRate;
00100                 DataBitsType DataBits;
00101                 ParityType Parity;
00102                 StopBitsType StopBits;
00103                 FlowType FlowControl;
00104                 unsigned long Timeout_Sec;
00105                 unsigned long Timeout_Millisec;
00106         };
00107 
00108         QextSerialPort( const QString& name = "" );
00109         virtual ~QextSerialPort();
00110 
00111         virtual bool open( int mode = 0 );
00112         virtual void close();
00113         virtual void flush();
00114 
00115         QIODevice::Offset size() const;
00116 #ifdef _QESP_LOGTRACE_
00117         QIODevice::Offset at() const;  // non-pure virtual
00118 #endif
00119         bool at( QIODevice::Offset );  // non-pure virtual
00120 #ifdef _QESP_LOGTRACE_
00121         bool atEnd() const;  // non-pure virtual
00122 #endif
00123 
00124         virtual Q_LONG readBlock( char *data, Q_ULONG maxSize );
00125         virtual Q_LONG writeBlock( const char *data, Q_ULONG size );
00126 
00127 #ifdef _QESP_LOGTRACE_
00128         Q_LONG readLine( char *data, Q_ULONG maxlen );  // non-pure virtual
00129         QByteArray readAll();  // non-pure virtual
00130 #endif
00131 
00132         int getch();
00133         int putch( int );
00134         int ungetch( int );
00135 
00136         Q_ULONG bytesAvailable() const;
00137 
00138         void setName( const QString& name );
00139         QString name();
00140 
00141         virtual void setBaudRate( BaudRateType );
00142         virtual void setDataBits( DataBitsType );
00143         virtual void setParity( ParityType );
00144         virtual void setStopBits( StopBitsType );
00145         void setFlowControl( FlowType );
00146         void setTimeout( unsigned long=0, unsigned long=0 );
00147 
00148         BaudRateType baudRate() const { return Settings.BaudRate; };
00149         DataBitsType setDataBits() const { return Settings.DataBits; };
00150         ParityType setParity() const { return Settings.Parity; };
00151         StopBitsType setStopBits() const { return Settings.StopBits; };
00152         FlowType setFlowControl() const { return Settings.FlowControl; };
00153 
00154         void setRts( bool set = TRUE );
00155         void setDtr( bool set = TRUE );
00156 
00157         bool cts() const;
00158         bool dsr() const;
00159         bool dcd() const;
00160         bool ri() const;
00161 
00162 private:
00163         QextSerialPort( const QextSerialPort& sp );
00164         QextSerialPort& operator=( const QextSerialPort& sp );
00165 
00166 protected:
00167 #ifdef Q_WS_WIN
00168         HANDLE Win_Handle;
00169         DCB Win_CommConfig;
00170         COMMTIMEOUTS Win_CommTimeouts;
00171 #else
00172         QFile* Posix_File;
00173         struct termios Posix_CommConfig;
00174 #endif
00175 
00176         QString Name;
00177         PortSettings Settings;
00178 private:
00179         QValueStack<char> ungetchBuffer;
00180 };
00181 
00182 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'