QtSDK と NI-DAQmxBase (Linux) を使った単純なサンプル
Revision | e8305f1a9058c8ef458912ad24c94ede126f9536 (tree) |
---|---|
Zeit | 2012-12-08 18:31:13 |
Autor | arakaki <alucky4416@user...> |
Commiter | arakaki |
ADD: 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 |
@@ -71,6 +73,17 @@ void DAQThread::run() | ||
71 | 73 | |
72 | 74 | while(!stopped) { |
73 | 75 | if (EvtQue->isEmpty()) { |
76 | + if (state == State_OUTPUT) { | |
77 | + bool32 done = 0; | |
78 | + DAQmxBaseIsTaskDone(taskHandle, &done); | |
79 | + if (done) { | |
80 | + DAQmxErrChk (DAQmxBaseClearTask(taskHandle)); | |
81 | + taskHandle = 0; | |
82 | + emit pulse_output_stopped(); | |
83 | + qDebug() << "done, stop pulse output."; // stop Pulse | |
84 | + state = State_IDLE; | |
85 | + } | |
86 | + } | |
74 | 87 | msleep(100); |
75 | 88 | continue; // Jump to Next Loop |
76 | 89 | } |
@@ -84,7 +97,7 @@ void DAQThread::run() | ||
84 | 97 | DAQmxErrChk (DAQmxBaseCreateTask("", &taskHandle)); |
85 | 98 | DAQmxErrChk (DAQmxBaseCreateCOPulseChanFreq (taskHandle, ctrname, "", DAQmx_Val_Hz, DAQmx_Val_Low, (float64)0.0, pulse_freq, pulse_duty)); |
86 | 99 | // int32 DAQmxBaseCfgImplicitTiming (TaskHandle taskHandle, int32 sampleMode, uInt64 sampsPerChanToAcquire); |
87 | - DAQmxErrChk (DAQmxBaseCfgImplicitTiming (taskHandle, DAQmx_Val_ContSamps, (uInt64)1)); // error, when USB-621x | |
100 | + DAQmxErrChk (DAQmxBaseCfgImplicitTiming (taskHandle, cont_mode, pulse_count)); | |
88 | 101 | //DAQmxErrChk (DAQmxBaseExportSignal(taskHandle, DAQmx_Val_CounterOutputEvent, "/Dev1/PFI6")); // not worked! , default "/Dev1/PFI4" |
89 | 102 | DAQmxErrChk (DAQmxBaseStartTask (taskHandle)); |
90 | 103 | emit pulse_output_started(); |
@@ -111,7 +124,7 @@ void DAQThread::run() | ||
111 | 124 | // int32 DAQmxBaseCreateCOPulseChanFreq (TaskHandle taskHandle, const char counter[ ], const char nameToAssignToChannel[ ], int32 units, int32 idleState, float64 initialDelay, float64 freq, float64 dutyCycle); |
112 | 125 | DAQmxErrChk (DAQmxBaseCreateCOPulseChanFreq (taskHandle, ctrname, "", DAQmx_Val_Hz, DAQmx_Val_Low, (float64)0.0, pulse_freq, pulse_duty)); |
113 | 126 | // int32 DAQmxBaseCfgImplicitTiming (TaskHandle taskHandle, int32 sampleMode, uInt64 sampsPerChanToAcquire); |
114 | - DAQmxErrChk (DAQmxBaseCfgImplicitTiming (taskHandle, DAQmx_Val_ContSamps, (uInt64)1)); | |
127 | + DAQmxErrChk (DAQmxBaseCfgImplicitTiming (taskHandle, cont_mode, pulse_count)); | |
115 | 128 | DAQmxErrChk (DAQmxBaseStartTask (taskHandle)); |
116 | 129 | } |
117 | 130 | break; |
@@ -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 continue_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, |
@@ -71,11 +71,16 @@ void MainWindow::on_pushButton_Output_clicked() | ||
71 | 71 | { |
72 | 72 | if (flag_output_status) { |
73 | 73 | DaqTh->stopPulseOutput(); |
74 | - ui->pushButton_Output->setText("ON"); | |
75 | - ui->comboBox_DevName->setEnabled(true); | |
76 | - flag_output_status = false; | |
74 | +// ui->pushButton_Output->setText("ON"); | |
75 | +// ui->comboBox_DevName->setEnabled(true); | |
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..."); |
@@ -133,6 +147,9 @@ void MainWindow::pulse_output_started() | ||
133 | 147 | |
134 | 148 | void MainWindow::pulse_output_stopped() |
135 | 149 | { |
150 | + ui->pushButton_Output->setText("ON"); | |
151 | + ui->comboBox_DevName->setEnabled(true); | |
152 | + flag_output_status = false; | |
153 | + | |
136 | 154 | ui->statusBar->showMessage("Idle..."); |
137 | 155 | } |
138 | - |
@@ -30,12 +30,15 @@ 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); |
36 | 38 | void pulse_output_started(); |
37 | 39 | void pulse_output_stopped(); |
38 | 40 | |
41 | + | |
39 | 42 | private: |
40 | 43 | Ui::MainWindow *ui; |
41 | 44 |
@@ -376,6 +376,63 @@ | ||
376 | 376 | <string>x Scale</string> |
377 | 377 | </property> |
378 | 378 | </widget> |
379 | + <widget class="QCheckBox" name="checkBox_ContMode"> | |
380 | + <property name="geometry"> | |
381 | + <rect> | |
382 | + <x>340</x> | |
383 | + <y>150</y> | |
384 | + <width>161</width> | |
385 | + <height>16</height> | |
386 | + </rect> | |
387 | + </property> | |
388 | + <property name="text"> | |
389 | + <string>Continue Output Pulse</string> | |
390 | + </property> | |
391 | + <property name="checked"> | |
392 | + <bool>true</bool> | |
393 | + </property> | |
394 | + </widget> | |
395 | + <widget class="QLabel" name="label_10"> | |
396 | + <property name="geometry"> | |
397 | + <rect> | |
398 | + <x>340</x> | |
399 | + <y>170</y> | |
400 | + <width>111</width> | |
401 | + <height>16</height> | |
402 | + </rect> | |
403 | + </property> | |
404 | + <property name="text"> | |
405 | + <string>Output Pulse Count</string> | |
406 | + </property> | |
407 | + </widget> | |
408 | + <widget class="QSpinBox" name="spinBox_PulseCount"> | |
409 | + <property name="enabled"> | |
410 | + <bool>false</bool> | |
411 | + </property> | |
412 | + <property name="geometry"> | |
413 | + <rect> | |
414 | + <x>340</x> | |
415 | + <y>190</y> | |
416 | + <width>121</width> | |
417 | + <height>22</height> | |
418 | + </rect> | |
419 | + </property> | |
420 | + <property name="wrapping"> | |
421 | + <bool>false</bool> | |
422 | + </property> | |
423 | + <property name="alignment"> | |
424 | + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
425 | + </property> | |
426 | + <property name="minimum"> | |
427 | + <number>1</number> | |
428 | + </property> | |
429 | + <property name="maximum"> | |
430 | + <number>214748647</number> | |
431 | + </property> | |
432 | + <property name="value"> | |
433 | + <number>1</number> | |
434 | + </property> | |
435 | + </widget> | |
379 | 436 | </widget> |
380 | 437 | <widget class="QMenuBar" name="menuBar"> |
381 | 438 | <property name="geometry"> |
@@ -383,7 +440,7 @@ | ||
383 | 440 | <x>0</x> |
384 | 441 | <y>0</y> |
385 | 442 | <width>562</width> |
386 | - <height>26</height> | |
443 | + <height>22</height> | |
387 | 444 | </rect> |
388 | 445 | </property> |
389 | 446 | </widget> |