no message

master
zcy 2023-10-02 01:54:37 +08:00
parent e0f929fab3
commit 97d5df159d
2 changed files with 38 additions and 12 deletions

View File

@ -25,6 +25,7 @@ typedef struct{
typedef struct T_Config{ typedef struct T_Config{
QString com; QString com;
int baurate;
int addr; int addr;
int rate; int rate;
QList<Req> req; QList<Req> req;
@ -72,12 +73,12 @@ public:
auto itr = mConf.at(it); auto itr = mConf.at(it);
uint16_t dat[10] = {0}; uint16_t dat[10] = {0};
mMod = modbus_new_rtu(itr->com.toStdString().c_str(), 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_debug(mMod,true);
modbus_set_slave(mMod,itr->addr); //设置modbus从机地址 modbus_set_slave(mMod,itr->addr); //设置modbus从机地址
modbus_connect(mMod); modbus_connect(mMod);
modbus_set_response_timeout(mMod,1000,1000); modbus_set_response_timeout(mMod,1,1000);
QThread::msleep(300); QThread::msleep(300);
for(auto s = 0;s < itr->req.length();s++){ for(auto s = 0;s < itr->req.length();s++){
@ -88,17 +89,16 @@ public:
mMux.lock(); mMux.lock();
if(mListData.contains(itr->addr)){ if(mListData.contains(itr->addr)){
mListData[itr->addr]->push_front(new CapData{ mListData[itr->addr]->push_front(new CapData{
itr->addr, itr->req[s].addr,
float(float(dat[0])), float(float(dat[0])),
}); });
}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->addr, itr->req[s].addr,
float(float(dat[0])), float(float(dat[0])),
}); });
} }
x += 3.1415*2 /256;
mMux.unlock(); mMux.unlock();

View File

@ -26,10 +26,12 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
mModel = new QStandardItemModel(this); mModel = new QStandardItemModel(this);
mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间"); mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间");
ui->tableView->setModel(mModel); ui->tableView->setModel(mModel);
ui->tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
mConfig = new Config; mConfig = new Config;
mConfig->addr = device_addr; mConfig->addr = device_addr;
mConfig->com = *com; mConfig->com = *com;
mConfig->baurate = baurate;
connect(pTimer,&QTimer::timeout,[=](){ connect(pTimer,&QTimer::timeout,[=](){
static float sd = 0; 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")); pTime.append(QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"));
mModel->clear(); QStandardItem *found = nullptr;
mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间"); qDebug()<<"mModel->columnCount()"<<mModel->columnCount()
<<mModel->rowCount();
int i = 0;
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;
}
}
}
QStandardItem *item = new QStandardItem(QString("%1").arg(z->val1)); // if(list.size() != 0){
mModel->setItem(0, 1, item); // 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 ++; sd ++;