no message
parent
5eeda7ab66
commit
e0f929fab3
57
global.h
57
global.h
|
@ -39,7 +39,7 @@ public:
|
|||
}
|
||||
~ASyncReadData(){
|
||||
if(mMod)
|
||||
modbus_close(mMod);
|
||||
modbus_close(mMod);
|
||||
}
|
||||
void Stop(){
|
||||
mRuning = false;
|
||||
|
@ -49,27 +49,30 @@ public:
|
|||
}
|
||||
void AddConfig(Config *c){
|
||||
if(nullptr != c){
|
||||
mMux.lock();
|
||||
for(auto itr = mConf.begin();itr != mConf.end();
|
||||
itr++){
|
||||
if (c == *itr){
|
||||
mMux.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->mConf.append(c);
|
||||
mMux.unlock();
|
||||
}
|
||||
}
|
||||
void Run(void *v) override{
|
||||
|
||||
// 读取1
|
||||
float x = 0;
|
||||
while(mRuning){
|
||||
int count = 0;
|
||||
|
||||
int it = 0;
|
||||
for(;it < mConf.size();
|
||||
it++){
|
||||
for(int it = 0;it < mConf.size();it++) {
|
||||
auto itr = mConf.at(it);
|
||||
uint16_t dat[10] = {0};
|
||||
mMod = modbus_new_rtu(itr->com.toStdString().c_str(),
|
||||
57600, 'N', 8, 1); //相同的端口只能同时打开一个
|
||||
57600, 'N', 8, 1); //相同的端口只能同时打开一个
|
||||
|
||||
modbus_set_debug(mMod,true);
|
||||
modbus_set_slave(mMod,itr->addr); //设置modbus从机地址
|
||||
|
@ -79,32 +82,32 @@ public:
|
|||
|
||||
for(auto s = 0;s < itr->req.length();s++){
|
||||
|
||||
QThread::msleep(1000);
|
||||
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
|
||||
|
||||
QThread::msleep(1000);
|
||||
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
|
||||
mMux.lock();
|
||||
if(mListData.contains(itr->addr)){
|
||||
mListData[itr->addr]->push_front(new CapData{
|
||||
itr->addr,
|
||||
float(float(dat[0])),
|
||||
});
|
||||
}else{
|
||||
mListData[itr->addr] = new QList<CapData *>;
|
||||
mListData[itr->addr]->push_front(new CapData{
|
||||
itr->addr,
|
||||
float(float(dat[0])),
|
||||
});
|
||||
}
|
||||
x += 3.1415*2 /256;
|
||||
|
||||
mMux.unlock();
|
||||
|
||||
mMux.lock();
|
||||
if(mListData.contains(itr->addr)){
|
||||
mListData[itr->addr]->push_front(new CapData{
|
||||
itr->addr,
|
||||
float(float(dat[0])),
|
||||
});
|
||||
}else{
|
||||
mListData[itr->addr] = new QList<CapData *>;
|
||||
mListData[itr->addr]->push_front(new CapData{
|
||||
itr->addr,
|
||||
float(float(dat[0])),
|
||||
});
|
||||
}
|
||||
x += 3.1415*2 /256;
|
||||
|
||||
mMux.unlock();
|
||||
|
||||
}
|
||||
modbus_close(mMod);
|
||||
}
|
||||
QThread::msleep(1000*pcom->rate);
|
||||
}
|
||||
}
|
||||
qDebug()<<"keep alive";
|
||||
QThread::msleep(100);
|
||||
}
|
||||
// 读取2
|
||||
}
|
||||
|
||||
|
|
|
@ -60,30 +60,28 @@ void MainWindow::on_pushButton_clicked()
|
|||
|
||||
void MainWindow::on_pushButton_3_clicked()
|
||||
{
|
||||
if(nullptr == gAsyncData){
|
||||
gAsyncData = new ASyncReadData(this);
|
||||
connect(gAsyncData,&QSSASyncProcess::Done,[&](){
|
||||
qDebug()<<"done";
|
||||
});
|
||||
qDebug()<<"hello world";
|
||||
gAsyncData->Start(nullptr);
|
||||
|
||||
}
|
||||
if(this->mForms.contains(ui->lineEdit_2->text())){
|
||||
QMessageBox::warning(this,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
SubForm *p1 = new SubForm(ui->lineEdit_2->text(),
|
||||
SubForm *p1 = new SubForm(ui->comboBox_2->currentText(),
|
||||
ui->comboBox->currentText().toInt(),
|
||||
ui->lineEdit_2->text().toInt());
|
||||
qDebug()<<ui->lineEdit_2->text();
|
||||
ui->tabWidget->addTab((QWidget*)p1,"<EFBFBD>豸<EFBFBD><EFBFBD>ַ:" + ui->lineEdit_2->text());
|
||||
ui->tabWidget->addTab((QWidget*)p1,"address:" + ui->lineEdit_2->text());
|
||||
this->mForms[ui->lineEdit_2->text()] = p1;
|
||||
|
||||
if(nullptr == gAsyncData){
|
||||
gAsyncData = new ASyncReadData(this);
|
||||
connect(gAsyncData,&QSSASyncProcess::Done,[&](){
|
||||
qDebug()<<"done";
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// gAsyncData->AddConfig(new Config{
|
||||
// QString(ui->comboBox_2->currentText()),
|
||||
// ui->lineEdit_2->text().toInt(),
|
||||
// ui->lineEdit_3->text().toInt(),
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
diff a/mainwindow.cpp b/mainwindow.cpp (rejected hunks)
|
||||
@@ -79,6 +79,11 @@
|
||||
|
||||
}
|
||||
|
||||
+// gAsyncData->AddConfig(new Config{
|
||||
+// QString(ui->comboBox_2->currentText()),
|
||||
+// ui->lineEdit_2->text().toInt(),
|
||||
+// ui->lineEdit_3->text().toInt(),
|
||||
+// });
|
||||
|
||||
}
|
||||
|
|
@ -54,6 +54,7 @@
|
|||
<widget class="QComboBox" name="comboBox_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
|
|
10
subform.cpp
10
subform.cpp
|
@ -27,13 +27,17 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
|
|||
mModel->setHorizontalHeaderLabels(QStringList() << "寄存器地址" << "返回值"<<"读取时间");
|
||||
ui->tableView->setModel(mModel);
|
||||
|
||||
mConfig = new Config;
|
||||
mConfig->addr = device_addr;
|
||||
mConfig->com = *com;
|
||||
|
||||
connect(pTimer,&QTimer::timeout,[=](){
|
||||
static float sd = 0;
|
||||
if(gAsyncData == nullptr)
|
||||
return;
|
||||
CapData *z = new CapData;
|
||||
|
||||
int ret = gAsyncData->TakeLast((*com).toInt(),&z);
|
||||
int ret = gAsyncData->TakeLast(device_addr,&z);
|
||||
if(ret == 0){
|
||||
mSeries1->append(sd,z->val1);
|
||||
|
||||
|
@ -60,10 +64,8 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
|
|||
pTimer->start(100);
|
||||
qDebug()<<QDateTime::currentDateTime().toString();
|
||||
ui->lineEdit_2->setText(addr);
|
||||
gAsyncData->AddConfig(this->mConfig);
|
||||
|
||||
mConfig = new Config;
|
||||
mConfig->addr = device_addr;
|
||||
mConfig->com = *com;
|
||||
}
|
||||
|
||||
void SubForm::on_pushButton_clicked() {
|
||||
|
|
Loading…
Reference in New Issue