can update a demo trace when started run.
This commit is contained in:
parent
42a4a5f0b0
commit
04be3f0776
|
@ -183,6 +183,11 @@ MainWindow::~MainWindow(){
|
||||||
//delete bnNewExp;
|
//delete bnNewExp;
|
||||||
//delete logInfo;
|
//delete logInfo;
|
||||||
|
|
||||||
|
updateTraceThread->Stop();
|
||||||
|
updateTraceThread->quit();
|
||||||
|
updateTraceThread->wait();
|
||||||
|
delete updateTraceThread;
|
||||||
|
|
||||||
delete dataTrace; /// dataTrace must be deleted before plot
|
delete dataTrace; /// dataTrace must be deleted before plot
|
||||||
delete plot;
|
delete plot;
|
||||||
|
|
||||||
|
@ -215,11 +220,17 @@ void MainWindow::StartACQ(){
|
||||||
bnStartACQ->setEnabled(false);
|
bnStartACQ->setEnabled(false);
|
||||||
bnStopACQ->setEnabled(true);
|
bnStopACQ->setEnabled(true);
|
||||||
|
|
||||||
|
updateTraceThread->start();
|
||||||
|
|
||||||
LogMsg("end of " + QString::fromStdString(__func__));
|
LogMsg("end of " + QString::fromStdString(__func__));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::StopACQ(){
|
void MainWindow::StopACQ(){
|
||||||
|
|
||||||
|
updateTraceThread->Stop();
|
||||||
|
updateTraceThread->quit();
|
||||||
|
updateTraceThread->wait();
|
||||||
|
|
||||||
for( int i = 0; i < nDigi; i++){
|
for( int i = 0; i < nDigi; i++){
|
||||||
if( digi[i]->IsDummy () ) continue;
|
if( digi[i]->IsDummy () ) continue;
|
||||||
digi[i]->StopACQ();
|
digi[i]->StopACQ();
|
||||||
|
@ -302,7 +313,6 @@ void MainWindow::CloseDigitizers(){
|
||||||
if( digiSetting != NULL ) digiSetting->close();
|
if( digiSetting != NULL ) digiSetting->close();
|
||||||
|
|
||||||
if( readDataThread[i] != NULL ){
|
if( readDataThread[i] != NULL ){
|
||||||
readDataThread[i]->Stop();
|
|
||||||
readDataThread[i]->quit();
|
readDataThread[i]->quit();
|
||||||
readDataThread[i]->wait();
|
readDataThread[i]->wait();
|
||||||
delete readDataThread[i];
|
delete readDataThread[i];
|
||||||
|
@ -320,10 +330,6 @@ void MainWindow::CloseDigitizers(){
|
||||||
//^###################################################################### Open Scope
|
//^###################################################################### Open Scope
|
||||||
void MainWindow::OpenScope(){
|
void MainWindow::OpenScope(){
|
||||||
|
|
||||||
QMainWindow * scope = new QMainWindow(this);
|
|
||||||
scope->setWindowTitle("Scope");
|
|
||||||
scope->setGeometry(0, 0, 1000, 800);
|
|
||||||
|
|
||||||
QWidget * layoutWidget = new QWidget(scope);
|
QWidget * layoutWidget = new QWidget(scope);
|
||||||
scope->setCentralWidget(layoutWidget);
|
scope->setCentralWidget(layoutWidget);
|
||||||
QGridLayout * layout = new QGridLayout(layoutWidget);
|
QGridLayout * layout = new QGridLayout(layoutWidget);
|
||||||
|
@ -343,7 +349,11 @@ void MainWindow::OpenScope(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::SetUpPlot(){
|
void MainWindow::SetUpPlot(){ //@--- this function run at start up
|
||||||
|
scope = new QMainWindow(this);
|
||||||
|
scope->setWindowTitle("Scope");
|
||||||
|
scope->setGeometry(0, 0, 1000, 800);
|
||||||
|
|
||||||
plot = new QChart();
|
plot = new QChart();
|
||||||
dataTrace = new QLineSeries();
|
dataTrace = new QLineSeries();
|
||||||
dataTrace->setName("data");
|
dataTrace->setName("data");
|
||||||
|
@ -352,12 +362,16 @@ void MainWindow::SetUpPlot(){
|
||||||
plot->createDefaultAxes(); /// this must be after addSeries();
|
plot->createDefaultAxes(); /// this must be after addSeries();
|
||||||
plot->axes(Qt::Vertical).first()->setRange(-1, 11); /// this must be after createDefaultAxes();
|
plot->axes(Qt::Vertical).first()->setRange(-1, 11); /// this must be after createDefaultAxes();
|
||||||
plot->axes(Qt::Horizontal).first()->setRange(-1, 101);
|
plot->axes(Qt::Horizontal).first()->setRange(-1, 101);
|
||||||
|
|
||||||
|
updateTraceThread = new UpdateTraceThread();
|
||||||
|
connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &MainWindow::UpdateScope);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::UpdateScope(){
|
void MainWindow::UpdateScope(){
|
||||||
|
|
||||||
//int nDataPoint = dataTrace->count();
|
if( scope->isVisible() == false) return;
|
||||||
//dataTrace->removePoints(0, 4);
|
|
||||||
for( int i = 0 ; i < dataTrace->count(); i++){
|
for( int i = 0 ; i < dataTrace->count(); i++){
|
||||||
dataTrace->replace(i, i, QRandomGenerator::global()->bounded(10));
|
dataTrace->replace(i, i, QRandomGenerator::global()->bounded(10));
|
||||||
}
|
}
|
||||||
|
|
57
mainwindow.h
57
mainwindow.h
|
@ -24,27 +24,15 @@
|
||||||
|
|
||||||
static QMutex digiMTX;
|
static QMutex digiMTX;
|
||||||
|
|
||||||
|
//^#===================================================== ReadData Thread
|
||||||
class ReadDataThread : public QThread {
|
class ReadDataThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
|
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
|
||||||
stop = false;
|
|
||||||
this->digi = dig;
|
this->digi = dig;
|
||||||
readCount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stop() {stop = true;}
|
|
||||||
|
|
||||||
void run(){
|
void run(){
|
||||||
clock_gettime(CLOCK_REALTIME, &ta);
|
clock_gettime(CLOCK_REALTIME, &ta);
|
||||||
readCount = 0;
|
|
||||||
|
|
||||||
//for( int i = 0; i < 10; i ++){
|
|
||||||
// emit sendMsg(QString::number(i));
|
|
||||||
// if( stop ) break;
|
|
||||||
//}
|
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
digiMTX.lock();
|
digiMTX.lock();
|
||||||
int ret = digi->ReadData();
|
int ret = digi->ReadData();
|
||||||
|
@ -60,32 +48,52 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &tb);
|
clock_gettime(CLOCK_REALTIME, &tb);
|
||||||
//if( readCount % 1000 == 0 ) {
|
|
||||||
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
||||||
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB");
|
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB");
|
||||||
|
|
||||||
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
|
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
|
||||||
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
|
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
|
||||||
ta = tb;
|
ta = tb;
|
||||||
}
|
}
|
||||||
readCount++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sendMsg(const QString &msg);
|
void sendMsg(const QString &msg);
|
||||||
|
private:
|
||||||
|
Digitizer2Gen * digi;
|
||||||
|
timespec ta, tb;
|
||||||
|
};
|
||||||
|
|
||||||
|
//^#===================================================== UpdateTrace Thread
|
||||||
|
class UpdateTraceThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
UpdateTraceThread(QObject * parent = 0) : QThread(parent){
|
||||||
|
waitTime = 5;
|
||||||
|
stop = false;
|
||||||
|
}
|
||||||
|
void Stop() {this->stop = true;}
|
||||||
|
void run(){
|
||||||
|
unsigned int count = 0;
|
||||||
|
stop = false;
|
||||||
|
do{
|
||||||
|
usleep(100000);
|
||||||
|
count ++;
|
||||||
|
if( count % waitTime == 0){
|
||||||
|
emit updateTrace();
|
||||||
|
}
|
||||||
|
}while(!stop);
|
||||||
|
}
|
||||||
|
signals:
|
||||||
|
void updateTrace();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool stop;
|
bool stop;
|
||||||
Digitizer2Gen * digi;
|
unsigned int waitTime; //100 of milisec
|
||||||
timespec ta, tb;
|
|
||||||
unsigned int readCount;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//=================================================
|
|
||||||
|
|
||||||
|
//^#===================================================== MainWindow
|
||||||
class MainWindow : public QMainWindow{
|
class MainWindow : public QMainWindow{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -118,7 +126,6 @@ private slots:
|
||||||
|
|
||||||
signals :
|
signals :
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QPushButton * bnProgramSettings;
|
QPushButton * bnProgramSettings;
|
||||||
|
@ -131,9 +138,11 @@ private:
|
||||||
QPushButton * bnDigiSettings;
|
QPushButton * bnDigiSettings;
|
||||||
QPushButton * bnSOLSettings;
|
QPushButton * bnSOLSettings;
|
||||||
|
|
||||||
|
QMainWindow * scope;
|
||||||
QPushButton * bnOpenScope;
|
QPushButton * bnOpenScope;
|
||||||
QChart * plot;
|
QChart * plot;
|
||||||
QLineSeries * dataTrace;
|
QLineSeries * dataTrace;
|
||||||
|
UpdateTraceThread * updateTraceThread;
|
||||||
|
|
||||||
QPushButton * bnStartACQ;
|
QPushButton * bnStartACQ;
|
||||||
QPushButton * bnStopACQ;
|
QPushButton * bnStopACQ;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user