Scope panel

This commit is contained in:
Ryan Tang 2023-02-06 15:58:21 -05:00
parent 04be3f0776
commit 3bfcccb698
2 changed files with 157 additions and 22 deletions

View File

@ -9,9 +9,10 @@
#include <QFile> #include <QFile>
#include <QProcess> #include <QProcess>
#include <QRandomGenerator> #include <QRandomGenerator>
#include <QVariant>
#include <QChartView> #include <QChartView>
#include <QValueAxis> #include <QValueAxis>
#include <QStandardItemModel>
#include <unistd.h> #include <unistd.h>
@ -214,13 +215,14 @@ void MainWindow::StartACQ(){
digi[i]->StartACQ(); digi[i]->StartACQ();
//TODO ========================== Sync start. //TODO ========================== Sync start.
readDataThread[i]->SetScopeRun(false);
readDataThread[i]->start(); readDataThread[i]->start();
} }
bnStartACQ->setEnabled(false); bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(true); bnStopACQ->setEnabled(true);
updateTraceThread->start(); //updateTraceThread->start();
LogMsg("end of " + QString::fromStdString(__func__)); LogMsg("end of " + QString::fromStdString(__func__));
} }
@ -330,20 +332,22 @@ void MainWindow::CloseDigitizers(){
//^###################################################################### Open Scope //^###################################################################### Open Scope
void MainWindow::OpenScope(){ void MainWindow::OpenScope(){
QWidget * layoutWidget = new QWidget(scope); cbScopeDigi->clear(); ///thsi will also trigger QComboBox::currentIndexChanged
scope->setCentralWidget(layoutWidget); cbScopeCh->clear();
QGridLayout * layout = new QGridLayout(layoutWidget); if( nDigi > 0 && digi != NULL) {
layoutWidget->setLayout(layout); for( int i = 0 ; i < nDigi; i++) {
cbScopeDigi->addItem("Digi-" + QString::number(digi[i]->GetSerialNumber()), i);
//*---- set digitizer to take full trace; since in scope mode, no data saving, speed would be fast (How fast?)
//* when the input rate is faster than trigger rate, Digitizer will stop data taking.
QChartView * plotView = new QChartView(plot); //digi[i]->WriteValue();
plotView->setRenderHints(QPainter::Antialiasing); //readDataThread[i]->SetScopeRun(true);
//scope->setCentralWidget(plotView); }
layout->addWidget(plotView, 0, 0); //if( nDigi == 1 ) cbScopeDigi->setEnabled(false);
//updateTraceThread->start();
}
QPushButton * bnUpdate = new QPushButton("Random", scope);
layout->addWidget(bnUpdate, 1, 0);
connect(bnUpdate, &QPushButton::clicked, this, &MainWindow::UpdateScope);
scope->show(); scope->show();
@ -366,6 +370,124 @@ void MainWindow::SetUpPlot(){ //@--- this function run at start up
updateTraceThread = new UpdateTraceThread(); updateTraceThread = new UpdateTraceThread();
connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &MainWindow::UpdateScope); connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &MainWindow::UpdateScope);
//*================ ad Widgets
int rowID = -1;
QWidget * layoutWidget = new QWidget(scope);
scope->setCentralWidget(layoutWidget);
QGridLayout * layout = new QGridLayout(layoutWidget);
layoutWidget->setLayout(layout);
//------------ Digitizer + channel selection
rowID ++;
cbScopeDigi = new QComboBox(scope);
cbScopeCh = new QComboBox(scope);
layout->addWidget(cbScopeDigi, rowID, 0);
layout->addWidget(cbScopeCh, rowID, 1);
connect(cbScopeDigi, &QComboBox::currentIndexChanged, this, [=](){
int index = cbScopeDigi->currentIndex();
if( index == -1 ) return;
for( int i = 0; i < digi[index]->GetNChannels(); i++){
cbScopeCh->addItem("ch-" + QString::number(i), i);
}
});
//------------ Probe selection
cbAnaProbe[0] = new QComboBox(scope);
cbAnaProbe[0]->addItem("ADC Input");
cbAnaProbe[0]->addItem("Time Filter");
cbAnaProbe[0]->addItem("Trapazoid");
cbAnaProbe[0]->addItem("Trap. Baseline");
cbAnaProbe[0]->addItem("Trap. - Baseline");
cbAnaProbe[1] = new QComboBox(scope);
for( int i = 0; i < cbAnaProbe[0]->count() ; i++) cbAnaProbe[1]->addItem(cbAnaProbe[0]->itemText(i), cbAnaProbe[0]->itemData(i));
connect(cbAnaProbe[0], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbAnaProbe, 2);});
connect(cbAnaProbe[1], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbAnaProbe, 2);});
cbAnaProbe[0]->setCurrentIndex(1); ///trigger the AnaProbeChange
cbAnaProbe[0]->setCurrentIndex(0);
cbAnaProbe[1]->setCurrentIndex(4);
cbDigProbe[0] = new QComboBox(scope);
cbDigProbe[0]->addItem("Trigger");
cbDigProbe[0]->addItem("Time Filter Armed");
cbDigProbe[0]->addItem("ReTrigger Guard");
cbDigProbe[0]->addItem("Trap. basline Freeze");
cbDigProbe[0]->addItem("Peaking");
cbDigProbe[0]->addItem("Peak Ready");
cbDigProbe[0]->addItem("Pile-up Guard");
cbDigProbe[0]->addItem("ADC Saturate");
cbDigProbe[0]->addItem("ADC Sat. Protection");
cbDigProbe[0]->addItem("Post Sat. Event");
cbDigProbe[0]->addItem("Trap. Saturate");
cbDigProbe[0]->addItem("ACQ Inhibit");
cbDigProbe[1] = new QComboBox(scope);
cbDigProbe[2] = new QComboBox(scope);
cbDigProbe[3] = new QComboBox(scope);
for( int i = 0; i < cbDigProbe[0]->count() ; i++) {
cbDigProbe[1]->addItem(cbDigProbe[0]->itemText(i), cbDigProbe[0]->itemData(i));
cbDigProbe[2]->addItem(cbDigProbe[0]->itemText(i), cbDigProbe[0]->itemData(i));
cbDigProbe[3]->addItem(cbDigProbe[0]->itemText(i), cbDigProbe[0]->itemData(i));
}
connect(cbDigProbe[0], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbDigProbe, 4);});
connect(cbDigProbe[1], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbDigProbe, 4);});
connect(cbDigProbe[2], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbDigProbe, 4);});
connect(cbDigProbe[3], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbDigProbe, 4);});
cbDigProbe[0]->setCurrentIndex(1); ///trigger the DigProbeChange
cbDigProbe[0]->setCurrentIndex(0);
cbDigProbe[1]->setCurrentIndex(4);
cbDigProbe[2]->setCurrentIndex(5);
cbDigProbe[3]->setCurrentIndex(6);
layout->addWidget(cbAnaProbe[0], rowID, 2);
layout->addWidget(cbAnaProbe[1], rowID, 3);
rowID ++;
layout->addWidget(cbDigProbe[0], rowID, 0);
layout->addWidget(cbDigProbe[1], rowID, 1);
layout->addWidget(cbDigProbe[2], rowID, 2);
layout->addWidget(cbDigProbe[3], rowID, 3);
//------------ plot view
rowID ++;
QChartView * plotView = new QChartView(plot);
plotView->setRenderHints(QPainter::Antialiasing);
layout->addWidget(plotView, rowID, 0, 1, 4);
//------------ testing button
rowID ++;
QPushButton * bnUpdate = new QPushButton("Random", scope);
layout->addWidget(bnUpdate, rowID, 0);
connect(bnUpdate, &QPushButton::clicked, this, &MainWindow::UpdateScope);
}
void MainWindow::ProbeChange(QComboBox * cb[], const int size ){
QStandardItemModel * model[size] = {NULL};
for( int i = 0; i < size; i++){
model[i] = qobject_cast<QStandardItemModel*>(cb[i]->model());
}
/// Enable all items
for( int i = 0; i < cb[0]->count(); i++) {
for( int j = 0; j < size; j ++ ) model[j]->item(i)->setEnabled(true);
}
for( int i = 0; i < size; i++){
int index = cb[i]->currentIndex();
for( int j = 0; j < size; j++){
if( i == j ) continue;
model[j]->item(index)->setEnabled(false);
}
}
} }
void MainWindow::UpdateScope(){ void MainWindow::UpdateScope(){

View File

@ -10,6 +10,7 @@
#include <QDateTime> #include <QDateTime>
#include <QScrollBar> #include <QScrollBar>
#include <QPushButton> #include <QPushButton>
#include <QComboBox>
#include <QMutex> #include <QMutex>
#include <QChart> #include <QChart>
#include <QLineSeries> #include <QLineSeries>
@ -30,7 +31,9 @@ class ReadDataThread : public QThread {
public: public:
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){ ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
this->digi = dig; this->digi = dig;
isScopeRun = false;
} }
void SetScopeRun(bool onOff) {this->isScopeRun = onOff;}
void run(){ void run(){
clock_gettime(CLOCK_REALTIME, &ta); clock_gettime(CLOCK_REALTIME, &ta);
while(true){ while(true){
@ -39,7 +42,7 @@ public:
digiMTX.unlock(); digiMTX.unlock();
if( ret == CAEN_FELib_Success){ if( ret == CAEN_FELib_Success){
digi->SaveDataToFile(); if( !isScopeRun) digi->SaveDataToFile();
}else if(ret == CAEN_FELib_Stop){ }else if(ret == CAEN_FELib_Stop){
digi->ErrorMsg("No more data"); digi->ErrorMsg("No more data");
break; break;
@ -47,13 +50,15 @@ public:
digi->ErrorMsg("ReadDataLoop()"); digi->ErrorMsg("ReadDataLoop()");
} }
clock_gettime(CLOCK_REALTIME, &tb); if( !isScopeRun ){
if( tb.tv_sec - ta.tv_sec > 2 ) { clock_gettime(CLOCK_REALTIME, &tb);
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB"); if( tb.tv_sec - ta.tv_sec > 2 ) {
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB");
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration); //double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
ta = tb; //printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
ta = tb;
}
} }
} }
} }
@ -62,6 +67,7 @@ signals:
private: private:
Digitizer2Gen * digi; Digitizer2Gen * digi;
timespec ta, tb; timespec ta, tb;
bool isScopeRun;
}; };
//^#===================================================== UpdateTrace Thread //^#===================================================== UpdateTrace Thread
@ -138,12 +144,19 @@ private:
QPushButton * bnDigiSettings; QPushButton * bnDigiSettings;
QPushButton * bnSOLSettings; QPushButton * bnSOLSettings;
//@------ scope things
QMainWindow * scope; QMainWindow * scope;
QPushButton * bnOpenScope; QPushButton * bnOpenScope;
QChart * plot; QChart * plot;
QLineSeries * dataTrace; QLineSeries * dataTrace;
UpdateTraceThread * updateTraceThread; UpdateTraceThread * updateTraceThread;
QComboBox * cbScopeDigi;
QComboBox * cbScopeCh;
QComboBox * cbAnaProbe[2];
QComboBox * cbDigProbe[4];
void ProbeChange(QComboBox * cb[], const int size);
//@------ ACQ things
QPushButton * bnStartACQ; QPushButton * bnStartACQ;
QPushButton * bnStopACQ; QPushButton * bnStopACQ;
QLineEdit * leRunID; QLineEdit * leRunID;