no message

master
zcy 2023-10-01 02:23:57 +08:00
parent 7993d51f95
commit 5eeda7ab66
5 changed files with 50 additions and 42 deletions

View File

@ -59,9 +59,6 @@ public:
}
}
void Run(void *v) override{
Config *pcom = (Config*)v;
qDebug()<<"start"<<pcom->com;
// 读取1
float x = 0;
while(mRuning){
@ -71,8 +68,6 @@ public:
it++){
auto itr = mConf.at(it);
uint16_t dat[10] = {0};
mMod = modbus_new_rtu(itr->com.toStdString().c_str(),
57600, 'N', 8, 1); //相同的端口只能同时打开一个
@ -82,30 +77,32 @@ public:
modbus_set_response_timeout(mMod,1000,1000);
QThread::msleep(300);
QThread::msleep(1000);
int ret = modbus_read_registers(mMod,1,1,dat);
mMux.lock();
for(auto s = 0;s < itr->req.length();s++){
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])),
});
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();
}
x += 3.1415*2 /256;
mMux.unlock();
modbus_close(mMod);
}
QThread::msleep(1000*pcom->rate);
}
// 读取2

View File

@ -61,13 +61,14 @@ void MainWindow::on_pushButton_clicked()
void MainWindow::on_pushButton_3_clicked()
{
if(this->mForms.contains(ui->lineEdit_2->text())){
QMessageBox::warning(this,"串口已经打开","串口已经打开");
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(),
ui->comboBox->currentText().toInt());
ui->comboBox->currentText().toInt(),
ui->lineEdit_2->text().toInt());
qDebug()<<ui->lineEdit_2->text();
ui->tabWidget->addTab((QWidget*)p1,"设备地址:" + ui->lineEdit_2->text());
ui->tabWidget->addTab((QWidget*)p1,"<EFBFBD><EFBFBD><EFBFBD>ַ:" + ui->lineEdit_2->text());
this->mForms[ui->lineEdit_2->text()] = p1;
if(nullptr == gAsyncData){
@ -76,17 +77,13 @@ void MainWindow::on_pushButton_3_clicked()
qDebug()<<"done";
});
gAsyncData->Start(new Config{
QString(ui->comboBox_2->currentText()),
ui->lineEdit_2->text().toInt(),
ui->lineEdit_3->text().toInt(),
});
}
gAsyncData->AddConfig(new Config{
QString(ui->comboBox_2->currentText()),
ui->lineEdit_2->text().toInt(),
ui->lineEdit_3->text().toInt(),
});
// gAsyncData->AddConfig(new Config{
// QString(ui->comboBox_2->currentText()),
// ui->lineEdit_2->text().toInt(),
// ui->lineEdit_3->text().toInt(),
// });
}

6
sub.ui
View File

@ -29,7 +29,11 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
<widget class="QLineEdit" name="lineEdit_2">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">

View File

@ -15,7 +15,7 @@
#endif
SubForm::SubForm(QString addr,int baurate)
SubForm::SubForm(QString addr,int baurate,int device_addr)
:ui(new Ui::Form) {
ui->setupUi(this);
@ -61,7 +61,9 @@ SubForm::SubForm(QString addr,int baurate)
qDebug()<<QDateTime::currentDateTime().toString();
ui->lineEdit_2->setText(addr);
mConfig = new Config;
mConfig->addr = device_addr;
mConfig->com = *com;
}
void SubForm::on_pushButton_clicked() {
@ -197,6 +199,14 @@ void SubForm::on_pushButton_2_clicked(bool checked) {
void SubForm::on_pushButton_2_clicked() {
for(int i = 0;i < mConfig->req.length();i++){
if(ui->lineEdit->text().toInt() == mConfig->req[i].addr){
return;
}
}
mConfig->req.append(Req{
ui->lineEdit->text().toUShort(),
ui->lineEdit_3->text().toUShort(),
});
}

View File

@ -27,7 +27,7 @@ class SubForm :QWidget
{
Q_OBJECT
public:
SubForm(QString,int baurate);
SubForm(QString,int baurate,int device_addr);
void init_charts();
private slots: