• 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ão20ebf0996ad54d5d630ad75ecac639131c559ace (tree)
Hora2012-08-23 15:19:36
Autorarakaki <alucky4416@user...>
Commiterarakaki

Mensagem de Log

ADD: add Control (FreqDial, DutySlider) to UI.

Mudança Sumário

Diff

--- a/daqthread.cpp
+++ b/daqthread.cpp
@@ -29,7 +29,6 @@ void DAQThread::startPulseOutput(float freq, float duty)
2929 {
3030 pulse_freq = freq;
3131 pulse_duty = (float64)(duty / 100.0);
32- qDebug() << QString("freq = %1, ducy = %2").arg(pulse_freq).arg(pulse_duty);
3332 EvtQue->enqueue(Ev_Start);
3433 }
3534
@@ -42,7 +41,6 @@ void DAQThread::changePulseOutput(float freq, float duty)
4241 {
4342 pulse_freq = freq;
4443 pulse_duty = (float64)(duty / 100.0);
45- qDebug() << QString("freq = %1, ducy = %2").arg(pulse_freq).arg(pulse_duty);
4644 EvtQue->enqueue(Ev_ChgPulse);
4745 }
4846
@@ -84,16 +82,18 @@ void DAQThread::run()
8482 // int32 DAQmxBaseCfgImplicitTiming (TaskHandle taskHandle, int32 sampleMode, uInt64 sampsPerChanToAcquire);
8583 DAQmxErrChk (DAQmxBaseCfgImplicitTiming (taskHandle, DAQmx_Val_ContSamps, (uInt64)0));
8684 DAQmxErrChk (DAQmxBaseStartTask (taskHandle));
85+ emit pulse_output_started();
8786 state = State_OUTPUT;
8887 }
8988 break;
9089 case State_OUTPUT:
9190 if (event == Ev_Stop) {
92- qDebug() << "stop pulse output."; // stop Pulse
9391 DAQmxErrChk (DAQmxBaseStopTask (taskHandle));
9492 msleep(200);
9593 DAQmxErrChk (DAQmxBaseClearTask (taskHandle));
9694 taskHandle = 0;
95+ emit pulse_output_stopped();
96+ qDebug() << "stop pulse output."; // stop Pulse
9797 state = State_IDLE;
9898 } else if (event == Ev_ChgPulse) {
9999 qDebug() << QString("change pulse freq, duty : freq = %1, ducy = %2").arg(pulse_freq).arg(pulse_duty);
--- a/daqthread.h
+++ b/daqthread.h
@@ -25,6 +25,8 @@ signals:
2525 void daqmxbase_ready();
2626 void daqmxbase_final();
2727 void daqmxbase_error(QString errmsg);
28+ void pulse_output_started();
29+ void pulse_output_stopped();
2830
2931 protected:
3032 void run();
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,6 +1,7 @@
11 #include "mainwindow.h"
22 #include "ui_mainwindow.h"
33
4+#include <QDebug>
45 #include <QMessageBox>
56
67 MainWindow::MainWindow(QWidget *parent) :
@@ -8,10 +9,19 @@ MainWindow::MainWindow(QWidget *parent) :
89 ui(new Ui::MainWindow)
910 {
1011 ui->setupUi(this);
11- flag_output_status = false;
12+
13+ ui->statusBar->showMessage("DaqmxBase Initialize...");
1214 ui->pushButton_Output->setEnabled(false);
1315 ui->pushButton_Output->setText("ON");
1416
17+ ui->doubleSpinBox_Freq->setValue(1000.0);
18+ ui->dial_Freq->setValue(1000);
19+
20+ ui->doubleSpinBox_Duty->setValue(50.0);
21+ ui->horizontalSlider_Duty->setValue(50);
22+
23+ flag_output_status = false;
24+
1525 // Init & Start DAQ Thread
1626 DaqTh = new DAQThread(this);
1727 // connect signals
@@ -21,7 +31,11 @@ MainWindow::MainWindow(QWidget *parent) :
2131 this, SLOT(daqmxbase_final()));
2232 connect(DaqTh, SIGNAL(daqmxbase_error(QString)),
2333 this, SLOT(daqmxbase_error(QString)));
24- // DaqTh start
34+ connect(DaqTh, SIGNAL(pulse_output_started()),
35+ this, SLOT(pulse_output_started()));
36+ connect(DaqTh, SIGNAL(pulse_output_stopped()),
37+ this, SLOT(pulse_output_stopped()));
38+ // DaqTh start
2539 DaqTh->start();
2640 }
2741
@@ -50,23 +64,38 @@ void MainWindow::on_pushButton_Output_clicked()
5064
5165 void MainWindow::on_doubleSpinBox_Freq_valueChanged(double arg1)
5266 {
67+ ui->dial_Freq->setValue((int)arg1);
68+
5369 DaqTh->changePulseOutput((float)ui->doubleSpinBox_Freq->value(), (float)ui->doubleSpinBox_Duty->value());
5470 }
5571
72+void MainWindow::on_dial_Freq_valueChanged(int value)
73+{
74+ ui->doubleSpinBox_Freq->setValue((double)value);
75+}
5676
5777 void MainWindow::on_doubleSpinBox_Duty_valueChanged(double arg1)
5878 {
79+ ui->horizontalSlider_Duty->setValue((int)arg1);
80+
5981 DaqTh->changePulseOutput((float)ui->doubleSpinBox_Freq->value(), (float)ui->doubleSpinBox_Duty->value());
6082 }
6183
84+void MainWindow::on_horizontalSlider_Duty_valueChanged(int value)
85+{
86+ ui->doubleSpinBox_Duty->setValue((double)value);
87+}
88+
6289 void MainWindow::daqmxbase_ready()
6390 {
91+ ui->statusBar->showMessage("Idle...");
6492 ui->pushButton_Output->setEnabled(true);
6593 }
6694
6795 void MainWindow::daqmxbase_final()
6896 {
6997 ui->pushButton_Output->setEnabled(false);
98+ ui->statusBar->showMessage("DaqmxBase final.");
7099 }
71100
72101 void MainWindow::daqmxbase_error(QString ErrMsg)
@@ -74,3 +103,15 @@ void MainWindow::daqmxbase_error(QString ErrMsg)
74103 // Dialog
75104 QMessageBox::critical(this, "DaqmxBase Error", ErrMsg);
76105 }
106+
107+void MainWindow::pulse_output_started()
108+{
109+ ui->statusBar->showMessage("Output pulse.");
110+}
111+
112+void MainWindow::pulse_output_stopped()
113+{
114+ ui->statusBar->showMessage("Idle...");
115+}
116+
117+
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -24,9 +24,16 @@ private slots:
2424
2525 void on_doubleSpinBox_Duty_valueChanged(double arg1);
2626
27+ void on_dial_Freq_valueChanged(int value);
28+
29+ void on_horizontalSlider_Duty_valueChanged(int value);
30+
2731 void daqmxbase_ready();
2832 void daqmxbase_final();
2933 void daqmxbase_error(QString ErrMsg);
34+ void pulse_output_started();
35+ void pulse_output_stopped();
36+
3037
3138 private:
3239 Ui::MainWindow *ui;
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -6,8 +6,8 @@
66 <rect>
77 <x>0</x>
88 <y>0</y>
9- <width>400</width>
10- <height>300</height>
9+ <width>500</width>
10+ <height>439</height>
1111 </rect>
1212 </property>
1313 <property name="windowTitle">
@@ -17,17 +17,23 @@
1717 <widget class="QDoubleSpinBox" name="doubleSpinBox_Freq">
1818 <property name="geometry">
1919 <rect>
20- <x>40</x>
21- <y>70</y>
20+ <x>80</x>
21+ <y>200</y>
2222 <width>101</width>
2323 <height>31</height>
2424 </rect>
2525 </property>
26+ <property name="suffix">
27+ <string>Hz</string>
28+ </property>
2629 <property name="decimals">
2730 <number>0</number>
2831 </property>
2932 <property name="maximum">
30- <double>1000000000.000000000000000</double>
33+ <double>1000000.000000000000000</double>
34+ </property>
35+ <property name="singleStep">
36+ <double>1.000000000000000</double>
3137 </property>
3238 <property name="value">
3339 <double>1000.000000000000000</double>
@@ -37,11 +43,17 @@
3743 <property name="geometry">
3844 <rect>
3945 <x>40</x>
40- <y>50</y>
41- <width>101</width>
46+ <y>40</y>
47+ <width>121</width>
4248 <height>18</height>
4349 </rect>
4450 </property>
51+ <property name="font">
52+ <font>
53+ <weight>75</weight>
54+ <bold>true</bold>
55+ </font>
56+ </property>
4557 <property name="text">
4658 <string>Frequency(Hz)</string>
4759 </property>
@@ -49,8 +61,8 @@
4961 <widget class="QPushButton" name="pushButton_Output">
5062 <property name="geometry">
5163 <rect>
52- <x>190</x>
53- <y>100</y>
64+ <x>280</x>
65+ <y>190</y>
5466 <width>141</width>
5567 <height>51</height>
5668 </rect>
@@ -62,12 +74,15 @@
6274 <widget class="QDoubleSpinBox" name="doubleSpinBox_Duty">
6375 <property name="geometry">
6476 <rect>
65- <x>40</x>
66- <y>140</y>
77+ <x>80</x>
78+ <y>310</y>
6779 <width>101</width>
6880 <height>31</height>
6981 </rect>
7082 </property>
83+ <property name="suffix">
84+ <string>%</string>
85+ </property>
7186 <property name="decimals">
7287 <number>0</number>
7388 </property>
@@ -84,12 +99,18 @@
8499 <widget class="QLabel" name="label_2">
85100 <property name="geometry">
86101 <rect>
87- <x>190</x>
88- <y>80</y>
102+ <x>280</x>
103+ <y>170</y>
89104 <width>101</width>
90105 <height>18</height>
91106 </rect>
92107 </property>
108+ <property name="font">
109+ <font>
110+ <weight>75</weight>
111+ <bold>true</bold>
112+ </font>
113+ </property>
93114 <property name="text">
94115 <string>Output</string>
95116 </property>
@@ -98,11 +119,17 @@
98119 <property name="geometry">
99120 <rect>
100121 <x>40</x>
101- <y>120</y>
102- <width>101</width>
122+ <y>260</y>
123+ <width>81</width>
103124 <height>18</height>
104125 </rect>
105126 </property>
127+ <property name="font">
128+ <font>
129+ <weight>75</weight>
130+ <bold>true</bold>
131+ </font>
132+ </property>
106133 <property name="text">
107134 <string>Duty(%)</string>
108135 </property>
@@ -110,7 +137,7 @@
110137 <widget class="QLabel" name="label_4">
111138 <property name="geometry">
112139 <rect>
113- <x>40</x>
140+ <x>20</x>
114141 <y>10</y>
115142 <width>321</width>
116143 <height>18</height>
@@ -120,13 +147,117 @@
120147 <string>Simple PulseGenerator (DAQmxBase Counter)</string>
121148 </property>
122149 </widget>
150+ <widget class="QSlider" name="horizontalSlider_Duty">
151+ <property name="geometry">
152+ <rect>
153+ <x>40</x>
154+ <y>280</y>
155+ <width>160</width>
156+ <height>19</height>
157+ </rect>
158+ </property>
159+ <property name="minimum">
160+ <number>1</number>
161+ </property>
162+ <property name="value">
163+ <number>50</number>
164+ </property>
165+ <property name="orientation">
166+ <enum>Qt::Horizontal</enum>
167+ </property>
168+ <property name="tickPosition">
169+ <enum>QSlider::TicksBelow</enum>
170+ </property>
171+ </widget>
172+ <widget class="QDial" name="dial_Freq">
173+ <property name="geometry">
174+ <rect>
175+ <x>30</x>
176+ <y>60</y>
177+ <width>181</width>
178+ <height>131</height>
179+ </rect>
180+ </property>
181+ <property name="minimum">
182+ <number>1</number>
183+ </property>
184+ <property name="maximum">
185+ <number>1000000</number>
186+ </property>
187+ <property name="singleStep">
188+ <number>1000</number>
189+ </property>
190+ <property name="pageStep">
191+ <number>1</number>
192+ </property>
193+ <property name="value">
194+ <number>1000</number>
195+ </property>
196+ <property name="sliderPosition">
197+ <number>1000</number>
198+ </property>
199+ <property name="tracking">
200+ <bool>false</bool>
201+ </property>
202+ <property name="invertedControls">
203+ <bool>false</bool>
204+ </property>
205+ <property name="wrapping">
206+ <bool>false</bool>
207+ </property>
208+ <property name="notchTarget">
209+ <double>100.000000000000000</double>
210+ </property>
211+ <property name="notchesVisible">
212+ <bool>true</bool>
213+ </property>
214+ </widget>
215+ <widget class="QLabel" name="label_5">
216+ <property name="geometry">
217+ <rect>
218+ <x>290</x>
219+ <y>250</y>
220+ <width>191</width>
221+ <height>20</height>
222+ </rect>
223+ </property>
224+ <property name="text">
225+ <string>Output Pulse to Dev/ctr0</string>
226+ </property>
227+ </widget>
228+ <widget class="QLabel" name="label_6">
229+ <property name="geometry">
230+ <rect>
231+ <x>60</x>
232+ <y>170</y>
233+ <width>21</width>
234+ <height>18</height>
235+ </rect>
236+ </property>
237+ <property name="text">
238+ <string>1</string>
239+ </property>
240+ </widget>
241+ <widget class="QLabel" name="label_7">
242+ <property name="geometry">
243+ <rect>
244+ <x>170</x>
245+ <y>170</y>
246+ <width>61</width>
247+ <height>18</height>
248+ </rect>
249+ </property>
250+ <property name="text">
251+ <string>1000000</string>
252+ </property>
253+ </widget>
123254 </widget>
124255 <widget class="QMenuBar" name="menuBar">
125256 <property name="geometry">
126257 <rect>
127258 <x>0</x>
128259 <y>0</y>
129- <width>400</width>
260+ <width>500</width>
130261 <height>26</height>
131262 </rect>
132263 </property>