no message

master
zcy 2023-10-03 00:24:09 +08:00
parent 97d5df159d
commit 7407c74f76
2 changed files with 35 additions and 17 deletions

View File

@ -5,6 +5,7 @@
#include <QWidget> #include <QWidget>
#include <QDebug> #include <QDebug>
#include <QMutex> #include <QMutex>
#include <QDateTime>
extern "C"{ extern "C"{
#include "libmodbus/modbus.h" #include "libmodbus/modbus.h"
@ -14,6 +15,7 @@ typedef struct {
int addr; int addr;
float val1; float val1;
QString time; QString time;
bool succ;
}CapData; }CapData;
@ -86,17 +88,27 @@ public:
QThread::msleep(1000); QThread::msleep(1000);
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat); int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
mMux.lock(); mMux.lock();
bool succ = true;
if(mListData.contains(itr->addr)){ if(mListData.contains(itr->addr)){
if(ret < 0){
succ = false;
}
mListData[itr->addr]->push_front(new CapData{ mListData[itr->addr]->push_front(new CapData{
itr->req[s].addr, itr->req[s].addr,
float(float(dat[0])), float(float(dat[0])),
QDateTime::currentDateTime().toString("yyyy-mm-DD hh:MM::ss"),
true
}); });
}else{ }else{
mListData[itr->addr] = new QList<CapData *>; mListData[itr->addr] = new QList<CapData *>;
mListData[itr->addr]->push_front(new CapData{ mListData[itr->addr]->push_front(new CapData{
itr->req[s].addr, itr->req[s].addr,
float(float(dat[0])), float(float(dat[0])),
QDateTime::currentDateTime().toString("yyyy-mm-DD hh:MM::ss"),
succ
}); });
} }

View File

@ -33,7 +33,7 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
mConfig->com = *com; mConfig->com = *com;
mConfig->baurate = baurate; mConfig->baurate = baurate;
connect(pTimer,&QTimer::timeout,[=](){ connect(pTimer,&QTimer::timeout,[=]() {
static float sd = 0; static float sd = 0;
if(gAsyncData == nullptr) if(gAsyncData == nullptr)
return; return;
@ -41,8 +41,8 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
int ret = gAsyncData->TakeLast(device_addr,&z); int ret = gAsyncData->TakeLast(device_addr,&z);
if(ret == 0){ if(ret == 0){
bool succ = z->succ;
mSeries1->append(sd,z->val1); mSeries1->append(sd,z->val1);
pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss")); pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
QStandardItem *found = nullptr; QStandardItem *found = nullptr;
@ -52,39 +52,45 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
int j = 0; int j = 0;
for(;i < mModel->rowCount();i++){ for(;i < mModel->rowCount();i++){
for(;j < mModel->columnCount();j++){ for(;j < mModel->columnCount();j++){
qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole); if(mModel->item((i,j)) != nullptr){
if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){ qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole);
found = mModel->item((i,j)); if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){
break; found = mModel->item((i,j));
break;
}
} }
} }
} }
// if(list.size() != 0){
// found = list[0];
// }
if(found == 0){ if(found == 0){
QStandardItem *item = new QStandardItem(QString("%1").arg(z->val1)); QStandardItem *item;
mModel->setItem(i, 1, item); if(succ)
item = new QStandardItem(QString("%1").arg(z->val1));
else
item = new QStandardItem(QString("³¬Ê±"));
mModel->setItem(i, 1, item);
QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr)); QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr));
mModel->setItem(i, 0, item1); mModel->setItem(i, 0, item1);
mModel->setItem(i, 2, new QStandardItem(QString("%1").arg(z->time)));
}else{ }else{
mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),Qt::DisplayRole); 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); if(succ)
mModel->item(found->row(),1)->setData(QString("%1").arg(z->val1),Qt::DisplayRole);
else
mModel->item(found->row(),1)->setData(QString("³¬Ê±"),Qt::DisplayRole);
mModel->item(found->row(),2)->setData(QString("%1").arg(z->time),Qt::DisplayRole);
} }
// mModel->clear();
// mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间");
sd ++; sd ++;
if(sd > mMaxX){ if(sd > mMaxX){
mMaxX += 1024; mMaxX += 1024;
mAxisX->setMax(mMaxX); mAxisX->setMax(mMaxX);
} }
delete z;
} }
}); });
pTimer->start(100); pTimer->start(100);