From e32cde9b4b222712e77f09bb3bd2852b1cc940a2 Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Fri, 17 Nov 2023 11:44:28 -0500 Subject: [PATCH] fixed crash when closing digitizer while Scope openned --- ClassDigitizer.cpp | 5 +++-- FSUDAQ.cpp | 13 ++++++------- Scope.cpp | 41 ++++++++++++++++++++++++++++++----------- Scope.h | 3 ++- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index f005a5e..26e2959 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -928,8 +928,9 @@ int Digitizer::LoadSettingBinaryToMemory(std::string fileName){ if( dummy != 0 ) printf("reach the end of file (read %ld).\n", dummy); uint32_t boardInfo = GetSettingFromMemory(DPP::BoardInfo_R); - if( (boardInfo & 0xFF) == 0x0E ) tick2ns = 4.0; - if( (boardInfo & 0xFF) == 0x0B ) tick2ns = 2.0; + if( (boardInfo & 0xFF) == 0x0E ) tick2ns = 4.0; // 725 + if( (boardInfo & 0xFF) == 0x0B ) tick2ns = 2.0; // 730 + if( (boardInfo & 0xFF) == 0x04 ) tick2ns = 16.0; // 740 ///Should seperate file<->memory, memory<->board ///ProgramSettingsToBoard(); /// do nothing if not connected. diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index ad410f5..e162f5a 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -719,17 +719,17 @@ void MainWindow::CloseDigitizers(){ LogMsg("MainWindow::Closing Digitizer(s)...."); - scalarThread->Stop(); - scalarThread->quit(); - scalarThread->exit(); - CleanUpScalar(); - if( scope ) { scope->close(); delete scope; scope = nullptr; } + scalarThread->Stop(); + scalarThread->quit(); + scalarThread->exit(); + CleanUpScalar(); + if( histThread){ histThread->Stop(); histThread->quit(); @@ -1016,7 +1016,7 @@ void MainWindow::UpdateScalar(){ influx->AddDataPoint("RunID value=" + std::to_string(runID)); influx->AddDataPoint("FileSize value=" + std::to_string(totalFileSize)); } - //influx->PrintDataPoints(); + //nflux->PrintDataPoints(); influx->WriteData(dataBaseName.toStdString()); influx->ClearDataPointsBuffer(); } @@ -1145,7 +1145,6 @@ void MainWindow::StopACQ(){ histThread->wait(); canvas->ClearInternalDataCount(); } - lbScalarACQStatus->setText("ACQ Off"); bnStartACQ->setEnabled(true); diff --git a/Scope.cpp b/Scope.cpp index 2e30ce1..77d171f 100644 --- a/Scope.cpp +++ b/Scope.cpp @@ -118,6 +118,12 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh updateTraceThread->SetWaitTimeinSec(ScopeUpdateMiliSec / 1000.); connect(updateTraceThread, &TimingThread::timeUp, this, &Scope::UpdateScope); + updateScalarThread = new TimingThread(); + updateScalarThread->SetWaitTimeinSec(2); + connect(updateScalarThread, &TimingThread::timeUp, this, [=](){ + emit UpdateScaler(); + }); + NullThePointers(); //*================================== UI @@ -305,6 +311,12 @@ Scope::~Scope(){ updateTraceThread->quit(); updateTraceThread->wait(); delete updateTraceThread; + + updateScalarThread->Stop(); + updateScalarThread->quit(); + updateScalarThread->wait(); + delete updateScalarThread; + for( int i = 0; i < MaxNumberOfTrace; i++) delete dataTrace[i]; delete plot; } @@ -358,7 +370,7 @@ void Scope::StartScope(){ digi[iDigi]->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1); digi[iDigi]->StartACQ(); - printf("----- readDataThread running ? %d.\n", readDataThread[iDigi]->isRunning()); +// printf("----- readDataThread running ? %d.\n", readDataThread[iDigi]->isRunning()); if( readDataThread[iDigi]->isRunning() ){ readDataThread[iDigi]->quit(); readDataThread[iDigi]->wait(); @@ -366,10 +378,14 @@ void Scope::StartScope(){ readDataThread[iDigi]->SetScopeMode(true); readDataThread[iDigi]->SetSaveData(false); readDataThread[iDigi]->start(); - printf("----- readDataThread running ? %d.\n", readDataThread[iDigi]->isRunning()); +// printf("----- readDataThread running ? %d.\n", readDataThread[iDigi]->isRunning()); } + printf("=========================== 1\n"); + updateTraceThread->start(); + updateScalarThread->start(); + printf("=========================== 2\n"); bnScopeStart->setEnabled(false); bnScopeStart->setStyleSheet(""); @@ -377,6 +393,7 @@ void Scope::StartScope(){ bnScopeStop->setStyleSheet("background-color: red;"); EnableControl(false); + printf("=========================== 3\n"); TellACQOnOff(true); @@ -392,6 +409,10 @@ void Scope::StopScope(){ updateTraceThread->quit(); updateTraceThread->exit(); + updateScalarThread->Stop(); + updateScalarThread->quit(); + updateScalarThread->exit(); + for( unsigned int iDigi = 0; iDigi < nDigi; iDigi ++){ if( readDataThread[iDigi]->isRunning() ){ @@ -501,18 +522,16 @@ void Scope::UpdateScope(){ } digiMTX[ID].unlock(); - if( data->TriggerRate[ch] == 0 ){ - dataTrace[0]->clear(); - dataTrace[1]->clear(); - dataTrace[2]->clear(); - dataTrace[3]->clear(); - dataTrace[4]->clear(); - } + // if( data->TriggerRate[ch] == 0 ){ + // dataTrace[0]->clear(); + // dataTrace[1]->clear(); + // dataTrace[2]->clear(); + // dataTrace[3]->clear(); + // dataTrace[4]->clear(); + // } plot->axes(Qt::Horizontal).first()->setRange(0, tick2ns * traceLength * factor); - emit UpdateScaler(); - } //*======================================================= diff --git a/Scope.h b/Scope.h index 3ab3d05..4a7b532 100644 --- a/Scope.h +++ b/Scope.h @@ -32,7 +32,7 @@ public: ~Scope(); void closeEvent(QCloseEvent * event){ - StopScope(); + if(isACQStarted) StopScope(); emit CloseWindow(); event->accept(); } @@ -84,6 +84,7 @@ private: ReadDataThread ** readDataThread; TimingThread * updateTraceThread; + TimingThread * updateScalarThread; bool enableSignalSlot;