
Qt+MinGw環境でNIDAQmxを使ったパルス生成サンプル
| Revision | 63321b4324512be0bf8614c9995455c8a62e851f (tree) |
|---|---|
| Time | 2012-11-09 23:29:37 |
| Author | arakaki <alucky4416@user...> |
| Commiter | arakaki |
ADD: Add Widget: CheckBox for Select ContSamp/FiniteSamp mode.
| @@ -25,13 +25,15 @@ void DAQThread::stop() | ||
| 25 | 25 | stopped = true; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | -void DAQThread::startPulseOutput(QString &devname, float freq, float duty) | |
| 28 | +void DAQThread::startPulseOutput(QString &devname, float freq, float duty, int continue_mode = 1, unsigned long long int pulsecount = 1) | |
| 29 | 29 | { |
| 30 | 30 | QString tmpname = devname + "/ctr0"; |
| 31 | 31 | // qDebug() << "counter name is " << tmpname; |
| 32 | 32 | ctrname = tmpname.toLocal8Bit(); |
| 33 | 33 | pulse_freq = freq; |
| 34 | 34 | pulse_duty = (float64)(duty / 100.0); |
| 35 | + cont_mode = continue_mode ? DAQmx_Val_ContSamps : DAQmx_Val_FiniteSamps; | |
| 36 | + pulse_count = pulsecount; | |
| 35 | 37 | EvtQue->enqueue(Ev_Start); |
| 36 | 38 | } |
| 37 | 39 |
| @@ -79,12 +81,13 @@ void DAQThread::run() | ||
| 79 | 81 | switch (state) { |
| 80 | 82 | case State_IDLE: |
| 81 | 83 | if (event == Ev_Start) { |
| 82 | - qDebug() << QString("start pulse output: freq = %1, ducy = %2").arg(pulse_freq).arg(pulse_duty); | |
| 84 | + qDebug() << QString("start pulse output: freq = %1, ducy = %2, mode = %3, count = %4").arg(pulse_freq).arg(pulse_duty).arg(cont_mode).arg(pulse_count); | |
| 83 | 85 | // int32 DAQmxBaseCreateCOPulseChanFreq (TaskHandle taskHandle, const char counter[ ], const char nameToAssignToChannel[ ], int32 units, int32 idleState, float64 initialDelay, float64 freq, float64 dutyCycle); |
| 84 | 86 | DAQmxErrChk (DAQmxCreateTask("", &taskHandle)); |
| 85 | 87 | DAQmxErrChk (DAQmxCreateCOPulseChanFreq (taskHandle, ctrname, "", DAQmx_Val_Hz, DAQmx_Val_Low, (float64)0.0, pulse_freq, pulse_duty)); |
| 86 | 88 | // int32 DAQmxBaseCfgImplicitTiming (TaskHandle taskHandle, int32 sampleMode, uInt64 sampsPerChanToAcquire); |
| 87 | - DAQmxErrChk (DAQmxCfgImplicitTiming (taskHandle, DAQmx_Val_ContSamps, (uInt64)0)); | |
| 89 | + // DAQmxErrChk (DAQmxCfgImplicitTiming (taskHandle, DAQmx_Val_ContSamps, (uInt64)0)); | |
| 90 | + DAQmxErrChk (DAQmxCfgImplicitTiming (taskHandle, cont_mode, pulse_count)); | |
| 88 | 91 | DAQmxErrChk (DAQmxStartTask (taskHandle)); |
| 89 | 92 | emit pulse_output_started(); |
| 90 | 93 | state = State_OUTPUT; |
| @@ -119,7 +122,7 @@ void DAQThread::run() | ||
| 119 | 122 | DAQmxErrChk (DAQmxClearTask (taskHandle)); |
| 120 | 123 | taskHandle = 0; |
| 121 | 124 | emit pulse_output_stopped(); |
| 122 | - qDebug() << "stop pulse output."; // stop Pulse | |
| 125 | + qDebug() << "done, stop pulse output."; // stop Pulse | |
| 123 | 126 | state = State_IDLE; |
| 124 | 127 | } |
| 125 | 128 | } |
| @@ -15,7 +15,7 @@ public: | ||
| 15 | 15 | ~DAQThread(); |
| 16 | 16 | void stop(); |
| 17 | 17 | |
| 18 | - void startPulseOutput(QString &devname, float freq, float duty); | |
| 18 | + void startPulseOutput(QString &devname, float freq, float duty, int mode, unsigned long long int pulsecount); | |
| 19 | 19 | void stopPulseOutput(); |
| 20 | 20 | void changePulseOutput(float freq, float duty); |
| 21 | 21 |
| @@ -38,6 +38,8 @@ private: | ||
| 38 | 38 | QByteArray ctrname; // = "Dev1/ctr0"; |
| 39 | 39 | float64 pulse_freq; |
| 40 | 40 | float64 pulse_duty; |
| 41 | + int32 cont_mode; // 1 = DAQmx_Val_ContSamps or 0 = DAQmx_Val_FiniteSamps | |
| 42 | + uInt64 pulse_count; // pulse count when DAQmx_Val_FiniteSamps | |
| 41 | 43 | |
| 42 | 44 | // State Machine, state Id |
| 43 | 45 | enum { State_IDLE = 0, |
| @@ -75,7 +75,12 @@ void MainWindow::on_pushButton_Output_clicked() | ||
| 75 | 75 | ui->comboBox_DevName->setEnabled(true); |
| 76 | 76 | flag_output_status = false; |
| 77 | 77 | } else { |
| 78 | - DaqTh->startPulseOutput(DevName, (float)ui->doubleSpinBox_Freq->value(), (float)ui->doubleSpinBox_Duty->value()); | |
| 78 | + int mode = ui->checkBox_ContMode->isChecked() ? 1 : 0; | |
| 79 | + DaqTh->startPulseOutput(DevName, | |
| 80 | + (float)ui->doubleSpinBox_Freq->value(), | |
| 81 | + (float)ui->doubleSpinBox_Duty->value(), | |
| 82 | + mode, | |
| 83 | + (unsigned long long int)ui->spinBox_PulseCount->value()); | |
| 79 | 84 | ui->pushButton_Output->setText("OFF"); |
| 80 | 85 | ui->comboBox_DevName->setEnabled(false); |
| 81 | 86 | flag_output_status = true; |
| @@ -108,6 +113,15 @@ void MainWindow::on_horizontalSlider_Duty_valueChanged(int value) | ||
| 108 | 113 | ui->doubleSpinBox_Duty->setValue((double)value); |
| 109 | 114 | } |
| 110 | 115 | |
| 116 | +void MainWindow::on_checkBox_ContMode_toggled(bool checked) | |
| 117 | +{ | |
| 118 | + if (checked) { | |
| 119 | + ui->spinBox_PulseCount->setEnabled(false); | |
| 120 | + } else { | |
| 121 | + ui->spinBox_PulseCount->setEnabled(true); | |
| 122 | + } | |
| 123 | +} | |
| 124 | + | |
| 111 | 125 | void MainWindow::daqmxbase_ready() |
| 112 | 126 | { |
| 113 | 127 | ui->statusBar->showMessage("Idle..."); |
| @@ -135,4 +149,3 @@ void MainWindow::pulse_output_stopped() | ||
| 135 | 149 | { |
| 136 | 150 | ui->statusBar->showMessage("Idle..."); |
| 137 | 151 | } |
| 138 | - |
| @@ -30,6 +30,8 @@ private slots: | ||
| 30 | 30 | |
| 31 | 31 | void on_horizontalSlider_Duty_valueChanged(int value); |
| 32 | 32 | |
| 33 | + void on_checkBox_ContMode_toggled(bool checked); | |
| 34 | + | |
| 33 | 35 | void daqmxbase_ready(); |
| 34 | 36 | void daqmxbase_final(); |
| 35 | 37 | void daqmxbase_error(QString ErrMsg); |
| @@ -22,15 +22,21 @@ | ||
| 22 | 22 | <rect> |
| 23 | 23 | <x>80</x> |
| 24 | 24 | <y>270</y> |
| 25 | - <width>101</width> | |
| 25 | + <width>91</width> | |
| 26 | 26 | <height>31</height> |
| 27 | 27 | </rect> |
| 28 | 28 | </property> |
| 29 | + <property name="alignment"> | |
| 30 | + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
| 31 | + </property> | |
| 29 | 32 | <property name="readOnly"> |
| 30 | 33 | <bool>true</bool> |
| 31 | 34 | </property> |
| 35 | + <property name="buttonSymbols"> | |
| 36 | + <enum>QAbstractSpinBox::NoButtons</enum> | |
| 37 | + </property> | |
| 32 | 38 | <property name="suffix"> |
| 33 | - <string>Hz</string> | |
| 39 | + <string> Hz</string> | |
| 34 | 40 | </property> |
| 35 | 41 | <property name="decimals"> |
| 36 | 42 | <number>0</number> |
| @@ -42,7 +48,7 @@ | ||
| 42 | 48 | <double>1.000000000000000</double> |
| 43 | 49 | </property> |
| 44 | 50 | <property name="value"> |
| 45 | - <double>1.000000000000000</double> | |
| 51 | + <double>1000.000000000000000</double> | |
| 46 | 52 | </property> |
| 47 | 53 | </widget> |
| 48 | 54 | <widget class="QLabel" name="label"> |
| @@ -68,7 +74,7 @@ | ||
| 68 | 74 | <property name="geometry"> |
| 69 | 75 | <rect> |
| 70 | 76 | <x>340</x> |
| 71 | - <y>250</y> | |
| 77 | + <y>290</y> | |
| 72 | 78 | <width>141</width> |
| 73 | 79 | <height>51</height> |
| 74 | 80 | </rect> |
| @@ -86,8 +92,11 @@ | ||
| 86 | 92 | <height>31</height> |
| 87 | 93 | </rect> |
| 88 | 94 | </property> |
| 95 | + <property name="alignment"> | |
| 96 | + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
| 97 | + </property> | |
| 89 | 98 | <property name="suffix"> |
| 90 | - <string>%</string> | |
| 99 | + <string> %</string> | |
| 91 | 100 | </property> |
| 92 | 101 | <property name="decimals"> |
| 93 | 102 | <number>0</number> |
| @@ -106,7 +115,7 @@ | ||
| 106 | 115 | <property name="geometry"> |
| 107 | 116 | <rect> |
| 108 | 117 | <x>340</x> |
| 109 | - <y>230</y> | |
| 118 | + <y>270</y> | |
| 110 | 119 | <width>101</width> |
| 111 | 120 | <height>18</height> |
| 112 | 121 | </rect> |
| @@ -222,7 +231,7 @@ | ||
| 222 | 231 | <property name="geometry"> |
| 223 | 232 | <rect> |
| 224 | 233 | <x>350</x> |
| 225 | - <y>310</y> | |
| 234 | + <y>350</y> | |
| 226 | 235 | <width>191</width> |
| 227 | 236 | <height>20</height> |
| 228 | 237 | </rect> |
| @@ -318,6 +327,9 @@ | ||
| 318 | 327 | <height>28</height> |
| 319 | 328 | </rect> |
| 320 | 329 | </property> |
| 330 | + <property name="currentIndex"> | |
| 331 | + <number>3</number> | |
| 332 | + </property> | |
| 321 | 333 | <property name="maxCount"> |
| 322 | 334 | <number>2147483645</number> |
| 323 | 335 | </property> |
| @@ -376,6 +388,63 @@ | ||
| 376 | 388 | <string>x Scale</string> |
| 377 | 389 | </property> |
| 378 | 390 | </widget> |
| 391 | + <widget class="QSpinBox" name="spinBox_PulseCount"> | |
| 392 | + <property name="enabled"> | |
| 393 | + <bool>false</bool> | |
| 394 | + </property> | |
| 395 | + <property name="geometry"> | |
| 396 | + <rect> | |
| 397 | + <x>340</x> | |
| 398 | + <y>190</y> | |
| 399 | + <width>121</width> | |
| 400 | + <height>22</height> | |
| 401 | + </rect> | |
| 402 | + </property> | |
| 403 | + <property name="wrapping"> | |
| 404 | + <bool>false</bool> | |
| 405 | + </property> | |
| 406 | + <property name="alignment"> | |
| 407 | + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
| 408 | + </property> | |
| 409 | + <property name="minimum"> | |
| 410 | + <number>1</number> | |
| 411 | + </property> | |
| 412 | + <property name="maximum"> | |
| 413 | + <number>214748647</number> | |
| 414 | + </property> | |
| 415 | + <property name="value"> | |
| 416 | + <number>1</number> | |
| 417 | + </property> | |
| 418 | + </widget> | |
| 419 | + <widget class="QCheckBox" name="checkBox_ContMode"> | |
| 420 | + <property name="geometry"> | |
| 421 | + <rect> | |
| 422 | + <x>340</x> | |
| 423 | + <y>150</y> | |
| 424 | + <width>141</width> | |
| 425 | + <height>16</height> | |
| 426 | + </rect> | |
| 427 | + </property> | |
| 428 | + <property name="text"> | |
| 429 | + <string>Continue Output Pulse</string> | |
| 430 | + </property> | |
| 431 | + <property name="checked"> | |
| 432 | + <bool>true</bool> | |
| 433 | + </property> | |
| 434 | + </widget> | |
| 435 | + <widget class="QLabel" name="label_10"> | |
| 436 | + <property name="geometry"> | |
| 437 | + <rect> | |
| 438 | + <x>340</x> | |
| 439 | + <y>170</y> | |
| 440 | + <width>111</width> | |
| 441 | + <height>16</height> | |
| 442 | + </rect> | |
| 443 | + </property> | |
| 444 | + <property name="text"> | |
| 445 | + <string>Output Pulse Count</string> | |
| 446 | + </property> | |
| 447 | + </widget> | |
| 379 | 448 | </widget> |
| 380 | 449 | <widget class="QMenuBar" name="menuBar"> |
| 381 | 450 | <property name="geometry"> |