-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
272 lines (225 loc) · 7.12 KB
/
mainwindow.cpp
File metadata and controls
272 lines (225 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialogabout.h"
#include "dialogloadsettings.h"
#include "dialogsavesettings.h"
//following QStatusBartutorial
#include <QtGui>
#include <QtCore>
#include <QtWidgets>
//including the process to link to external source
#include <qprocess.h>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QFileDialog>
#include <QApplication>
#include <QTabWidget>
#include <visa.h> // include VISA header file
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionAbout_triggered()
{
dia_about = new DialogAbout(this);
dia_about->show();
}
void MainWindow::on_actionLoad_Settings_triggered()
{
//copy and paste from ORC project
QString pathplusfilename=QFileDialog::getOpenFileName(
this,
tr("Open File"),
"C://",
"All files (*.*)"
);
QFile myfile(pathplusfilename); // connect the file in disk to the memory block allocated for myfile
char firstSetting[128]; char secondSetting[128]; char thirdSetting[128]; char fourthSetting[128];
if (myfile.open(QFile::ReadOnly)){
// read the first line to a variable called firstSettings
qint64 lineLength = myfile.readLine(firstSetting,30);
if (lineLength != -1) ui->lineEdit->setText(firstSetting);
lineLength = myfile.readLine(secondSetting,30);
if (lineLength != -1) ui->lineEdit_2->setText(secondSetting);
lineLength = myfile.readLine(thirdSetting,40);
if (lineLength != -1) ui->lineEdit_3->setText(thirdSetting);
lineLength = myfile.readLine(fourthSetting,40);
if (lineLength != -1) ui->lineEdit_4->setText(fourthSetting);
}
}
void MainWindow::on_actionSave_Settings_triggered()
{
QString filename=QFileDialog::getSaveFileName(this, tr("Save File"), "C://", "All files (*.*)");
QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return;
QTextStream out(&file);
QString setting1 = ui->lineEdit->text();
out << setting1 << "\n";
QString setting2 = ui->lineEdit_2->text();
out << setting2 << "\n";
QString setting3 = ui->lineEdit_3->text();
out << setting3 << "\n";
QString setting4 = ui->lineEdit_4->text();
out << setting4 << "\n";
}
//Agilent VISA User's Guide
void MainWindow::on_actionLink_1_triggered()
{
QProcess *process = new QProcess(this);
QString command = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe";
QStringList args;
args<<"http://cp.literature.agilent.com/litweb/pdf/5188-5798.pdf";
process->start(command, args);
}
//Oscilloscope user's guide
void MainWindow::on_actionDigital_Oscilloscope_User_s_Guide_triggered()
{
QProcess *process = new QProcess(this);
QString command = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe";
QStringList args;
args<<"http://www.berkeleynucleonics.com/resources/Scope_Manual.pdf";
process->start(command, args);
}
//UltraSigma User's Guide
void MainWindow::on_actionUltraSigma_User_s_Guide_triggered()
{
QProcess *process = new QProcess(this);
QString command = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe";
QStringList args;
args<<"Need address here";
process->start(command, args);
}
void MainWindow::on_actionConnect_triggered()
{
// open resource manager
ViStatus stat = viOpenDefaultRM(&rscmng);
// search for the oscilloscope
ViChar viFound[VI_FIND_BUFLEN];
ViUInt32 nFound;
ViFindList listOfFound;
stat = viFindRsrc(rscmng, (ViString)"USB?*", &listOfFound, &nFound, viFound);
qDebug()<<stat;
if (stat!=0) {
ui->statusBar->showMessage("Please connect scope to PC");
viClose(rscmng);
return;
}
qDebug()<<nFound;
if (nFound==0) {
ui->statusBar->showMessage("No scope found");
viClose(rscmng);
return;
} else if (nFound>1) {
ui->statusBar->showMessage("More than 1 scopes found");
viClose(rscmng);
return;
}
qDebug()<<viFound;
// connect to the oscilloscope
ViUInt32 openTimeout=1000;
stat = viOpen(rscmng, viFound, VI_NULL, openTimeout, &osc);
if (stat!=0) return;
viSetAttribute(osc, VI_ATTR_TMO_VALUE, 1);//set timeout value
char buf[256] = {0};
// communicate
viPrintf(osc, (ViString)"*IDN?\n");
viScanf(osc,(ViString)"%t",&buf);
ui->statusBar->showMessage(buf);
}
void MainWindow::on_actionDisconnect_triggered()
{
// close VI sessions
viClose(osc);
viClose(rscmng);
}
void MainWindow::on_Run_clicked()
{
// Run
viPrintf(osc, (ViString)":RUN\n");
}
void MainWindow::on_Stop_clicked()
{
// Stop
viPrintf(osc, (ViString)":STOP\n");
}
void MainWindow::on_Autoscale_clicked()
{
viPrintf(osc, (ViString)":AUToscale\n");
}
void MainWindow::on_Single_clicked()
{
viPrintf(osc, (ViString)":SINGle\n");
}
void MainWindow::on_Aquire_clicked()
{
// set up wavform readout
viPrintf(osc, (ViString)":WAV:POIN:MODE RAW\n");
viPrintf(osc, (ViString)":WAV:FORM BYTE\n");
//viPrintf(osc, (ViString)":WAV:UNS ON\n");
viPrintf(osc, (ViString)":WAV:SOUR CHAN1\n");
viPrintf(osc, (ViString)":WAV:POIN 2000\n");
viPrintf(osc, (ViString)":WAV:POIN?\n");
char buf[128];
viScanf(osc,(ViString)"%t",&buf);
qDebug()<<buf;
// get data from osc
viSetAttribute(osc, VI_ATTR_TMO_VALUE, 1000);//set timeout value
char dat[10000] = {0};
ViStatus st;
st=viPrintf(osc, (ViString)":WAVeform:DATA?\n");
qDebug()<<st;
st=viScanf(osc,(ViString)"%t",&dat);
qDebug()<<st;
viPrintf(osc, (ViString)"*OPC?\n");
viScanf(osc,(ViString)"%t",&buf);
for (int i=0; i<10; i++) {
qDebug()<<dat[i];
}
//assign data to xy plot
int size = 2000;
QVector<double> x(size), y(size);
for (int i=0; i<size; i++)
{
x[i] = i;
y[i] = (double) dat[i+10];
qDebug()<<(double) dat[i+10];
}
ui->plot->addGraph();
ui->plot->graph(0)->setData(x,y);
// give the axes some labels
ui->plot->xAxis->setLabel("Timescale");
ui->plot->yAxis->setLabel("Voltage");
ui->plot->xAxis->setRange(0,2000);
ui->plot->yAxis->setRange(-128,128);
ui->plot->replot();
}
void MainWindow::on_ReadSettings_clicked()
{
char buf[256] = {0};
// Operation Complete
viPrintf(osc, (ViString)"*OPC?\n");
viScanf(osc,(ViString)"%t",&buf);
// Get x axis units; :TIMebase[:MAIN]:SCALe?
viPrintf(osc, (ViString)":tim:scal?\n");
viScanf(osc,(ViString)"%t", &buf);
ui->lineEdit->setText(buf);
// Get y axis scale maybe; :CHANnel<n>:SCALe?
viPrintf(osc, (ViString)":CHANnel1:SCALe?\n");
viScanf(osc, (ViString)"%t", &buf);
ui->lineEdit_2->setText(buf);
// Get Offset; :TIMebase[:MAIN]:OFFSet?
viPrintf(osc, (ViString)":TIMebase:RANGe?\n");
viScanf(osc, (ViString)"%t", &buf);
ui->lineEdit_3->setText(buf);
// Timebase:HREF:MODE?
viPrintf(osc, (ViString)":TIMebase:RANGe?\n");
viScanf(osc, (ViString)"%t", &buf);
ui->lineEdit_4->setText(buf);
}