From e0f929fab3d020ae0659cb76beb9d1059f5a56a7 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Sun, 1 Oct 2023 17:15:57 +0800 Subject: [PATCH] no message --- global.h | 57 ++++++++++++++++++++++++---------------------- mainwindow.cpp | 24 +++++++++---------- mainwindow.cpp.rej | 13 +++++++++++ mainwindow.ui | 1 + subform.cpp | 10 ++++---- 5 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 mainwindow.cpp.rej diff --git a/global.h b/global.h index 5dfd6b2..fcb41e1 100644 --- a/global.h +++ b/global.h @@ -39,7 +39,7 @@ public: } ~ASyncReadData(){ if(mMod) - modbus_close(mMod); + modbus_close(mMod); } void Stop(){ mRuning = false; @@ -49,27 +49,30 @@ public: } void AddConfig(Config *c){ if(nullptr != c){ + mMux.lock(); for(auto itr = mConf.begin();itr != mConf.end(); itr++){ if (c == *itr){ + mMux.unlock(); return; } } this->mConf.append(c); + mMux.unlock(); } } void Run(void *v) override{ + // 读取1 float x = 0; while(mRuning){ + int count = 0; - int it = 0; - for(;it < mConf.size(); - it++){ + for(int it = 0;it < mConf.size();it++) { auto itr = mConf.at(it); uint16_t dat[10] = {0}; mMod = modbus_new_rtu(itr->com.toStdString().c_str(), - 57600, 'N', 8, 1); //相同的端口只能同时打开一个 + 57600, 'N', 8, 1); //相同的端口只能同时打开一个 modbus_set_debug(mMod,true); modbus_set_slave(mMod,itr->addr); //设置modbus从机地址 @@ -79,32 +82,32 @@ public: for(auto s = 0;s < itr->req.length();s++){ + QThread::msleep(1000); + int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat); - QThread::msleep(1000); - int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat); + mMux.lock(); + if(mListData.contains(itr->addr)){ + mListData[itr->addr]->push_front(new CapData{ + itr->addr, + float(float(dat[0])), + }); + }else{ + mListData[itr->addr] = new QList; + mListData[itr->addr]->push_front(new CapData{ + itr->addr, + float(float(dat[0])), + }); + } + x += 3.1415*2 /256; + + mMux.unlock(); - mMux.lock(); - if(mListData.contains(itr->addr)){ - mListData[itr->addr]->push_front(new CapData{ - itr->addr, - float(float(dat[0])), - }); - }else{ - mListData[itr->addr] = new QList; - mListData[itr->addr]->push_front(new CapData{ - itr->addr, - float(float(dat[0])), - }); } - x += 3.1415*2 /256; - - mMux.unlock(); - - } modbus_close(mMod); - } - QThread::msleep(1000*pcom->rate); - } + } + qDebug()<<"keep alive"; + QThread::msleep(100); + } // 读取2 } diff --git a/mainwindow.cpp b/mainwindow.cpp index 01725ea..bae4659 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -60,30 +60,28 @@ void MainWindow::on_pushButton_clicked() void MainWindow::on_pushButton_3_clicked() { + if(nullptr == gAsyncData){ + gAsyncData = new ASyncReadData(this); + connect(gAsyncData,&QSSASyncProcess::Done,[&](){ + qDebug()<<"done"; + }); + qDebug()<<"hello world"; + gAsyncData->Start(nullptr); + + } if(this->mForms.contains(ui->lineEdit_2->text())){ QMessageBox::warning(this,"�����Ѿ���","�����Ѿ���"); return; } - SubForm *p1 = new SubForm(ui->lineEdit_2->text(), + SubForm *p1 = new SubForm(ui->comboBox_2->currentText(), ui->comboBox->currentText().toInt(), ui->lineEdit_2->text().toInt()); qDebug()<lineEdit_2->text(); - ui->tabWidget->addTab((QWidget*)p1,"�豸��ַ:" + ui->lineEdit_2->text()); + ui->tabWidget->addTab((QWidget*)p1,"address:" + ui->lineEdit_2->text()); this->mForms[ui->lineEdit_2->text()] = p1; - if(nullptr == gAsyncData){ - gAsyncData = new ASyncReadData(this); - connect(gAsyncData,&QSSASyncProcess::Done,[&](){ - qDebug()<<"done"; - }); - } -// gAsyncData->AddConfig(new Config{ -// QString(ui->comboBox_2->currentText()), -// ui->lineEdit_2->text().toInt(), -// ui->lineEdit_3->text().toInt(), -// }); } diff --git a/mainwindow.cpp.rej b/mainwindow.cpp.rej new file mode 100644 index 0000000..916c0d3 --- /dev/null +++ b/mainwindow.cpp.rej @@ -0,0 +1,13 @@ +diff a/mainwindow.cpp b/mainwindow.cpp (rejected hunks) +@@ -79,6 +79,11 @@ + + } + ++// gAsyncData->AddConfig(new Config{ ++// QString(ui->comboBox_2->currentText()), ++// ui->lineEdit_2->text().toInt(), ++// ui->lineEdit_3->text().toInt(), ++// }); + + } + diff --git a/mainwindow.ui b/mainwindow.ui index bc1bc0e..1d93aa9 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -54,6 +54,7 @@ + Arial 12 diff --git a/subform.cpp b/subform.cpp index 4bd122e..5b9c3c4 100644 --- a/subform.cpp +++ b/subform.cpp @@ -27,13 +27,17 @@ SubForm::SubForm(QString addr,int baurate,int device_addr) mModel->setHorizontalHeaderLabels(QStringList() << "Ĵַ" << "ֵ"<<"ȡʱ"); ui->tableView->setModel(mModel); + mConfig = new Config; + mConfig->addr = device_addr; + mConfig->com = *com; + connect(pTimer,&QTimer::timeout,[=](){ static float sd = 0; if(gAsyncData == nullptr) return; CapData *z = new CapData; - int ret = gAsyncData->TakeLast((*com).toInt(),&z); + int ret = gAsyncData->TakeLast(device_addr,&z); if(ret == 0){ mSeries1->append(sd,z->val1); @@ -60,10 +64,8 @@ SubForm::SubForm(QString addr,int baurate,int device_addr) pTimer->start(100); qDebug()<lineEdit_2->setText(addr); + gAsyncData->AddConfig(this->mConfig); - mConfig = new Config; - mConfig->addr = device_addr; - mConfig->com = *com; } void SubForm::on_pushButton_clicked() {