
QtSDK と NI-DAQmxBase (Linux) を使った単純なサンプル
| Revision | 1ed5db835fc216132340089c6329066ffb7048e1 (tree) |
|---|---|
| Time | 2012-08-29 17:13:46 |
| Author | arakaki <alucky4416@user...> |
| Commiter | arakaki |
CHG: add DevName combobox Widget for selectable DeviceName.
| @@ -25,8 +25,11 @@ void DAQThread::stop() | ||
| 25 | 25 | stopped = true; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | -void DAQThread::startPulseOutput(float freq, float duty) | |
| 28 | +void DAQThread::startPulseOutput(QString &devname, float freq, float duty) | |
| 29 | 29 | { |
| 30 | + QString tmpname = devname + "/ctr0"; | |
| 31 | + // qDebug() << "counter name is " << tmpname; | |
| 32 | + ctrname = tmpname.toLocal8Bit(); | |
| 30 | 33 | pulse_freq = freq; |
| 31 | 34 | pulse_duty = (float64)(duty / 100.0); |
| 32 | 35 | EvtQue->enqueue(Ev_Start); |
| @@ -48,9 +51,10 @@ void DAQThread::run() | ||
| 48 | 51 | { |
| 49 | 52 | int32 error = 0; |
| 50 | 53 | char errBuff[2048] = { '\0' }; |
| 51 | - char ctrname[128] = "Dev1/ctr0"; | |
| 54 | +// char ctrname[128] = "Dev1/ctr0"; | |
| 52 | 55 | |
| 53 | 56 | taskHandle = 0; |
| 57 | + ctrname = "Dev1/ctr0"; | |
| 54 | 58 | pulse_freq = (float64)1000.0; |
| 55 | 59 | pulse_duty = (float64)0.50; // 0.50 is 50% |
| 56 | 60 | int event = 0; |
| @@ -15,7 +15,7 @@ public: | ||
| 15 | 15 | ~DAQThread(); |
| 16 | 16 | void stop(); |
| 17 | 17 | |
| 18 | - void startPulseOutput(float freq, float duty); | |
| 18 | + void startPulseOutput(QString &devname, float freq, float duty); | |
| 19 | 19 | void stopPulseOutput(); |
| 20 | 20 | void changePulseOutput(float freq, float duty); |
| 21 | 21 |
| @@ -35,6 +35,7 @@ private: | ||
| 35 | 35 | volatile bool stopped; |
| 36 | 36 | |
| 37 | 37 | TaskHandle taskHandle; // Daqmxbase task handle |
| 38 | + QByteArray ctrname; // = "Dev1/ctr0"; | |
| 38 | 39 | float64 pulse_freq; |
| 39 | 40 | float64 pulse_duty; |
| 40 | 41 |
| @@ -4,12 +4,22 @@ | ||
| 4 | 4 | #include <QDebug> |
| 5 | 5 | #include <QMessageBox> |
| 6 | 6 | |
| 7 | +#include <QRegExp> | |
| 8 | +#include <QRegExpValidator> | |
| 9 | + | |
| 7 | 10 | MainWindow::MainWindow(QWidget *parent) : |
| 8 | 11 | QMainWindow(parent), |
| 9 | 12 | ui(new Ui::MainWindow) |
| 10 | 13 | { |
| 11 | 14 | ui->setupUi(this); |
| 12 | 15 | |
| 16 | + QRegExp regexpDevName("Dev[1-9][0-9]*"); | |
| 17 | + ui->comboBox_DevName->setValidator(new QRegExpValidator(regexpDevName, this)); | |
| 18 | + ui->comboBox_DevName->setEditable(true); | |
| 19 | + ui->comboBox_DevName->setEnabled(true); | |
| 20 | + ui->comboBox_DevName->setCurrentIndex(0); | |
| 21 | + DevName = "Dev1"; | |
| 22 | + | |
| 13 | 23 | ui->statusBar->showMessage("DaqmxBase Initialize..."); |
| 14 | 24 | ui->pushButton_Output->setEnabled(false); |
| 15 | 25 | ui->pushButton_Output->setText("ON"); |
| @@ -49,15 +59,23 @@ MainWindow::~MainWindow() | ||
| 49 | 59 | delete ui; |
| 50 | 60 | } |
| 51 | 61 | |
| 62 | +void MainWindow::on_comboBox_DevName_editTextChanged(const QString &arg1) | |
| 63 | +{ | |
| 64 | + DevName = arg1; | |
| 65 | +// qDebug() << QString("combobox_Devname is %1").arg(DevName); | |
| 66 | +} | |
| 67 | + | |
| 52 | 68 | void MainWindow::on_pushButton_Output_clicked() |
| 53 | 69 | { |
| 54 | 70 | if (flag_output_status) { |
| 55 | 71 | DaqTh->stopPulseOutput(); |
| 56 | 72 | ui->pushButton_Output->setText("ON"); |
| 73 | + ui->comboBox_DevName->setEnabled(true); | |
| 57 | 74 | flag_output_status = false; |
| 58 | 75 | } else { |
| 59 | - DaqTh->startPulseOutput((float)ui->doubleSpinBox_Freq->value(), (float)ui->doubleSpinBox_Duty->value()); | |
| 76 | + DaqTh->startPulseOutput(DevName, (float)ui->doubleSpinBox_Freq->value(), (float)ui->doubleSpinBox_Duty->value()); | |
| 60 | 77 | ui->pushButton_Output->setText("OFF"); |
| 78 | + ui->comboBox_DevName->setEnabled(false); | |
| 61 | 79 | flag_output_status = true; |
| 62 | 80 | } |
| 63 | 81 | } |
| @@ -113,5 +131,3 @@ void MainWindow::pulse_output_stopped() | ||
| 113 | 131 | { |
| 114 | 132 | ui->statusBar->showMessage("Idle..."); |
| 115 | 133 | } |
| 116 | - | |
| 117 | - |
| @@ -18,6 +18,8 @@ public: | ||
| 18 | 18 | ~MainWindow(); |
| 19 | 19 | |
| 20 | 20 | private slots: |
| 21 | + void on_comboBox_DevName_editTextChanged(const QString &arg1); | |
| 22 | + | |
| 21 | 23 | void on_pushButton_Output_clicked(); |
| 22 | 24 | |
| 23 | 25 | void on_doubleSpinBox_Freq_valueChanged(double arg1); |
| @@ -35,11 +37,13 @@ private slots: | ||
| 35 | 37 | void pulse_output_stopped(); |
| 36 | 38 | |
| 37 | 39 | |
| 40 | + | |
| 38 | 41 | private: |
| 39 | 42 | Ui::MainWindow *ui; |
| 40 | 43 | |
| 41 | 44 | DAQThread *DaqTh; |
| 42 | 45 | bool flag_output_status; |
| 46 | + QString DevName; | |
| 43 | 47 | }; |
| 44 | 48 | |
| 45 | 49 | #endif // MAINWINDOW_H |
| @@ -6,8 +6,8 @@ | ||
| 6 | 6 | <rect> |
| 7 | 7 | <x>0</x> |
| 8 | 8 | <y>0</y> |
| 9 | - <width>500</width> | |
| 10 | - <height>439</height> | |
| 9 | + <width>562</width> | |
| 10 | + <height>500</height> | |
| 11 | 11 | </rect> |
| 12 | 12 | </property> |
| 13 | 13 | <property name="windowTitle"> |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | <property name="geometry"> |
| 19 | 19 | <rect> |
| 20 | 20 | <x>80</x> |
| 21 | - <y>200</y> | |
| 21 | + <y>260</y> | |
| 22 | 22 | <width>101</width> |
| 23 | 23 | <height>31</height> |
| 24 | 24 | </rect> |
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | <property name="geometry"> |
| 44 | 44 | <rect> |
| 45 | 45 | <x>40</x> |
| 46 | - <y>40</y> | |
| 46 | + <y>110</y> | |
| 47 | 47 | <width>121</width> |
| 48 | 48 | <height>18</height> |
| 49 | 49 | </rect> |
| @@ -62,7 +62,7 @@ | ||
| 62 | 62 | <property name="geometry"> |
| 63 | 63 | <rect> |
| 64 | 64 | <x>280</x> |
| 65 | - <y>190</y> | |
| 65 | + <y>250</y> | |
| 66 | 66 | <width>141</width> |
| 67 | 67 | <height>51</height> |
| 68 | 68 | </rect> |
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | <property name="geometry"> |
| 76 | 76 | <rect> |
| 77 | 77 | <x>80</x> |
| 78 | - <y>310</y> | |
| 78 | + <y>370</y> | |
| 79 | 79 | <width>101</width> |
| 80 | 80 | <height>31</height> |
| 81 | 81 | </rect> |
| @@ -100,7 +100,7 @@ | ||
| 100 | 100 | <property name="geometry"> |
| 101 | 101 | <rect> |
| 102 | 102 | <x>280</x> |
| 103 | - <y>170</y> | |
| 103 | + <y>230</y> | |
| 104 | 104 | <width>101</width> |
| 105 | 105 | <height>18</height> |
| 106 | 106 | </rect> |
| @@ -119,7 +119,7 @@ | ||
| 119 | 119 | <property name="geometry"> |
| 120 | 120 | <rect> |
| 121 | 121 | <x>40</x> |
| 122 | - <y>260</y> | |
| 122 | + <y>320</y> | |
| 123 | 123 | <width>81</width> |
| 124 | 124 | <height>18</height> |
| 125 | 125 | </rect> |
| @@ -151,7 +151,7 @@ | ||
| 151 | 151 | <property name="geometry"> |
| 152 | 152 | <rect> |
| 153 | 153 | <x>40</x> |
| 154 | - <y>280</y> | |
| 154 | + <y>340</y> | |
| 155 | 155 | <width>160</width> |
| 156 | 156 | <height>19</height> |
| 157 | 157 | </rect> |
| @@ -173,7 +173,7 @@ | ||
| 173 | 173 | <property name="geometry"> |
| 174 | 174 | <rect> |
| 175 | 175 | <x>30</x> |
| 176 | - <y>60</y> | |
| 176 | + <y>120</y> | |
| 177 | 177 | <width>181</width> |
| 178 | 178 | <height>131</height> |
| 179 | 179 | </rect> |
| @@ -216,7 +216,7 @@ | ||
| 216 | 216 | <property name="geometry"> |
| 217 | 217 | <rect> |
| 218 | 218 | <x>290</x> |
| 219 | - <y>250</y> | |
| 219 | + <y>310</y> | |
| 220 | 220 | <width>191</width> |
| 221 | 221 | <height>20</height> |
| 222 | 222 | </rect> |
| @@ -229,7 +229,7 @@ | ||
| 229 | 229 | <property name="geometry"> |
| 230 | 230 | <rect> |
| 231 | 231 | <x>60</x> |
| 232 | - <y>170</y> | |
| 232 | + <y>230</y> | |
| 233 | 233 | <width>21</width> |
| 234 | 234 | <height>18</height> |
| 235 | 235 | </rect> |
| @@ -242,7 +242,7 @@ | ||
| 242 | 242 | <property name="geometry"> |
| 243 | 243 | <rect> |
| 244 | 244 | <x>170</x> |
| 245 | - <y>170</y> | |
| 245 | + <y>230</y> | |
| 246 | 246 | <width>61</width> |
| 247 | 247 | <height>18</height> |
| 248 | 248 | </rect> |
| @@ -251,13 +251,65 @@ | ||
| 251 | 251 | <string>1000000</string> |
| 252 | 252 | </property> |
| 253 | 253 | </widget> |
| 254 | + <widget class="QComboBox" name="comboBox_DevName"> | |
| 255 | + <property name="geometry"> | |
| 256 | + <rect> | |
| 257 | + <x>40</x> | |
| 258 | + <y>60</y> | |
| 259 | + <width>121</width> | |
| 260 | + <height>28</height> | |
| 261 | + </rect> | |
| 262 | + </property> | |
| 263 | + <property name="editable"> | |
| 264 | + <bool>true</bool> | |
| 265 | + </property> | |
| 266 | + <item> | |
| 267 | + <property name="text"> | |
| 268 | + <string>Dev1</string> | |
| 269 | + </property> | |
| 270 | + </item> | |
| 271 | + <item> | |
| 272 | + <property name="text"> | |
| 273 | + <string>Dev2</string> | |
| 274 | + </property> | |
| 275 | + </item> | |
| 276 | + <item> | |
| 277 | + <property name="text"> | |
| 278 | + <string>Dev3</string> | |
| 279 | + </property> | |
| 280 | + </item> | |
| 281 | + <item> | |
| 282 | + <property name="text"> | |
| 283 | + <string>Dev4</string> | |
| 284 | + </property> | |
| 285 | + </item> | |
| 286 | + </widget> | |
| 287 | + <widget class="QLabel" name="label_8"> | |
| 288 | + <property name="geometry"> | |
| 289 | + <rect> | |
| 290 | + <x>40</x> | |
| 291 | + <y>40</y> | |
| 292 | + <width>121</width> | |
| 293 | + <height>18</height> | |
| 294 | + </rect> | |
| 295 | + </property> | |
| 296 | + <property name="font"> | |
| 297 | + <font> | |
| 298 | + <weight>75</weight> | |
| 299 | + <bold>true</bold> | |
| 300 | + </font> | |
| 301 | + </property> | |
| 302 | + <property name="text"> | |
| 303 | + <string>DevName</string> | |
| 304 | + </property> | |
| 305 | + </widget> | |
| 254 | 306 | </widget> |
| 255 | 307 | <widget class="QMenuBar" name="menuBar"> |
| 256 | 308 | <property name="geometry"> |
| 257 | 309 | <rect> |
| 258 | 310 | <x>0</x> |
| 259 | 311 | <y>0</y> |
| 260 | - <width>500</width> | |
| 312 | + <width>562</width> | |
| 261 | 313 | <height>26</height> |
| 262 | 314 | </rect> |
| 263 | 315 | </property> |