no message
parent
e0f929fab3
commit
97d5df159d
10
global.h
10
global.h
|
@ -25,6 +25,7 @@ typedef struct{
|
|||
|
||||
typedef struct T_Config{
|
||||
QString com;
|
||||
int baurate;
|
||||
int addr;
|
||||
int rate;
|
||||
QList<Req> 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<CapData *>;
|
||||
mListData[itr->addr]->push_front(new CapData{
|
||||
itr->addr,
|
||||
itr->req[s].addr,
|
||||
float(float(dat[0])),
|
||||
});
|
||||
}
|
||||
x += 3.1415*2 /256;
|
||||
|
||||
mMux.unlock();
|
||||
|
||||
|
|
38
subform.cpp
38
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()"<<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(list.size() != 0){
|
||||
// found = list[0];
|
||||
// }
|
||||
|
||||
if(found == 0){
|
||||
QStandardItem *item = new QStandardItem(QString("%1").arg(z->val1));
|
||||
mModel->setItem(0, 1, item);
|
||||
|
||||
mModel->setItem(i, 1, item);
|
||||
|
||||
QStandardItem *item1 = new QStandardItem(QString("%1").arg(z->addr));
|
||||
mModel->setItem(0, 0, item1);
|
||||
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() << "寄存器地址" << "返回值"<<"读取时间");
|
||||
|
||||
|
||||
|
||||
sd ++;
|
||||
|
|
Loading…
Reference in New Issue