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

@ -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,6 +52,7 @@ 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++){
if(mModel->item((i,j)) != nullptr){
qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole); qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole);
if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){ if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){
found = mModel->item((i,j)); found = mModel->item((i,j));
@ -59,25 +60,29 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
} }
} }
} }
// 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(); if(found == 0){
// mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间"); QStandardItem *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));
mModel->setItem(i, 0, item1);
mModel->setItem(i, 2, new QStandardItem(QString("%1").arg(z->time)));
}else{
mModel->item(found->row(),0)->setData(QString("%1").arg(z->addr),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);
}
sd ++; sd ++;
@ -85,6 +90,7 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
mMaxX += 1024; mMaxX += 1024;
mAxisX->setMax(mMaxX); mAxisX->setMax(mMaxX);
} }
delete z;
} }
}); });
pTimer->start(100); pTimer->start(100);