From 5eeda7ab66faf991c1f565a336e6445fce967354 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Sun, 1 Oct 2023 02:23:57 +0800 Subject: [PATCH] no message --- global.h | 45 +++++++++++++++++++++------------------------ mainwindow.cpp | 23 ++++++++++------------- sub.ui | 6 +++++- subform.cpp | 16 +++++++++++++--- subform.h | 2 +- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/global.h b/global.h index 8480209..5dfd6b2 100644 --- a/global.h +++ b/global.h @@ -59,9 +59,6 @@ public: } } void Run(void *v) override{ - Config *pcom = (Config*)v; - qDebug()<<"start"<com; - // 读取1 float x = 0; while(mRuning){ @@ -71,8 +68,6 @@ public: it++){ auto itr = mConf.at(it); uint16_t dat[10] = {0}; - - mMod = modbus_new_rtu(itr->com.toStdString().c_str(), 57600, 'N', 8, 1); //相同的端口只能同时打开一个 @@ -82,30 +77,32 @@ public: modbus_set_response_timeout(mMod,1000,1000); QThread::msleep(300); - QThread::msleep(1000); - int ret = modbus_read_registers(mMod,1,1,dat); - - mMux.lock(); + for(auto s = 0;s < itr->req.length();s++){ - 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])), - }); + 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(); + } - x += 3.1415*2 /256; - - mMux.unlock(); modbus_close(mMod); } - QThread::msleep(1000*pcom->rate); } // 读取2 diff --git a/mainwindow.cpp b/mainwindow.cpp index 447ccaf..01725ea 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -61,13 +61,14 @@ void MainWindow::on_pushButton_clicked() void MainWindow::on_pushButton_3_clicked() { if(this->mForms.contains(ui->lineEdit_2->text())){ - QMessageBox::warning(this,"Ѿ","Ѿ"); + QMessageBox::warning(this,"�����Ѿ���","�����Ѿ���"); return; } SubForm *p1 = new SubForm(ui->lineEdit_2->text(), - ui->comboBox->currentText().toInt()); + 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,"�豸��ַ:" + ui->lineEdit_2->text()); this->mForms[ui->lineEdit_2->text()] = p1; if(nullptr == gAsyncData){ @@ -76,17 +77,13 @@ void MainWindow::on_pushButton_3_clicked() qDebug()<<"done"; }); - gAsyncData->Start(new Config{ - QString(ui->comboBox_2->currentText()), - ui->lineEdit_2->text().toInt(), - ui->lineEdit_3->text().toInt(), - }); } - gAsyncData->AddConfig(new Config{ - QString(ui->comboBox_2->currentText()), - ui->lineEdit_2->text().toInt(), - ui->lineEdit_3->text().toInt(), - }); + +// gAsyncData->AddConfig(new Config{ +// QString(ui->comboBox_2->currentText()), +// ui->lineEdit_2->text().toInt(), +// ui->lineEdit_3->text().toInt(), +// }); } diff --git a/sub.ui b/sub.ui index 0684123..33c123e 100644 --- a/sub.ui +++ b/sub.ui @@ -29,7 +29,11 @@ - + + + true + + diff --git a/subform.cpp b/subform.cpp index 191a5be..4bd122e 100644 --- a/subform.cpp +++ b/subform.cpp @@ -15,7 +15,7 @@ #endif -SubForm::SubForm(QString addr,int baurate) +SubForm::SubForm(QString addr,int baurate,int device_addr) :ui(new Ui::Form) { ui->setupUi(this); @@ -61,7 +61,9 @@ SubForm::SubForm(QString addr,int baurate) qDebug()<lineEdit_2->setText(addr); - + mConfig = new Config; + mConfig->addr = device_addr; + mConfig->com = *com; } void SubForm::on_pushButton_clicked() { @@ -197,6 +199,14 @@ void SubForm::on_pushButton_2_clicked(bool checked) { void SubForm::on_pushButton_2_clicked() { - + for(int i = 0;i < mConfig->req.length();i++){ + if(ui->lineEdit->text().toInt() == mConfig->req[i].addr){ + return; + } + } + mConfig->req.append(Req{ + ui->lineEdit->text().toUShort(), + ui->lineEdit_3->text().toUShort(), + }); } diff --git a/subform.h b/subform.h index 0ea47f1..a0c2dcd 100644 --- a/subform.h +++ b/subform.h @@ -27,7 +27,7 @@ class SubForm :QWidget { Q_OBJECT public: - SubForm(QString,int baurate); + SubForm(QString,int baurate,int device_addr); void init_charts(); private slots: