diff --git a/global.h b/global.h index fcb41e1..f7329f1 100644 --- a/global.h +++ b/global.h @@ -25,6 +25,7 @@ typedef struct{ typedef struct T_Config{ QString com; + int baurate; int addr; int rate; QList req; @@ -72,12 +73,12 @@ public: auto itr = mConf.at(it); uint16_t dat[10] = {0}; mMod = modbus_new_rtu(itr->com.toStdString().c_str(), - 57600, 'N', 8, 1); //相同的端口只能同时打开一个 + itr->baurate, 'N', 8, 1); //相同的端口只能同时打开一个 modbus_set_debug(mMod,true); modbus_set_slave(mMod,itr->addr); //设置modbus从机地址 modbus_connect(mMod); - modbus_set_response_timeout(mMod,1000,1000); + modbus_set_response_timeout(mMod,1,1000); QThread::msleep(300); for(auto s = 0;s < itr->req.length();s++){ @@ -88,17 +89,16 @@ public: mMux.lock(); if(mListData.contains(itr->addr)){ mListData[itr->addr]->push_front(new CapData{ - itr->addr, + itr->req[s].addr, float(float(dat[0])), }); }else{ mListData[itr->addr] = new QList; mListData[itr->addr]->push_front(new CapData{ - itr->addr, + itr->req[s].addr, float(float(dat[0])), }); } - x += 3.1415*2 /256; mMux.unlock(); diff --git a/subform.cpp b/subform.cpp index 5b9c3c4..6e227f2 100644 --- a/subform.cpp +++ b/subform.cpp @@ -26,10 +26,12 @@ SubForm::SubForm(QString addr,int baurate,int device_addr) mModel = new QStandardItemModel(this); mModel->setHorizontalHeaderLabels(QStringList() << "Ĵַ" << "ֵ"<<"ȡʱ"); ui->tableView->setModel(mModel); - + ui->tableView->setSelectionMode(QAbstractItemView::ContiguousSelection); + ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); mConfig = new Config; mConfig->addr = device_addr; mConfig->com = *com; + mConfig->baurate = baurate; connect(pTimer,&QTimer::timeout,[=](){ static float sd = 0; @@ -43,15 +45,39 @@ SubForm::SubForm(QString addr,int baurate,int device_addr) pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss")); - mModel->clear(); - mModel->setHorizontalHeaderLabels(QStringList() << "Ĵַ" << "ֵ"<<"ȡʱ"); + QStandardItem *found = nullptr; + qDebug()<<"mModel->columnCount()"<columnCount() + <rowCount(); + int i = 0; + int j = 0; + for(;i < mModel->rowCount();i++){ + for(;j < mModel->columnCount();j++){ + qDebug()<item((i,j))->data(Qt::DisplayRole); + if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){ + found = mModel->item((i,j)); + break; + } + } + } - QStandardItem *item = new QStandardItem(QString("%1").arg(z->val1)); - mModel->setItem(0, 1, item); +// if(list.size() != 0){ +// found = list[0]; +// } + if(found == 0){ + QStandardItem *item = new QStandardItem(QString("%1").arg(z->val1)); + mModel->setItem(i, 1, item); + + QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr)); + mModel->setItem(i, 0, item1); + }else{ + mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole); + mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1),Qt::DisplayRole); + } + +// mModel->clear(); +// mModel->setHorizontalHeaderLabels(QStringList() << "Ĵַ" << "ֵ"<<"ȡʱ"); - QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr)); - mModel->setItem(0, 0, item1); sd ++;