• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

QtSDK と NI-DAQmxBase (Linux) を使った単純なサンプル


Commit MetaInfo

Revisãoe8305f1a9058c8ef458912ad24c94ede126f9536 (tree)
Hora2012-12-08 18:31:13
Autorarakaki <alucky4416@user...>
Commiterarakaki

Mensagem de Log

ADD: Select ContSamp/FiniteSamp mode.

Mudança Sumário

Diff

--- 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
@@ -71,6 +73,17 @@ void DAQThread::run()
7173
7274 while(!stopped) {
7375 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+ }
7487 msleep(100);
7588 continue; // Jump to Next Loop
7689 }
@@ -84,7 +97,7 @@ void DAQThread::run()
8497 DAQmxErrChk (DAQmxBaseCreateTask("", &taskHandle));
8598 DAQmxErrChk (DAQmxBaseCreateCOPulseChanFreq (taskHandle, ctrname, "", DAQmx_Val_Hz, DAQmx_Val_Low, (float64)0.0, pulse_freq, pulse_duty));
8699 // 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));
88101 //DAQmxErrChk (DAQmxBaseExportSignal(taskHandle, DAQmx_Val_CounterOutputEvent, "/Dev1/PFI6")); // not worked! , default "/Dev1/PFI4"
89102 DAQmxErrChk (DAQmxBaseStartTask (taskHandle));
90103 emit pulse_output_started();
@@ -111,7 +124,7 @@ void DAQThread::run()
111124 // int32 DAQmxBaseCreateCOPulseChanFreq (TaskHandle taskHandle, const char counter[ ], const char nameToAssignToChannel[ ], int32 units, int32 idleState, float64 initialDelay, float64 freq, float64 dutyCycle);
112125 DAQmxErrChk (DAQmxBaseCreateCOPulseChanFreq (taskHandle, ctrname, "", DAQmx_Val_Hz, DAQmx_Val_Low, (float64)0.0, pulse_freq, pulse_duty));
113126 // 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));
115128 DAQmxErrChk (DAQmxBaseStartTask (taskHandle));
116129 }
117130 break;
--- 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 continue_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
@@ -71,11 +71,16 @@ void MainWindow::on_pushButton_Output_clicked()
7171 {
7272 if (flag_output_status) {
7373 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;
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...");
@@ -133,6 +147,9 @@ void MainWindow::pulse_output_started()
133147
134148 void MainWindow::pulse_output_stopped()
135149 {
150+ ui->pushButton_Output->setText("ON");
151+ ui->comboBox_DevName->setEnabled(true);
152+ flag_output_status = false;
153+
136154 ui->statusBar->showMessage("Idle...");
137155 }
138-
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -30,12 +30,15 @@ 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);
3638 void pulse_output_started();
3739 void pulse_output_stopped();
3840
41+
3942 private:
4043 Ui::MainWindow *ui;
4144
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -376,6 +376,63 @@
376376 <string>x Scale</string>
377377 </property>
378378 </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>
379436 </widget>
380437 <widget class="QMenuBar" name="menuBar">
381438 <property name="geometry">
@@ -383,7 +440,7 @@
383440 <x>0</x>
384441 <y>0</y>
385442 <width>562</width>
386- <height>26</height>
443+ <height>22</height>
387444 </rect>
388445 </property>
389446 </widget>