From f6bbf0bf797bdcacd992a2f202798c3ecdaf172f Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS-DAQ" Date: Mon, 3 Apr 2023 18:20:36 -0400 Subject: [PATCH] few bugs fix. add RunTimeStamp.CSV --- ClassDigitizer2Gen.cpp | 15 +++++----- digiSettingsPanel.cpp | 4 ++- mainwindow.cpp | 68 ++++++++++++++++++++++++++++-------------- mainwindow.h | 2 +- scope.cpp | 5 ++-- 5 files changed, 61 insertions(+), 33 deletions(-) diff --git a/ClassDigitizer2Gen.cpp b/ClassDigitizer2Gen.cpp index c76151c..0fb1080 100644 --- a/ClassDigitizer2Gen.cpp +++ b/ClassDigitizer2Gen.cpp @@ -108,10 +108,10 @@ std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose){ //printf(" %s|%s \n", __func__, parameter); ret = CAEN_FELib_GetValue(handle, parameter, retValue); if (ret != CAEN_FELib_Success) { - printf("%-45s | read fail\n", parameter); + printf(" %s|%d|%-45s| read fail\n", __func__, serialNumber, parameter); return ErrorMsg(__func__); }else{ - if( verbose ) printf("%-45s : %s\n", parameter, retValue); + if( verbose ) printf(" %s|%d|%-45s:%s\n", __func__, serialNumber, parameter, retValue); } return retValue; } @@ -133,6 +133,7 @@ std::string Digitizer2Gen::ReadValue(const Reg para, int ch_index, bool verbose bool Digitizer2Gen::WriteValue(const char * parameter, std::string value){ if( !isConnected ) return false; + //ReadValue(parameter, 1); printf(" %s|%d|%-45s|%s|\n", __func__, serialNumber, parameter, value.c_str()); ret = CAEN_FELib_SetValue(handle, parameter, value.c_str()); if (ret != CAEN_FELib_Success) { @@ -776,7 +777,7 @@ int Digitizer2Gen::SaveSettingsToFile(const char * saveFileName, bool setReadOnl if( boardSettings[i].ReadWrite() == RW::WriteOnly) continue; totCount ++; if( boardSettings[i].GetValue() == "" && boardSettings[i].GetPara() != "Gateway") break; - fprintf(saveFile, "%-45s|%d|%4d|%s\n", boardSettings[i].GetFullPara().c_str(), + fprintf(saveFile, "%-45s!%d!%4d!%s\n", boardSettings[i].GetFullPara().c_str(), boardSettings[i].ReadWrite(), 8000 + i, boardSettings[i].GetValue().c_str()); @@ -786,7 +787,7 @@ int Digitizer2Gen::SaveSettingsToFile(const char * saveFileName, bool setReadOnl for(int i = 0; i < 4 ; i ++){ totCount ++; if( VGASetting[i].GetValue() == "" ) break; - fprintf(saveFile, "%-45s|%d|%4d|%s\n", VGASetting[i].GetFullPara(i).c_str(), + fprintf(saveFile, "%-45s!%d!%4d!%s\n", VGASetting[i].GetFullPara(i).c_str(), VGASetting[i].ReadWrite(), 9000 + i, VGASetting[i].GetValue().c_str()); @@ -797,7 +798,7 @@ int Digitizer2Gen::SaveSettingsToFile(const char * saveFileName, bool setReadOnl if( chSettings[ch][i].ReadWrite() == RW::WriteOnly) continue; totCount ++; if( chSettings[ch][i].GetValue() == "") break; - fprintf(saveFile, "%-45s|%d|%4d|%s\n", chSettings[ch][i].GetFullPara(ch).c_str(), + fprintf(saveFile, "%-45s!%d!%4d!%s\n", chSettings[ch][i].GetFullPara(ch).c_str(), chSettings[ch][i].ReadWrite(), ch*100 + i, chSettings[ch][i].GetValue().c_str()); @@ -847,7 +848,7 @@ bool Digitizer2Gen::LoadSettingsFromFile(const char * loadFileName){ while(fgets(line, sizeof(line), loadFile) != NULL){ //printf("%s", line); - char* token = std::strtok(line, "|"); + char* token = std::strtok(line, "!"); int count = 0; while( token != nullptr){ @@ -866,7 +867,7 @@ bool Digitizer2Gen::LoadSettingsFromFile(const char * loadFileName){ if( count > 3) break; count ++; - token = std::strtok(nullptr, "|"); + token = std::strtok(nullptr, "!"); } int id = atoi(idStr); diff --git a/digiSettingsPanel.cpp b/digiSettingsPanel.cpp index 927cd4e..010ec88 100644 --- a/digiSettingsPanel.cpp +++ b/digiSettingsPanel.cpp @@ -1662,7 +1662,9 @@ void DigiSettingsPanel::LoadSettings(){ fileDialog.setDirectory(digiSettingPath); fileDialog.setFileMode(QFileDialog::ExistingFile); fileDialog.setNameFilter("Data file (*.dat);;Text file (*.txt);;All file (*.*)"); - fileDialog.exec(); + int result = fileDialog.exec(); + + if( ! (result == QDialog::Accepted) ) return; if( fileDialog.selectedFiles().size() == 0 ) return; // when no file selected. diff --git a/mainwindow.cpp b/mainwindow.cpp index d2eec42..1c5d113 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -326,7 +326,7 @@ MainWindow::~MainWindow(){ } //^################################################################ ACQ control -void MainWindow::StartACQ(){ +int MainWindow::StartACQ(){ if( chkSaveRun->isChecked() ){ runID ++; @@ -363,7 +363,9 @@ void MainWindow::StartACQ(){ startComment = "Start Comment: " + startComment; }else{ LogMsg("Start Run aborted. "); - return; + runID --; + leRunID->setText(QString::number(runID)); + return 0 ; } if( cbAutoRun -> currentData().toInt() != 0 ){ @@ -435,6 +437,8 @@ void MainWindow::StartACQ(){ lbScalarACQStatus->setText("ACQ On"); scalarThread->start(); + return 1; + } void MainWindow::StopACQ(){ @@ -533,24 +537,26 @@ void MainWindow::StopACQ(){ void MainWindow::AutoRun(){ if( chkSaveRun->isChecked() == false){ - StartACQ(); - bnStartACQ->setEnabled(false); - bnStopACQ->setEnabled(true); - bnComment->setEnabled(false); - bnOpenScope->setEnabled(false); - chkSaveRun->setEnabled(false); - cbAutoRun->setEnabled(false); - if( digiSetting ) digiSetting->EnableControl(); + if( StartACQ() ){ + bnStartACQ->setEnabled(false); + bnStopACQ->setEnabled(true); + bnComment->setEnabled(false); + bnOpenScope->setEnabled(false); + chkSaveRun->setEnabled(false); + cbAutoRun->setEnabled(false); + if( digiSetting ) digiSetting->EnableControl(); + } return; } needManualComment = true; + int isRun = 0; ///=========== infinite single run if( cbAutoRun->currentData().toInt() == 0 ){ - StartACQ(); + isRun = StartACQ(); disconnect(runTimer, &QTimer::timeout, nullptr, nullptr); }else{ - StartACQ(); + isRun = StartACQ(); connect(runTimer, &QTimer::timeout, this, [=](){ StopACQ(); if( cbAutoRun->currentData().toInt() > 0 ) { @@ -569,6 +575,8 @@ void MainWindow::AutoRun(){ }); } + if( isRun == 0 ) return; + int timeMiliSec = cbAutoRun->currentData().toInt() * 60 * 1000; ///=========== single timed run @@ -624,7 +632,7 @@ void MainWindow::OpenDigitizers(){ connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg); //*------ search for settings_XXXX.dat - QString settingFile = analysisPath + "/Settings/setting_" + QString::number(digi[i]->GetSerialNumber()) + ".dat"; + QString settingFile = analysisPath + "/working/Settings/setting_" + QString::number(digi[i]->GetSerialNumber()) + ".dat"; if( digi[i]->LoadSettingsFromFile( settingFile.toStdString().c_str() ) ){ LogMsg("Found setting file " + settingFile + " and loading. please wait."); digi[i]->SetSettingFileName(settingFile.toStdString()); @@ -2029,19 +2037,35 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){ void MainWindow::WriteRunTimeStampDat(bool isStartRun){ - QFile file(dataPath + "/" + expName + "/RunTimeStampe.dat"); + QFile file(dataPath + "/" + expName + "/RunTimeStamp.dat"); - file.open(QIODevice::Text | QIODevice::WriteOnly | QIODevice::Append); - QString dateTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss"); + if( file.open(QIODevice::Text | QIODevice::WriteOnly | QIODevice::Append) ){ - if( isStartRun ){ - file.write(("Start Run | " + dateTime + " | " + startComment + "\n").toStdString().c_str()); - }else{ - file.write((" Stop Run | " + dateTime + " | " + stopComment + "\n").toStdString().c_str()); + if( isStartRun ){ + file.write(("Start Run | " + QString::number(runID) + " | " + dateTime + " | " + startComment + "\n").toStdString().c_str()); + }else{ + file.write((" Stop Run | " + QString::number(runID) + " | " + dateTime + " | " + stopComment + "\n").toStdString().c_str()); + } + + file.close(); + } + + + QFile fileCSV(dataPath + "/" + expName + "/RunTimeStamp.csv"); + + if( fileCSV.open(QIODevice::Text | QIODevice::WriteOnly | QIODevice::Append) ){ + + QTextStream out(&fileCSV); + + if( isStartRun){ + out << QString::number(runID) + "," + dateTime + "," + startComment; + }else{ + out << "," + dateTime + "," + stopComment + "\n"; + } + + fileCSV.close(); } - - file.close(); } diff --git a/mainwindow.h b/mainwindow.h index fffbf8c..9f34944 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,7 +51,7 @@ private slots: void OpenSOLARISpanel(); bool CheckSOLARISpanelOK(); - void StartACQ(); + int StartACQ(); // return 1 when ACQ start void StopACQ(); void AutoRun(); diff --git a/scope.cpp b/scope.cpp index 0a0dd22..cb512cd 100644 --- a/scope.cpp +++ b/scope.cpp @@ -72,13 +72,14 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat layout->addWidget(cbScopeCh, rowID, 1); connect(cbScopeDigi, &RComboBox::currentIndexChanged, this, [=](){ - //if( allowChange ) StopScope(); int index = cbScopeDigi->currentIndex(); if( index == -1 ) return; + allowChange = false; + cbScopeCh->clear(); for( int i = 0; i < digi[index]->GetNChannels(); i++){ cbScopeCh->addItem("ch-" + QString::number(i), i); } - //if( allowChange )StartScope(index); + allowChange = true; }); connect(cbScopeCh, &RComboBox::currentIndexChanged, this, [=](){