完成日志功能。
parent
ba1e158819
commit
f7c5404c66
22
global.h
22
global.h
|
@ -11,6 +11,13 @@ extern "C"{
|
||||||
#include "libmodbus/modbus.h"
|
#include "libmodbus/modbus.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
||||||
|
# pragma execution_character_set("utf-8")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int addr;
|
int addr;
|
||||||
uint16_t *val1;
|
uint16_t *val1;
|
||||||
|
@ -85,10 +92,23 @@ public:
|
||||||
QThread::msleep(300);
|
QThread::msleep(300);
|
||||||
|
|
||||||
for(auto s = 0;s < itr->req.length();s++){
|
for(auto s = 0;s < itr->req.length();s++){
|
||||||
QThread::msleep(1000);
|
QThread::msleep(itr->rate*1000);
|
||||||
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
|
int ret = modbus_read_registers(mMod,itr->req[s].addr,itr->req[s].len,dat);
|
||||||
|
|
||||||
mMux.lock();
|
mMux.lock();
|
||||||
|
QString log = QDateTime::currentDateTime().toString("yyyy-mm-dd hh:MM:ss ") + "发送数据:";
|
||||||
|
for(int i =0;i < req_length;i++){
|
||||||
|
log += QString::asprintf("0x%02x ",req[i]);
|
||||||
|
}
|
||||||
|
emit(Info(log));
|
||||||
|
|
||||||
|
|
||||||
|
log = QDateTime::currentDateTime().toString("yyyy-mm-dd hh:MM:ss ") + "接收数据:";
|
||||||
|
for(int i =0;i < resp_length;i++){
|
||||||
|
log += QString::asprintf("0x%02x ",rsp[i]);
|
||||||
|
}
|
||||||
|
emit(Info(log));
|
||||||
|
// req_length;
|
||||||
bool succ = true;
|
bool succ = true;
|
||||||
|
|
||||||
if(mListData.contains(itr->addr)){
|
if(mListData.contains(itr->addr)){
|
||||||
|
|
|
@ -75,7 +75,8 @@ void MainWindow::on_pushButton_3_clicked()
|
||||||
}
|
}
|
||||||
SubForm *p1 = new SubForm(ui->comboBox_2->currentText(),
|
SubForm *p1 = new SubForm(ui->comboBox_2->currentText(),
|
||||||
ui->comboBox->currentText().toInt(),
|
ui->comboBox->currentText().toInt(),
|
||||||
ui->lineEdit_2->text().toInt());
|
ui->lineEdit_2->text().toInt(),
|
||||||
|
ui->lineEdit_3->text().toInt());
|
||||||
qDebug()<<ui->lineEdit_2->text();
|
qDebug()<<ui->lineEdit_2->text();
|
||||||
ui->tabWidget->addTab((QWidget*)p1,"address:" + ui->lineEdit_2->text());
|
ui->tabWidget->addTab((QWidget*)p1,"address:" + ui->lineEdit_2->text());
|
||||||
this->mForms[ui->lineEdit_2->text()] = p1;
|
this->mForms[ui->lineEdit_2->text()] = p1;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
<widget class="QLineEdit" name="lineEdit_2">
|
<widget class="QLineEdit" name="lineEdit_2">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
|
<family>Arial</family>
|
||||||
<pointsize>12</pointsize>
|
<pointsize>12</pointsize>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
|
|
12
subform.cpp
12
subform.cpp
|
@ -15,7 +15,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
SubForm::SubForm(QString addr,int baurate,int device_addr)
|
SubForm::SubForm(QString addr,int baurate,int device_addr,int rate)
|
||||||
:ui(new Ui::Form) {
|
:ui(new Ui::Form) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
|
||||||
mConfig->addr = device_addr;
|
mConfig->addr = device_addr;
|
||||||
mConfig->com = *com;
|
mConfig->com = *com;
|
||||||
mConfig->baurate = baurate;
|
mConfig->baurate = baurate;
|
||||||
|
mConfig->rate = rate;
|
||||||
|
|
||||||
connect(pTimer,&QTimer::timeout,[=]() {
|
connect(pTimer,&QTimer::timeout,[=]() {
|
||||||
static float sd = 0;
|
static float sd = 0;
|
||||||
|
@ -109,6 +110,7 @@ SubForm::SubForm(QString addr,int baurate,int device_addr)
|
||||||
ui->lineEdit_2->setText(addr);
|
ui->lineEdit_2->setText(addr);
|
||||||
gAsyncData->AddConfig(this->mConfig);
|
gAsyncData->AddConfig(this->mConfig);
|
||||||
ui->tableView->setColumnWidth(2,230);
|
ui->tableView->setColumnWidth(2,230);
|
||||||
|
connect(gAsyncData,SIGNAL(Info(QString)),this,SLOT( on_log(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubForm::on_pushButton_clicked() {
|
void SubForm::on_pushButton_clicked() {
|
||||||
|
@ -234,6 +236,12 @@ void SubForm::on_pushButton_2_clicked() {
|
||||||
mConfig->req.append(Req{
|
mConfig->req.append(Req{
|
||||||
ui->lineEdit->text().toUShort(),
|
ui->lineEdit->text().toUShort(),
|
||||||
ui->lineEdit_3->text().toUShort(),
|
ui->lineEdit_3->text().toUShort(),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubForm::on_log(QString info)
|
||||||
|
{
|
||||||
|
qDebug()<<info;
|
||||||
|
ui->textEdit->append(info + "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class SubForm :QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SubForm(QString,int baurate,int device_addr);
|
SubForm(QString,int baurate,int device_addr,int rate);
|
||||||
|
|
||||||
void init_charts();
|
void init_charts();
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -36,6 +36,8 @@ private slots:
|
||||||
|
|
||||||
void on_pushButton_2_clicked();
|
void on_pushButton_2_clicked();
|
||||||
|
|
||||||
|
void on_log(QString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Form *ui;
|
Ui::Form *ui;
|
||||||
QChart *mChart;
|
QChart *mChart;
|
||||||
|
|
Loading…
Reference in New Issue