diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index 5f73092..96c479a 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -284,8 +284,9 @@ int Digitizer::ProgramBoard(){ int Digitizer::ProgramPHABoard(){ + printf("========Digitizer::%s\n", __func__); + ret = CAEN_DGTZ_Reset(handle); - printf("======== program board PHA\n"); ret = CAEN_DGTZ_WriteRegister(handle, DPP::RecordLength_G + 0x7000, 62); ret = CAEN_DGTZ_WriteRegister(handle, DPP::BoardConfiguration, 0x0F8915); /// has Extra2, dual trace, input and trap-baseline @@ -302,8 +303,6 @@ int Digitizer::ProgramPHABoard(){ ret = CAEN_DGTZ_SetRunSynchronizationMode(handle, CAEN_DGTZ_RUN_SYNC_Disabled); if( ret != 0 ) { printf("==== set board error.\n"); return 0;} - - printf("======== program Channels PHA\n"); uint32_t address; @@ -330,8 +329,6 @@ int Digitizer::ProgramPHABoard(){ if( ret != 0 ) { printf("==== set channels error.\n"); return 0;} - printf("End of program board and channels\n"); - isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard(); ReadAllSettingsFromBoard(); @@ -555,7 +552,7 @@ void Digitizer::ReadAllSettingsFromBoard(bool force){ if( AcqRun ) return; if( isSettingFilledinMemeory && !force) return; - printf("===== %s \n", __func__); + printf("===== Digitizer::%s \n", __func__); /// board setting for( int p = 0; p < (int) RegisterDPPList.size(); p++){ @@ -581,37 +578,44 @@ void Digitizer::ReadAllSettingsFromBoard(bool force){ } } isSettingFilledinMemeory = true; + + printf("---------------------- end of %s \n", __func__); + } void Digitizer::ProgramSettingsToBoard(){ - if( !isConnected ) return; - if( isDummy ) return; + if( !isConnected || isDummy ) return; + printf("========== %s \n", __func__); + Reg haha; /// board setting - for( int p = 0; p < (int) RegisterDPPList[p]; p++){ - if( RegisterDPPList[p].GetType() == RW::ReadONLY) continue; - haha = RegisterDPPList[p]; - WriteRegister(haha, GetSettingFromMemory(haha), -1, false); - usleep(100 * 1000); + for( int p = 0; p < (int) RegisterDPPList.size(); p++){ + if( RegisterDPPList[p].GetType() == RW::ReadWrite) { + haha = RegisterDPPList[p]; + WriteRegister(haha, GetSettingFromMemory(haha), -1, false); + usleep(1 * 1000); + } } /// Channels Setting for( int ch = 0; ch < NChannel; ch ++){ if( DPPType == V1730_DPP_PHA_CODE ){ - for( int p = 0; p < (int) RegisterPHAList[p]; p++){ - if( RegisterPHAList[p].GetType() == RW::ReadONLY) continue; - haha = RegisterPHAList[p]; - WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false); - usleep(100 * 1000); + for( int p = 0; p < (int) RegisterPHAList.size(); p++){ + if( RegisterPHAList[p].GetType() == RW::ReadWrite ){ + haha = RegisterPHAList[p]; + WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false); + usleep(1 * 1000); + } } } if( DPPType == V1730_DPP_PSD_CODE ){ - for( int p = 0; p < (int) RegisterPSDList[p]; p++){ - if( RegisterPSDList[p].GetType() == RW::ReadONLY) continue; - haha = RegisterPHAList[p]; - WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false); - usleep(100 * 1000); + for( int p = 0; p < (int) RegisterPSDList.size(); p++){ + if( RegisterPSDList[p].GetType() == RW::ReadWrite){ + haha = RegisterPHAList[p]; + WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false); + usleep(1 * 1000); + } } } } diff --git a/DigiSettingsPanel.cpp b/DigiSettingsPanel.cpp index 28814c3..1fa41ab 100644 --- a/DigiSettingsPanel.cpp +++ b/DigiSettingsPanel.cpp @@ -1229,21 +1229,21 @@ void DigiSettingsPanel::SaveSetting(int opt){ QDir dir(rawDataPath); if( !dir.exists() ) dir.mkpath("."); - QString filePath = QFileDialog::getSaveFileName(this, "Save Settings File", rawDataPath, opt == 0 ? "Data file (*.dat)" : "Text file (*.txt)"); + QString filePath = QFileDialog::getSaveFileName(this, "Save Settings File", rawDataPath, opt == 0 ? "Binary (*.bin)" : "Text file (*.txt)"); if (!filePath.isEmpty()) { QFileInfo fileInfo(filePath); QString ext = fileInfo.suffix(); if( opt == 0 ){ - if( ext == "") filePath += ".dat"; + if( ext == "") filePath += ".bin"; digi[ID]->SaveAllSettingsAsBin(filePath.toStdString().c_str()); - leSaveFilePath[ID]->setText(filePath + " | update constantly"); + leSaveFilePath[ID]->setText(filePath + " | dynamic update"); } if( opt == 1 ){ if( ext == "") filePath += ".txt"; digi[ID]->SaveAllSettingsAsText(filePath.toStdString().c_str()); - leSaveFilePath[ID]->setText(filePath); + leSaveFilePath[ID]->setText(filePath + " | not loadable!!"); } SendLogMsg("Saved setting file " + filePath + "."); @@ -1256,7 +1256,7 @@ void DigiSettingsPanel::LoadSetting(){ QFileDialog fileDialog(this); fileDialog.setDirectory(rawDataPath); fileDialog.setFileMode(QFileDialog::ExistingFile); - fileDialog.setNameFilter("Data file (*.dat);;"); + fileDialog.setNameFilter("Binary (*.bin);;"); int result = fileDialog.exec(); if( ! (result == QDialog::Accepted) ) return; @@ -1265,12 +1265,12 @@ void DigiSettingsPanel::LoadSetting(){ QString fileName = fileDialog.selectedFiles().at(0); - leSaveFilePath[ID]->setText(fileName); - - if( digi[ID]->LoadSettingBinaryToMemory(fileName.toStdString().c_str()) ){ + if( digi[ID]->LoadSettingBinaryToMemory(fileName.toStdString().c_str()) == 0 ){ SendLogMsg("Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber())); + leSaveFilePath[ID]->setText(fileName + " | dynamic update"); digi[ID]->ProgramSettingsToBoard(); UpdatePanelFromMemory(); + }else{ SendLogMsg("Fail to Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber())); } diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index ec41652..c138096 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -161,33 +161,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ programSettingsFilePath = QDir::current().absolutePath() + "/programSettings.txt"; LoadProgramSettings(); - { - scalar = new QMainWindow(this); - scalar->setWindowTitle("Scalar"); - - QScrollArea * scopeScroll = new QScrollArea(scalar); - scalar->setCentralWidget(scopeScroll); - scopeScroll->setWidgetResizable(true); - scopeScroll->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - QWidget * layoutWidget = new QWidget(scalar); - scopeScroll->setWidget(layoutWidget); - - scalarLayout = new QGridLayout(layoutWidget); - scalarLayout->setSpacing(0); - scalarLayout->setAlignment(Qt::AlignTop); - - leTrigger = nullptr; - leAccept = nullptr; - - lbLastUpdateTime = nullptr; - lbScalarACQStatus = nullptr; - - scalarThread = new TimingThread(); - connect(scalarThread, &TimingThread::timeUp, this, &MainWindow::UpdateScalar); - - } - //=========== disable widget WaitForDigitizersOpen(true); @@ -373,15 +346,30 @@ void MainWindow::OpenDigitizers(){ readDataThread = new ReadDataThread * [nDigi]; for( unsigned int i = 0; i < nDigi; i++){ digi[i] = new Digitizer(portList[i].first, portList[i].second); - //TODO === load settings digi[i]->Reset(); - digi[i]->ProgramPHABoard(); + + ///============== load settings + QString fileName = rawDataPath + "/Digi-" + QString::number(digi[i]->GetSerialNumber()) + ".bin"; + QFile file(fileName); + if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) { + LogMsg("" + fileName + " not found. Program predefined PHA settings."); //TODO, PSD? + digi[i]->ProgramPHABoard(); + }else{ + LogMsg("Found " + fileName + " for digitizer settings."); + + if( digi[i]->LoadSettingBinaryToMemory(fileName.toStdString().c_str()) == 0 ){ + LogMsg("Loaded settings file " + fileName + " for Digi-" + QString::number(digi[i]->GetSerialNumber())); + digi[i]->ProgramSettingsToBoard(); + + }else{ + LogMsg("Fail to Loaded settings file " + fileName + " for Digi-" + QString::number(digi[i]->GetSerialNumber())); + } + } + readDataThread[i] = new ReadDataThread(digi[i], i); connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg); } - digi[0]->SaveAllSettingsAsText("setting.txt"); - LogMsg(QString("Done. Opened %1 digitizer(s).").arg(nDigi)); WaitForDigitizersOpen(false); @@ -413,8 +401,6 @@ void MainWindow::CloseDigitizers(){ for(unsigned int i = 0; i < nDigi; i ++){ digi[i]->CloseDigitizer(); delete digi[i]; - digi[i] = nullptr; - delete readDataThread[i]; } delete [] digi; @@ -448,6 +434,30 @@ void MainWindow::WaitForDigitizersOpen(bool onOff){ //*************************************************************** void MainWindow::SetupScalar(){ + scalar = new QMainWindow(this); + scalar->setWindowTitle("Scalar"); + + QScrollArea * scopeScroll = new QScrollArea(scalar); + scalar->setCentralWidget(scopeScroll); + scopeScroll->setWidgetResizable(true); + scopeScroll->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QWidget * layoutWidget = new QWidget(scalar); + scopeScroll->setWidget(layoutWidget); + + scalarLayout = new QGridLayout(layoutWidget); + scalarLayout->setSpacing(0); + scalarLayout->setAlignment(Qt::AlignTop); + + leTrigger = nullptr; + leAccept = nullptr; + + lbLastUpdateTime = nullptr; + lbScalarACQStatus = nullptr; + + scalarThread = new TimingThread(); + connect(scalarThread, &TimingThread::timeUp, this, &MainWindow::UpdateScalar); + scalar->setGeometry(0, 0, 10 + nDigi * 180, 110 + MaxNChannels * 20); if( lbLastUpdateTime == nullptr ){