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 <QDebug>
#include <QMutex>
#include <QDateTime>
extern "C"{
#include "libmodbus/modbus.h"
@ -14,6 +15,7 @@ typedef struct {
int addr;
float val1;
QString time;
bool succ;
}CapData;
@ -86,17 +88,27 @@ public:
QThread::msleep(1000);
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
mMux.lock();
bool succ = true;
if(mListData.contains(itr->addr)){
if(ret < 0){
succ = false;
}
mListData[itr->addr]->push_front(new CapData{
itr->req[s].addr,
float(float(dat[0])),
QDateTime::currentDateTime().toString("yyyy-mm-DD hh:MM::ss"),
true
});
}else{
mListData[itr->addr] = new QList<CapData *>;
mListData[itr->addr]->push_front(new CapData{
itr->req[s].addr,
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->baurate = baurate;
connect(pTimer,&QTimer::timeout,[=](){
connect(pTimer,&QTimer::timeout,[=]() {
static float sd = 0;
if(gAsyncData == nullptr)
return;
@ -41,8 +41,8 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
int ret = gAsyncData->TakeLast(device_addr,&z);
if(ret == 0){
bool succ = z->succ;
mSeries1->append(sd,z->val1);
pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
QStandardItem *found = nullptr;
@ -52,39 +52,45 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
int j = 0;
for(;i < mModel->rowCount();i++){
for(;j < mModel->columnCount();j++){
qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole);
if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){
found = mModel->item((i,j));
break;
if(mModel->item((i,j)) != nullptr){
qDebug()<<mModel->item((i,j))->data(Qt::DisplayRole);
if(mModel->item((i,j))->data(Qt::DisplayRole).toInt() == z->addr){
found = mModel->item((i,j));
break;
}
}
}
}
// 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 *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);
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 ++;
if(sd > mMaxX){
mMaxX += 1024;
mAxisX->setMax(mMaxX);
}
delete z;
}
});
pTimer->start(100);