• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Qt+MinGw環境でNIDAQmxを使ったパルス生成サンプル


Commit MetaInfo

修订版63321b4324512be0bf8614c9995455c8a62e851f (tree)
时间2012-11-09 23:29:37
作者arakaki <alucky4416@user...>
Commiterarakaki

Log Message

ADD: Add Widget: CheckBox for Select ContSamp/FiniteSamp mode.

更改概述

差异

--- a/daqthread.cpp
+++ b/daqthread.cpp
@@ -25,13 +25,15 @@ void DAQThread::stop()
2525 stopped = true;
2626 }
2727
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)
2929 {
3030 QString tmpname = devname + "/ctr0";
3131 // qDebug() << "counter name is " << tmpname;
3232 ctrname = tmpname.toLocal8Bit();
3333 pulse_freq = freq;
3434 pulse_duty = (float64)(duty / 100.0);
35+ cont_mode = continue_mode ? DAQmx_Val_ContSamps : DAQmx_Val_FiniteSamps;
36+ pulse_count = pulsecount;
3537 EvtQue->enqueue(Ev_Start);
3638 }
3739
@@ -79,12 +81,13 @@ void DAQThread::run()
7981 switch (state) {
8082 case State_IDLE:
8183 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);
8385 // int32 DAQmxBaseCreateCOPulseChanFreq (TaskHandle taskHandle, const char counter[ ], const char nameToAssignToChannel[ ], int32 units, int32 idleState, float64 initialDelay, float64 freq, float64 dutyCycle);
8486 DAQmxErrChk (DAQmxCreateTask("", &taskHandle));
8587 DAQmxErrChk (DAQmxCreateCOPulseChanFreq (taskHandle, ctrname, "", DAQmx_Val_Hz, DAQmx_Val_Low, (float64)0.0, pulse_freq, pulse_duty));
8688 // 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));
8891 DAQmxErrChk (DAQmxStartTask (taskHandle));
8992 emit pulse_output_started();
9093 state = State_OUTPUT;
@@ -119,7 +122,7 @@ void DAQThread::run()
119122 DAQmxErrChk (DAQmxClearTask (taskHandle));
120123 taskHandle = 0;
121124 emit pulse_output_stopped();
122- qDebug() << "stop pulse output."; // stop Pulse
125+ qDebug() << "done, stop pulse output."; // stop Pulse
123126 state = State_IDLE;
124127 }
125128 }
--- a/daqthread.h
+++ b/daqthread.h
@@ -15,7 +15,7 @@ public:
1515 ~DAQThread();
1616 void stop();
1717
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);
1919 void stopPulseOutput();
2020 void changePulseOutput(float freq, float duty);
2121
@@ -38,6 +38,8 @@ private:
3838 QByteArray ctrname; // = "Dev1/ctr0";
3939 float64 pulse_freq;
4040 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
4143
4244 // State Machine, state Id
4345 enum { State_IDLE = 0,
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -75,7 +75,12 @@ void MainWindow::on_pushButton_Output_clicked()
7575 ui->comboBox_DevName->setEnabled(true);
7676 flag_output_status = false;
7777 } 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());
7984 ui->pushButton_Output->setText("OFF");
8085 ui->comboBox_DevName->setEnabled(false);
8186 flag_output_status = true;
@@ -108,6 +113,15 @@ void MainWindow::on_horizontalSlider_Duty_valueChanged(int value)
108113 ui->doubleSpinBox_Duty->setValue((double)value);
109114 }
110115
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+
111125 void MainWindow::daqmxbase_ready()
112126 {
113127 ui->statusBar->showMessage("Idle...");
@@ -135,4 +149,3 @@ void MainWindow::pulse_output_stopped()
135149 {
136150 ui->statusBar->showMessage("Idle...");
137151 }
138-
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -30,6 +30,8 @@ private slots:
3030
3131 void on_horizontalSlider_Duty_valueChanged(int value);
3232
33+ void on_checkBox_ContMode_toggled(bool checked);
34+
3335 void daqmxbase_ready();
3436 void daqmxbase_final();
3537 void daqmxbase_error(QString ErrMsg);
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -22,15 +22,21 @@
2222 <rect>
2323 <x>80</x>
2424 <y>270</y>
25- <width>101</width>
25+ <width>91</width>
2626 <height>31</height>
2727 </rect>
2828 </property>
29+ <property name="alignment">
30+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
31+ </property>
2932 <property name="readOnly">
3033 <bool>true</bool>
3134 </property>
35+ <property name="buttonSymbols">
36+ <enum>QAbstractSpinBox::NoButtons</enum>
37+ </property>
3238 <property name="suffix">
33- <string>Hz</string>
39+ <string> Hz</string>
3440 </property>
3541 <property name="decimals">
3642 <number>0</number>
@@ -42,7 +48,7 @@
4248 <double>1.000000000000000</double>
4349 </property>
4450 <property name="value">
45- <double>1.000000000000000</double>
51+ <double>1000.000000000000000</double>
4652 </property>
4753 </widget>
4854 <widget class="QLabel" name="label">
@@ -68,7 +74,7 @@
6874 <property name="geometry">
6975 <rect>
7076 <x>340</x>
71- <y>250</y>
77+ <y>290</y>
7278 <width>141</width>
7379 <height>51</height>
7480 </rect>
@@ -86,8 +92,11 @@
8692 <height>31</height>
8793 </rect>
8894 </property>
95+ <property name="alignment">
96+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
97+ </property>
8998 <property name="suffix">
90- <string>%</string>
99+ <string> %</string>
91100 </property>
92101 <property name="decimals">
93102 <number>0</number>
@@ -106,7 +115,7 @@
106115 <property name="geometry">
107116 <rect>
108117 <x>340</x>
109- <y>230</y>
118+ <y>270</y>
110119 <width>101</width>
111120 <height>18</height>
112121 </rect>
@@ -222,7 +231,7 @@
222231 <property name="geometry">
223232 <rect>
224233 <x>350</x>
225- <y>310</y>
234+ <y>350</y>
226235 <width>191</width>
227236 <height>20</height>
228237 </rect>
@@ -318,6 +327,9 @@
318327 <height>28</height>
319328 </rect>
320329 </property>
330+ <property name="currentIndex">
331+ <number>3</number>
332+ </property>
321333 <property name="maxCount">
322334 <number>2147483645</number>
323335 </property>
@@ -376,6 +388,63 @@
376388 <string>x Scale</string>
377389 </property>
378390 </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>
379448 </widget>
380449 <widget class="QMenuBar" name="menuBar">
381450 <property name="geometry">