From 898ddfa63c1932b89d32fbfcd18c48c96ff50686 Mon Sep 17 00:00:00 2001 From: "Ryan@WorkStation" Date: Tue, 7 Feb 2023 15:55:39 -0500 Subject: [PATCH] some buttons is working at the scope --- .gitignore | 1 + .vscode/settings.json | 66 ++++++++++++++- ClassDigitizer2Gen.cpp | 10 +++ ClassDigitizer2Gen.h | 2 + mainwindow.cpp | 187 +++++++++++++++++++++++++++++++++-------- mainwindow.h | 6 ++ makeTest.sh | 28 ++++++ test.cpp | 9 +- 8 files changed, 272 insertions(+), 37 deletions(-) create mode 100644 makeTest.sh diff --git a/.gitignore b/.gitignore index 7e633f9..c5f2117 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ SOLARIS_DAQ *.sol programSettings.txt +test *~ *.autosave diff --git a/.vscode/settings.json b/.vscode/settings.json index 0650fea..439eb2b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,71 @@ "files.associations": { "script.C": "cpp", "SOLARIS_Qt6_DAQ.pro": "makefile", - "qlineseries": "cpp" + "qlineseries": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "variant": "cpp" }, "better-comments.multilineComments": true, diff --git a/ClassDigitizer2Gen.cpp b/ClassDigitizer2Gen.cpp index 9c9b70d..aac21a9 100644 --- a/ClassDigitizer2Gen.cpp +++ b/ClassDigitizer2Gen.cpp @@ -97,6 +97,11 @@ std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose){ return retValue; } +std::string Digitizer2Gen::ReadChValue(std::string ch, std::string shortPara, bool verbose){ + std::string haha = "/ch/" + ch + "/par/" + shortPara; + return ReadValue(haha.c_str(), verbose); +} + void Digitizer2Gen::WriteValue(const char * parameter, std::string value){ if( !isConnected ) return; printf(" %s| %-45s : %s\n", __func__, parameter, value.c_str()); @@ -107,6 +112,11 @@ void Digitizer2Gen::WriteValue(const char * parameter, std::string value){ } } +void Digitizer2Gen::WriteChValue(std::string ch, std::string shortPara, std::string value){ + std::string haha = "/ch/" + ch + "/par/" + shortPara; + WriteValue(haha.c_str(), value); +} + void Digitizer2Gen::SendCommand(const char * parameter){ if( !isConnected ) return; printf("Send Command : %s \n", parameter); diff --git a/ClassDigitizer2Gen.h b/ClassDigitizer2Gen.h index d7c9b15..6769d56 100644 --- a/ClassDigitizer2Gen.h +++ b/ClassDigitizer2Gen.h @@ -72,7 +72,9 @@ class Digitizer2Gen { int CloseDigitizer(); std::string ReadValue(const char * parameter, bool verbose = false); + std::string ReadChValue(std::string ch, std::string shortPara, bool verbose = false); void WriteValue(const char * parameter, std::string value); + void WriteChValue(std::string ch, std::string shortPara, std::string value); void SendCommand(const char * parameter); uint64_t GetHandle(const char * parameter); diff --git a/mainwindow.cpp b/mainwindow.cpp index cc3b280..fe01aaa 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -170,8 +170,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ if( OpenProgramSettings() ) OpenExpSettings(); - bnOpenScope->setEnabled(true); - } MainWindow::~MainWindow(){ @@ -333,44 +331,91 @@ void MainWindow::CloseDigitizers(){ //^###################################################################### Open Scope void MainWindow::OpenScope(){ - cbScopeDigi->clear(); ///thsi will also trigger QComboBox::currentIndexChanged cbScopeCh->clear(); if( digi ) { - 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. - + //*---- get digi setting int iDigi = cbScopeDigi->currentIndex(); int ch = cbScopeCh->currentIndex(); if( digi[iDigi]->IsDummy() ) return; + int index; + std::string ans; + + std::vector haha = {"WaveAnalogProbe0", "WaveAnalogProbe1"}; + + for( int i = 0 ; i < 2; i++){ + ans = digi[iDigi]->ReadChValue(std::to_string(ch), haha[i]); + index = cbAnaProbe[i]->findData(QString::fromStdString(ans)); + cbAnaProbe[i]->setCurrentIndex(index); + } + + haha.clear(); + haha = {"WaveDigitalProbe0", "WaveDigitalProbe1", "WaveDigitalProbe2", "WaveDigitalProbe3"}; + + for( int i = 0 ; i < 4; i++){ + ans = digi[iDigi]->ReadChValue(std::to_string(ch), haha[i]); + index = cbDigProbe[i]->findData(QString::fromStdString(ans)); + cbDigProbe[i]->setCurrentIndex(index); + } + + ans = digi[iDigi]->ReadChValue(std::to_string(ch), "ChRecordLengthT"); + sbRL->setValue(atoi(ans.c_str())); + + ans = digi[iDigi]->ReadChValue(std::to_string(ch), "ChPreTriggerT"); + sbPT->setValue(atoi(ans.c_str())); + + //TODO ===== Reset and ProgramPHA should be removed digi[iDigi]->Reset(); digi[iDigi]->ProgramPHA(false); - - digi[iDigi]->WriteValue("/ch/0..63/par/ChEnable", "false"); - digi[iDigi]->WriteValue(("/ch/" + std::to_string(ch) + "/par/ChEnable").c_str(), "true"); + + digi[iDigi]->WriteChValue("0..63", "ChEnable", "false"); + digi[iDigi]->WriteChValue(std::to_string(ch), "ChEnable", "true"); digi[iDigi]->SetPHADataFormat(0); - digi[iDigi]->StartACQ(); + StartScope(); - readDataThread[iDigi]->SetScopeRun(true); - readDataThread[iDigi]->start(); - - updateTraceThread->start(); bnStartACQ->setEnabled(false); bnStopACQ->setEnabled(false); + + } scope->show(); } + +void MainWindow::StartScope(){ + + if( !digi ) return; + + //*---- 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. + + int iDigi = cbScopeDigi->currentIndex(); + + digi[iDigi]->StartACQ(); + + readDataThread[iDigi]->SetScopeRun(true); + readDataThread[iDigi]->start(); + + updateTraceThread->start(); + + bnScopeStart->setEnabled(false); + bnScopeStop->setEnabled(true); + + sbRL->setEnabled(false); + + allowChange = true; + +} + void MainWindow::StopScope(){ updateTraceThread->Stop(); @@ -380,7 +425,9 @@ void MainWindow::StopScope(){ if(digi){ for(int i = 0; i < nDigi; i++){ if( digi[i]->IsDummy() ) continue; + digiMTX.lock(); digi[i]->StopACQ(); + digiMTX.unlock(); readDataThread[i]->quit(); readDataThread[i]->wait(); @@ -389,6 +436,11 @@ void MainWindow::StopScope(){ bnStopACQ->setEnabled(true); } + bnScopeStart->setEnabled(true); + bnScopeStop->setEnabled(false); + + sbRL->setEnabled(true); + } void MainWindow::UpdateScope(){ @@ -448,6 +500,17 @@ void MainWindow::ProbeChange(QComboBox * cb[], const int size ){ } } + digiMTX.lock(); + if( size == 2) {// analog probes + dataTrace->setName(cb[0]->currentText()); + } + if( size == 4){ // digitial probes + + } + + digiMTX.unlock(); + + } void MainWindow::SetUpPlot(){ //@--- this function run at start up @@ -456,10 +519,13 @@ void MainWindow::SetUpPlot(){ //@--- this function run at start up scope->setGeometry(0, 0, 1000, 800); scope->setWindowFlags( scope->windowFlags() & ~Qt::WindowCloseButtonHint ); + allowChange = false; + plot = new QChart(); dataTrace = new QLineSeries(); - dataTrace->setName("data"); + dataTrace->setName("Analog Trace 1"); for(int i = 0; i < 100; i ++) dataTrace->append(i, QRandomGenerator::global()->bounded(10)); + plot->addSeries(dataTrace); plot->createDefaultAxes(); /// this must be after addSeries(); plot->axes(Qt::Vertical).first()->setRange(-1, 11); /// this must be after createDefaultAxes(); @@ -491,6 +557,7 @@ void MainWindow::SetUpPlot(){ //@--- this function run at start up }); //------------ Probe selection + rowID ++; cbAnaProbe[0] = new QComboBox(scope); cbAnaProbe[0]->addItem("ADC Input", "ADCInput"); cbAnaProbe[0]->addItem("Time Filter", "TimeFiler"); @@ -504,20 +571,22 @@ void MainWindow::SetUpPlot(){ //@--- this function run at start up connect(cbAnaProbe[0], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbAnaProbe, 2);}); connect(cbAnaProbe[1], &QComboBox::currentIndexChanged, this, [=](){ this->ProbeChange(cbAnaProbe, 2);}); - //connect(cbAnaProbe[0], &QComboBox::currentIndexChanged, this, [=](){ - // int iDigi = cbScopeDigi->currentIndex(); - // int ch = cbScopeCh->currentIndex(); - // char str[200] = ("/ch/" + std::to_string(ch) + "/par/WaveAnalogProbe0").c_str(); - // digi[iDigi]->WriteValue(str, (cbAnaProbe[0]->currentData()).toString().toStdString()); - //}); - cbAnaProbe[0]->setCurrentIndex(1); ///trigger the AnaProbeChange cbAnaProbe[0]->setCurrentIndex(0); cbAnaProbe[1]->setCurrentIndex(4); + connect(cbAnaProbe[0], &QComboBox::currentIndexChanged, this, [=](){ + int iDigi = cbScopeDigi->currentIndex(); + int ch = cbScopeCh->currentIndex(); + digiMTX.lock(); + digi[iDigi]->WriteChValue(std::to_string(ch), "WaveAnalogProbe0", (cbAnaProbe[0]->currentData()).toString().toStdString()); + digiMTX.unlock(); + }); + + cbDigProbe[0] = new QComboBox(scope); cbDigProbe[0]->addItem("Trigger", "Trigger"); - cbDigProbe[0]->addItem("Time Filter Armed", "TimeFilerArmed"); + cbDigProbe[0]->addItem("Time Filter Armed", "TimeFilterArmed"); cbDigProbe[0]->addItem("ReTrigger Guard", "ReTriggerGaurd"); cbDigProbe[0]->addItem("Trap. basline Freeze", "EnergyFilterBaselineFreeze"); cbDigProbe[0]->addItem("Peaking", "EnergyFilterPeaking"); @@ -550,29 +619,77 @@ void MainWindow::SetUpPlot(){ //@--- this function run at start up cbDigProbe[2]->setCurrentIndex(5); cbDigProbe[3]->setCurrentIndex(6); - layout->addWidget(cbAnaProbe[0], rowID, 2); - layout->addWidget(cbAnaProbe[1], rowID, 3); + layout->addWidget(cbAnaProbe[0], rowID, 0); + layout->addWidget(cbAnaProbe[1], rowID, 1); + layout->addWidget(cbDigProbe[0], rowID, 2); + layout->addWidget(cbDigProbe[1], rowID, 3); + layout->addWidget(cbDigProbe[2], rowID, 4); + layout->addWidget(cbDigProbe[3], rowID, 5); + + //------------ wave settings 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); + QLabel * lbRL = new QLabel("Record Lenght [ns]",scope); + layout->addWidget(lbRL, rowID, 0); + sbRL = new QSpinBox(scope); + sbRL->setMinimum(32); + sbRL->setMaximum(648000); + sbRL->setSingleStep(8); + layout->addWidget(sbRL, rowID, 1); + + connect(sbRL, &QSpinBox::valueChanged, this, [=](){ + if( !allowChange ) return; + int iDigi = cbScopeDigi->currentIndex(); + digiMTX.lock(); + //StopScope(); + digi[iDigi]->WriteChValue(std::to_string(cbScopeCh->currentIndex()), + "ChRecordLengthT", + std::to_string(sbRL->value())); + //StartScope(); + digiMTX.unlock(); + + plot->axes(Qt::Horizontal).first()->setRange(0, sbRL->value()/8); + + }); + + QLabel * lbPT = new QLabel("Pre Trigger [ns]",scope); + layout->addWidget(lbPT, rowID, 2); + sbPT = new QSpinBox(scope); + sbPT->setMinimum(32); + sbPT->setMaximum(32000); + sbPT->setSingleStep(8); + layout->addWidget(sbPT, rowID, 3); + + QLabel * lbDCOffset = new QLabel("DC offset [%]",scope); + layout->addWidget(lbDCOffset, rowID, 4); + QSpinBox * sbDCOffset = new QSpinBox(scope); + sbDCOffset->setMinimum(0); + sbDCOffset->setMaximum(100); + sbDCOffset->setSingleStep(1); + layout->addWidget(sbDCOffset, rowID, 5); + + + //------------ plot view rowID ++; QChartView * plotView = new QChartView(plot); plotView->setRenderHints(QPainter::Antialiasing); - layout->addWidget(plotView, rowID, 0, 1, 4); + layout->addWidget(plotView, rowID, 0, 1, 6); //------------ close button rowID ++; - QPushButton * bnStop = new QPushButton("Stop", scope); - layout->addWidget(bnStop, rowID, 2); - connect(bnStop, &QPushButton::clicked, this, &MainWindow::StopScope); + bnScopeStart = new QPushButton("Start", scope); + layout->addWidget(bnScopeStart, rowID, 0); + bnScopeStart->setEnabled(false); + connect(bnScopeStart, &QPushButton::clicked, this, &MainWindow::StartScope); + + bnScopeStop = new QPushButton("Stop", scope); + layout->addWidget(bnScopeStop, rowID, 1); + connect(bnScopeStop, &QPushButton::clicked, this, &MainWindow::StopScope); QPushButton * bnClose = new QPushButton("Close", scope); - layout->addWidget(bnClose, rowID, 3); + layout->addWidget(bnClose, rowID, 5); connect(bnClose, &QPushButton::clicked, this, &MainWindow::StopScope); connect(bnClose, &QPushButton::clicked, scope, &QMainWindow::close); diff --git a/mainwindow.h b/mainwindow.h index 762a26f..5607998 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -114,6 +114,7 @@ private slots: void CloseDigitizers(); void OpenScope(); + void StartScope(); void StopScope(); void SetUpPlot(); void UpdateScope(); @@ -155,6 +156,11 @@ private: QComboBox * cbScopeCh; QComboBox * cbAnaProbe[2]; QComboBox * cbDigProbe[4]; + QSpinBox * sbRL; // record length + QSpinBox * sbPT; // pre trigger + QPushButton * bnScopeStart; + QPushButton * bnScopeStop; + bool allowChange; void ProbeChange(QComboBox * cb[], const int size); //@------ ACQ things diff --git a/makeTest.sh b/makeTest.sh new file mode 100644 index 0000000..13309ee --- /dev/null +++ b/makeTest.sh @@ -0,0 +1,28 @@ +CC="g++" +COPTS="-fPIC -DLINUX -O2 -std=c++17 -lpthread" +CAENLIBS="-lCAEN_FELib" +CURLLIBS="-lcurl" + +OBJS="ClassDigitizer2Gen.o influxdb.o" + +# +#ALL = test +# +################################################################ + +# +#test : test.cpp ClassDigitizer2Gen.o influxdb.o +# $(CC) $(COPTS) $(OBJS) -o test test.cpp $(CAENLIBS) $(CURLLIBS) +# +#ClassDigitizer2Gen.o : ClassDigitizer2Gen.cpp ClassDigitizer2Gen.h Event.h +# $(CC) $(COPTS) -c ClassDigitizer2Gen.cpp $(CAENLIBS) +# +#influxdb.o : influxdb.cpp influxdb.h +# $(CC) $(COPTS) -c influxdb.cpp $(CURLLIBS) + + + + +${CC} ${COPTS} -c influxdb.cpp ${CURLLIBS} +${CC} ${COPTS} -c ClassDigitizer2Gen.cpp ${CAENLIBS} +${CC} ${COPTS} ${OBJS} -o test test.cpp ${CAENLIBS} ${CURLLIBS} \ No newline at end of file diff --git a/test.cpp b/test.cpp index 3954c0b..5e71eb9 100644 --- a/test.cpp +++ b/test.cpp @@ -92,6 +92,8 @@ int main(int argc, char* argv[]){ digi->Reset(); digi->ProgramPHA(false); + printf("--------%s \n", digi->ReadChValue(0, "WaveAnalogprobe0", true).c_str()); + //printf("%s \n", digi->ReadValue("/ch/0/par/ChRealtimeMonitor").c_str()); //printf("%s \n", digi->ReadValue("/ch/0/par/Energy_Nbit").c_str()); //printf("%s \n", digi->ReadValue("/par/MaxRawDataSize").c_str()); @@ -119,7 +121,8 @@ int main(int argc, char* argv[]){ parHandle = digi->GetParentHandle(parHandle); printf("%lu|%lX\n", parHandle, parHandle); printf("%s\n", digi->GetPath(parHandle).c_str()); */ - + +/* digi->ReadDigitizerSettings(); digi->SetPHADataFormat(1); @@ -156,6 +159,10 @@ int main(int argc, char* argv[]){ (t1.tv_nsec-t0.tv_nsec + t1.tv_sec*1e+9 - t0.tv_sec*1e+9)*1.0/1e9); digi->CloseOutFile(); + +*/ + + digi->CloseDigitizer(); delete digi;