00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef PORT_H
00012 #define PORT_H
00013
00014 #include <qstringlist.h>
00015
00016 #include <termios.h>
00017
00021 class Port
00022 {
00023 public:
00024 enum ProbeResult
00025 {
00026 ExistsAndRW = 1 << 0,
00027 ExistsButNotRW = 1 << 1,
00028 DoesntExist = 1 << 2
00029 };
00030
00031 Port();
00032 virtual ~Port();
00033
00039 static QStringList ports( unsigned probeResult );
00040 };
00041
00042
00048 class SerialPort : public Port
00049 {
00050 public:
00051 enum Pin
00052 {
00053 CD = 1,
00054 RD = 2,
00055 TD = 3,
00056 DTR = 4,
00057 GND = 5,
00058 DSR = 6,
00059 RTS = 7,
00060 CTS = 8,
00061 RI = 9,
00062 };
00063
00064 SerialPort();
00065 ~SerialPort();
00066
00070 void setPinState( Pin pin, bool state );
00071 bool pinState( Pin pin );
00072
00073 static ProbeResult probe( const QString & port );
00077 static QStringList ports( unsigned probeResult );
00083 bool openPort( const QString & port, speed_t baudRate );
00087 void closePort();
00088
00089 protected:
00091 termios m_previousState;
00092
00094 int m_file;
00095 };
00096
00097
00104 class ParallelPort : public Port
00105 {
00106 public:
00107 enum Pin
00108 {
00109
00110
00111
00112 PIN02 = 1 << 0,
00113 PIN03 = 1 << 1,
00114 PIN04 = 1 << 2,
00115 PIN05 = 1 << 3,
00116 PIN06 = 1 << 4,
00117 PIN07 = 1 << 5,
00118 PIN08 = 1 << 6,
00119 PIN09 = 1 << 7,
00120 DATA_PINS = PIN02 | PIN03 | PIN04 | PIN05 | PIN06
00121 | PIN07 | PIN08 | PIN09,
00122
00123
00124
00125
00126 PIN15 = 1 << 11,
00127 PIN13 = 1 << 12,
00128 PIN12 = 1 << 13,
00129 PIN10 = 1 << 14,
00130 PIN11 = 1 << 15,
00131 STATUS_PINS = PIN15 | PIN13 | PIN12 | PIN10 | PIN11,
00132
00133
00134
00135
00136 PIN01 = 1 << 16,
00137 PIN14 = 1 << 17,
00138 PIN16 = 1 << 18,
00139 PIN17 = 1 << 19,
00140 CONTROL_PINS = PIN01 | PIN14 | PIN16 | PIN17,
00141
00142
00143
00144 };
00145
00146 enum Register
00147 {
00148 Data = 0,
00149 Status = 1,
00150 Control = 2,
00151 };
00152
00156 enum Direction
00157 {
00158 Input = 0,
00159 Output = 1,
00160 };
00161
00162 ParallelPort();
00163 ~ParallelPort();
00164
00169 bool openPort( const QString & port );
00173 void closePort();
00174
00175
00179 void setPinState( int pins, bool state );
00183 int pinState( int pins );
00187 void setDataState( uchar pins, bool state );
00191 void setControlState( uchar pins, bool state );
00192
00193
00194
00195
00199 uchar readFromRegister( Register reg );
00203 void writeToData( uchar value );
00208 void writeToControl( uchar value );
00209
00210
00211
00212
00216 void setDataDirection( Direction dir );
00220 void setControlDirection( int pins, Direction dir );
00221
00222
00223 static ProbeResult probe( const QString & port );
00227 static QStringList ports( unsigned probeResult );
00228
00229 protected:
00233 void writeToRegister( Register reg, uchar value );
00234 void reset();
00235
00236 uchar m_reg[3];
00237
00239 int m_inputPins;
00240
00242 int m_outputPins;
00243
00245 int m_file;
00246 };
00247
00248 #endif