added program lock, only one instance
This commit is contained in:
parent
58dcd0d717
commit
31eefc2d92
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,6 +8,8 @@ programSettings.txt
|
||||||
EventKenshikushi
|
EventKenshikushi
|
||||||
DataGenerator
|
DataGenerator
|
||||||
DataReaderScript
|
DataReaderScript
|
||||||
|
pid.dat
|
||||||
|
DAQLock.dat
|
||||||
|
|
||||||
data
|
data
|
||||||
|
|
||||||
|
|
11
FSUDAQ.cpp
11
FSUDAQ.cpp
|
@ -337,6 +337,9 @@ MainWindow::~MainWindow(){
|
||||||
|
|
||||||
delete influx;
|
delete influx;
|
||||||
|
|
||||||
|
printf("-------- remove %s\n", DAQLockFile);
|
||||||
|
remove(DAQLockFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//***************************************************************
|
//***************************************************************
|
||||||
|
@ -984,7 +987,7 @@ void MainWindow::StartACQ(){
|
||||||
if( onlineAnalyzer ) onlineAnalyzer->StartThread();
|
if( onlineAnalyzer ) onlineAnalyzer->StartThread();
|
||||||
|
|
||||||
{//^=== elog and database
|
{//^=== elog and database
|
||||||
if( influx && chkSaveData->isChecked() ){
|
if( influx ){
|
||||||
influx->AddDataPoint("RunID value=" + std::to_string(runID));
|
influx->AddDataPoint("RunID value=" + std::to_string(runID));
|
||||||
influx->AddDataPoint("SavingData,ExpName=" + elogName.toStdString() + " value=1");
|
influx->AddDataPoint("SavingData,ExpName=" + elogName.toStdString() + " value=1");
|
||||||
influx->WriteData(dataBaseName.toStdString());
|
influx->WriteData(dataBaseName.toStdString());
|
||||||
|
@ -1055,7 +1058,7 @@ void MainWindow::StopACQ(){
|
||||||
cbAutoRun->setEnabled(true);
|
cbAutoRun->setEnabled(true);
|
||||||
|
|
||||||
{//^=== elog and database
|
{//^=== elog and database
|
||||||
if( influx && chkSaveData->isChecked() ){
|
if( influx ){
|
||||||
influx->AddDataPoint("SavingData,ExpName=" + elogName.toStdString() + " value=0");
|
influx->AddDataPoint("SavingData,ExpName=" + elogName.toStdString() + " value=0");
|
||||||
influx->WriteData(dataBaseName.toStdString());
|
influx->WriteData(dataBaseName.toStdString());
|
||||||
influx->ClearDataPointsBuffer();
|
influx->ClearDataPointsBuffer();
|
||||||
|
@ -1349,9 +1352,13 @@ void MainWindow::OpenScope(){
|
||||||
if( scope ) {
|
if( scope ) {
|
||||||
if( onOff ) {
|
if( onOff ) {
|
||||||
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
|
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
|
||||||
|
influx->AddDataPoint("SavingData,ExpName=" + elogName.toStdString() + " value=1");
|
||||||
}else{
|
}else{
|
||||||
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
|
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
|
||||||
|
influx->AddDataPoint("SavingData,ExpName=" + elogName.toStdString() + " value=0");
|
||||||
}
|
}
|
||||||
|
influx->WriteData(dataBaseName.toStdString());
|
||||||
|
influx->ClearDataPointsBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( canvas ){
|
if( canvas ){
|
||||||
|
|
3
macro.h
3
macro.h
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
#define SETTINGSIZE 2048
|
#define SETTINGSIZE 2048
|
||||||
|
|
||||||
|
#define DAQLockFile "DAQLock.dat"
|
||||||
|
#define PIDFile "pid.dat"
|
||||||
|
|
||||||
#include <sys/time.h> /** struct timeval, select() */
|
#include <sys/time.h> /** struct timeval, select() */
|
||||||
|
|
||||||
inline unsigned int get_time(){
|
inline unsigned int get_time(){
|
||||||
|
|
45
main.cpp
45
main.cpp
|
@ -1,10 +1,55 @@
|
||||||
#include "FSUDAQ.h"
|
#include "FSUDAQ.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
bool isLock = false;
|
||||||
|
int pid = 0;
|
||||||
|
QFile lockFile(DAQLockFile);
|
||||||
|
if( lockFile.open(QIODevice::Text | QIODevice::ReadOnly) ){
|
||||||
|
QTextStream in(&lockFile);
|
||||||
|
QString line = in.readLine();
|
||||||
|
isLock = line.toInt();
|
||||||
|
lockFile.close();
|
||||||
|
}
|
||||||
|
QFile pidFile(PIDFile);
|
||||||
|
if( pidFile.open(QIODevice::Text | QIODevice::ReadOnly)){
|
||||||
|
QTextStream in(&pidFile);
|
||||||
|
QString line = in.readLine();
|
||||||
|
pid = line.toInt();
|
||||||
|
pidFile.close();
|
||||||
|
}
|
||||||
|
if( isLock ) {
|
||||||
|
qDebug() << "The DAQ program is already opened. PID is " + QString::number(pid) + ", and delete the " + DAQLockFile ;
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setWindowTitle("Oopss....");
|
||||||
|
msgBox.setText("The DAQ program is already opened, or crashed perviously. \nPID is " + QString::number(pid) + "\n You can kill the procee by \"kill -9 <pid>\" and delete the " + DAQLockFile + "\n or click the \"Kill\" button");
|
||||||
|
msgBox.setIcon(QMessageBox::Information);
|
||||||
|
|
||||||
|
QPushButton * kill = msgBox.addButton("Kill and Open New", QMessageBox::AcceptRole);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
msgBox.exec();
|
||||||
|
if(msgBox.clickedButton() == kill){
|
||||||
|
remove(DAQLockFile);
|
||||||
|
QProcess::execute("kill", QStringList() << "-9" << QString::number(pid));
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lockFile.open(QIODevice::Text | QIODevice::WriteOnly);
|
||||||
|
lockFile.write( "1" );
|
||||||
|
lockFile.close();
|
||||||
|
pidFile.open(QIODevice::Text | QIODevice::WriteOnly);
|
||||||
|
pidFile.write( QString::number(QCoreApplication::applicationPid() ).toStdString().c_str() );
|
||||||
|
pidFile.close();
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user