can update a demo trace when started run.

This commit is contained in:
Ryan Tang 2023-02-03 18:58:35 -05:00
parent 42a4a5f0b0
commit 04be3f0776
2 changed files with 56 additions and 33 deletions

View File

@ -183,6 +183,11 @@ MainWindow::~MainWindow(){
//delete bnNewExp;
//delete logInfo;
updateTraceThread->Stop();
updateTraceThread->quit();
updateTraceThread->wait();
delete updateTraceThread;
delete dataTrace; /// dataTrace must be deleted before plot
delete plot;
@ -215,11 +220,17 @@ void MainWindow::StartACQ(){
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(true);
updateTraceThread->start();
LogMsg("end of " + QString::fromStdString(__func__));
}
void MainWindow::StopACQ(){
updateTraceThread->Stop();
updateTraceThread->quit();
updateTraceThread->wait();
for( int i = 0; i < nDigi; i++){
if( digi[i]->IsDummy () ) continue;
digi[i]->StopACQ();
@ -302,7 +313,6 @@ void MainWindow::CloseDigitizers(){
if( digiSetting != NULL ) digiSetting->close();
if( readDataThread[i] != NULL ){
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
delete readDataThread[i];
@ -320,10 +330,6 @@ void MainWindow::CloseDigitizers(){
//^###################################################################### Open Scope
void MainWindow::OpenScope(){
QMainWindow * scope = new QMainWindow(this);
scope->setWindowTitle("Scope");
scope->setGeometry(0, 0, 1000, 800);
QWidget * layoutWidget = new QWidget(scope);
scope->setCentralWidget(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();
dataTrace = new QLineSeries();
dataTrace->setName("data");
@ -352,12 +362,16 @@ void MainWindow::SetUpPlot(){
plot->createDefaultAxes(); /// this must be after addSeries();
plot->axes(Qt::Vertical).first()->setRange(-1, 11); /// this must be after createDefaultAxes();
plot->axes(Qt::Horizontal).first()->setRange(-1, 101);
updateTraceThread = new UpdateTraceThread();
connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &MainWindow::UpdateScope);
}
void MainWindow::UpdateScope(){
//int nDataPoint = dataTrace->count();
//dataTrace->removePoints(0, 4);
if( scope->isVisible() == false) return;
for( int i = 0 ; i < dataTrace->count(); i++){
dataTrace->replace(i, i, QRandomGenerator::global()->bounded(10));
}

View File

@ -24,27 +24,15 @@
static QMutex digiMTX;
//^#===================================================== ReadData Thread
class ReadDataThread : public QThread {
Q_OBJECT
public:
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
stop = false;
this->digi = dig;
readCount = 0;
}
void Stop() {stop = true;}
void run(){
clock_gettime(CLOCK_REALTIME, &ta);
readCount = 0;
//for( int i = 0; i < 10; i ++){
// emit sendMsg(QString::number(i));
// if( stop ) break;
//}
while(true){
digiMTX.lock();
int ret = digi->ReadData();
@ -60,32 +48,52 @@ public:
}
clock_gettime(CLOCK_REALTIME, &tb);
//if( readCount % 1000 == 0 ) {
if( tb.tv_sec - ta.tv_sec > 2 ) {
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;
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
ta = tb;
}
readCount++;
}
}
signals:
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:
bool stop;
Digitizer2Gen * digi;
timespec ta, tb;
unsigned int readCount;
unsigned int waitTime; //100 of milisec
};
//=================================================
//^#===================================================== MainWindow
class MainWindow : public QMainWindow{
Q_OBJECT
@ -118,7 +126,6 @@ private slots:
signals :
private:
QPushButton * bnProgramSettings;
@ -131,9 +138,11 @@ private:
QPushButton * bnDigiSettings;
QPushButton * bnSOLSettings;
QMainWindow * scope;
QPushButton * bnOpenScope;
QChart * plot;
QLineSeries * dataTrace;
UpdateTraceThread * updateTraceThread;
QPushButton * bnStartACQ;
QPushButton * bnStopACQ;