diff --git a/Language/BatteryMonitor_CHN.qm b/Language/BatteryMonitor_CHN.qm index bd7bce8..ae247bc 100644 Binary files a/Language/BatteryMonitor_CHN.qm and b/Language/BatteryMonitor_CHN.qm differ diff --git a/Language/BatteryMonitor_ENG.qm b/Language/BatteryMonitor_ENG.qm index 2851da2..469fbfd 100644 Binary files a/Language/BatteryMonitor_ENG.qm and b/Language/BatteryMonitor_ENG.qm differ diff --git a/dialoglogin.cpp b/dialoglogin.cpp index 27409d0..c624531 100644 --- a/dialoglogin.cpp +++ b/dialoglogin.cpp @@ -10,6 +10,7 @@ #include "appserial.h" #include "modbusrtu.h" #include +#include DialogLogin::DialogLogin(QWidget *parent) : QDialog(parent) @@ -84,11 +85,24 @@ void DialogLogin::init() connect(m_ModbusRTU, &ModbusRTU::sig_showModbusData_base_info_list_47_49_51_53_55, m_MainWindow, &MainWindow::slot_pageHomeBaseInfo47_49_51_53_55); //写寄存器的信号与槽的连接 - connect(m_MainWindow, &MainWindow::write_regs_signals, m_ModbusRTU, &ModbusRTU::write_regs_slot); + connect(m_MainWindow, &MainWindow::write_regs_signals, m_ModbusRTU, &ModbusRTU::write_regs_slot, Qt::QueuedConnection); //读寄存器的信号与槽的连接 - connect(m_MainWindow, &MainWindow::read_regs_signals, m_ModbusRTU, &ModbusRTU::read_regs_slot); + connect(m_MainWindow, &MainWindow::read_regs_signals, m_ModbusRTU, &ModbusRTU::read_regs_slot, Qt::QueuedConnection); connect(m_ModbusRTU, &ModbusRTU::sig_showReadHoldingRegs, m_MainWindow, &MainWindow::slot_pageParaSetShow); + + //主窗口关闭时,关闭线程 + connect(m_MainWindow, &MainWindow::closeThread, this, [=]{ + qDebug() << "关闭线程"; + m_ModbusRTU->quit(); + }); + + // QMetaObject::invokeMethod(m_ModbusRTU,"read_regs_slot",Qt::QueuedConnection); + // connect(m_ModbusRTU, &ModbusRTU::sig_readMoveToThread, m_ModbusRTU, &ModbusRTU::read_regs_slot, Qt::QueuedConnection); + // thread = new QThread; + + // m_ModbusRTU->moveToThread(thread); + // thread->start(); } void DialogLogin::serialInit() @@ -247,6 +261,7 @@ void DialogLogin::slot_btnConnect_clicked() m_MainWindow->statusBarConnectedIcon->setPixmap(QPixmap(QIcon(":/Image/connected2.png").pixmap(QSize(24, 24)))); m_MainWindow->show(); // m_MainWindow->showMaximized(); + // m_ModbusRTU->start(); m_ModbusRTU->start(); } else { diff --git a/dialoglogin.h b/dialoglogin.h index 50cd32c..2ddb72b 100644 --- a/dialoglogin.h +++ b/dialoglogin.h @@ -31,6 +31,7 @@ private: AppSerial *m_Serial; ModbusRTU *m_ModbusRTU; QSettings *ini; + // QThread *thread; int BCUNumbers; signals: diff --git a/mainwindow.cpp b/mainwindow.cpp index 7f1be71..8ad5ede 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -26,11 +26,15 @@ #include #include "modbusrtu.h" #include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { + qDebug() << "mainwindow:进入线程:" << QThread::currentThread(); + // QMetaObject::invokeMethod(this, "write_regs_slot", Qt::QueuedConnection); + // QMetaObject::invokeMethod(this, "read_regs_slot", Qt::QueuedConnection); ui->setupUi(this); this->init(); this->setMenuStyle(); @@ -218,12 +222,12 @@ void MainWindow::init() //设置按钮的提示文本 - ui->btnHome->setToolTip("概述信息"); - ui->btnBattery->setToolTip("详细信息"); - ui->btnParaSet->setToolTip("参数设置"); - ui->btnDebug->setToolTip("报文信息"); - ui->btnFlash->setToolTip("升级调试"); - ui->btnSetup->setToolTip("串口信息"); + ui->btnHome->setToolTip("概述信息(Overview Information)"); + ui->btnBattery->setToolTip("详细信息(Detailed Information)"); + ui->btnParaSet->setToolTip("参数设置(Parameter Settings)"); + ui->btnDebug->setToolTip("报文信息(Message Information)"); + ui->btnFlash->setToolTip("升级调试(Upgrade Debugging)"); + ui->btnSetup->setToolTip("串口信息(Serial Port)"); ui->btnSetup->setStyleSheet("QToolTip { position: absolute; left: 20px; top: 20px; }"); // ui->btnRecord->setToolTip("记录导出"); @@ -3307,6 +3311,13 @@ void MainWindow::slot_pageParaSetShow(QByteArray byteArray, int dataType, int ro } +void MainWindow::closeEvent(QCloseEvent *e) +{ + emit closeThread(); + + QWidget::closeEvent(e); +} + void MainWindow::on_pageParaSetWrite_clicked() { BatteryConfig::Item item; @@ -3705,4 +3716,5 @@ void MainWindow::on_pageParaSetWrite_clicked() void MainWindow::on_tabChanged(int index) { tabWidget_paraset_index = index; + ui->pageParaSetCheck->setCheckState(Qt::Unchecked); } diff --git a/mainwindow.h b/mainwindow.h index 999d5bb..503af76 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -119,6 +119,7 @@ signals: void closeLogin(); void write_regs_signals(int addr, const uint16_t data); void read_regs_signals(int addr, int nb, uint16_t *data, int row); + void closeThread(); public: void slot_getBcuNumberFromDialoglogin(int number); @@ -131,6 +132,9 @@ public: void slot_pageHomeBaseInfo47_49_51_53_55(QList byteArray, int dataType); void slot_pageParaSetShow(QByteArray byteArray, int dataType, int row, int nb); +protected: + void closeEvent(QCloseEvent *e) override; + private slots: void on_pageParaSetCheck_stateChanged(int arg1); void on_pageParaSetRead_clicked(); diff --git a/mainwindow.ui b/mainwindow.ui index d6c6ea9..36779a0 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -281,7 +281,7 @@ background-color: rgba(255, 255, 255, 0); - 2 + 1 @@ -290,7 +290,7 @@ background-color: rgba(255, 255, 255, 0); } - + @@ -482,8 +482,11 @@ background-color: rgba(255, 255, 255, 0); 9 + + + - <html><head/><body><p align="center">总正继电器</p></body></html> + 总正继电器 Qt::AlignCenter @@ -499,7 +502,7 @@ background-color: rgba(255, 255, 255, 0); - <html><head/><body><p align="center">预充继电器</p></body></html> + 预充继电器 Qt::AlignCenter @@ -515,7 +518,7 @@ background-color: rgba(255, 255, 255, 0); - <html><head/><body><p align="center">总负继电器</p></body></html> + 总负继电器 Qt::AlignCenter @@ -531,7 +534,7 @@ background-color: rgba(255, 255, 255, 0); - <html><head/><body><p align="center">隔离开关</p></body></html> + 隔离开关 Qt::AlignCenter @@ -749,8 +752,8 @@ background-color: rgba(255, 255, 255, 0); 0 0 - 614 - 235 + 1113 + 379 @@ -2378,7 +2381,7 @@ background-color: rgba(255, 255, 255, 0); - 1 + 2 @@ -19177,7 +19180,7 @@ background-color: rgba(255, 255, 255, 0); - check all + 全部勾选 @@ -19197,14 +19200,14 @@ background-color: rgba(255, 255, 255, 0); - read + 读取 - write + 写入 @@ -19355,14 +19358,14 @@ background-color: rgba(255, 255, 255, 0); - Display + 显示 - Clear + 清除 @@ -19392,21 +19395,21 @@ li.checked::marker { content: "\2612"; } - Save Log + 保存 - SendData + 发送数据 - Time Starmp + 时间戳 @@ -19452,13 +19455,13 @@ li.checked::marker { content: "\2612"; } - File + 文件 - Connection + 连接 @@ -19467,36 +19470,30 @@ li.checked::marker { content: "\2612"; } - View + 视图 - Help + 帮助 - Language + 语言 - Debug - - - - - Flash + 调试 - @@ -19509,22 +19506,22 @@ li.checked::marker { content: "\2612"; } - Exit + 退出 - Connect + 连接 - Disconnect + 断开 - Auto Connect + 自动连接 @@ -19535,7 +19532,7 @@ li.checked::marker { content: "\2612"; } true - Show Status Bar + 显示状态栏 @@ -19549,7 +19546,7 @@ li.checked::marker { content: "\2612"; } true - English + 英语 @@ -19560,7 +19557,7 @@ li.checked::marker { content: "\2612"; } true - Chinese + 中文 diff --git a/modbusrtu.cpp b/modbusrtu.cpp index 6bfb632..6741674 100644 --- a/modbusrtu.cpp +++ b/modbusrtu.cpp @@ -7,6 +7,8 @@ ModbusRTU::ModbusRTU(QObject *parent) : QThread(parent) { init(); + // start(); + } ModbusRTU::~ModbusRTU() @@ -23,6 +25,8 @@ void ModbusRTU::init() void ModbusRTU::run() { qDebug() << "进入线程:" << QThread::currentThread(); + // QMetaObject::invokeMethod(QThread::currentThread(), "read_regs_slot", Qt::QueuedConnection); + // QMetaObject::invokeMethod(QThread::currentThread(), "write_regs_slot", Qt::QueuedConnection); while(true) { // qDebug() << "11111111111111111111111111111111"; @@ -166,6 +170,7 @@ void ModbusRTU::run() void ModbusRTU::write_regs_slot(int addr,const uint16_t data) { + qDebug() << "write:进入线程:" << QThread::currentThread(); int rc = write_single_register(addr, data); if(MODBUS_ERR == rc) { qDebug() << "######modbus no message"; @@ -175,6 +180,7 @@ void ModbusRTU::write_regs_slot(int addr,const uint16_t data) void ModbusRTU::read_regs_slot(int addr, int nb, uint16_t *data, int row) { + qDebug() << "read:进入线程:" << QThread::currentThread(); int rc = read_holding_register(addr, nb, data); if(MODBUS_ERR == rc) { // qDebug() << "modbus no message"; diff --git a/modbusrtu.h b/modbusrtu.h index 6727d85..f23d86e 100644 --- a/modbusrtu.h +++ b/modbusrtu.h @@ -13,6 +13,8 @@ class ModbusRTU : public QThread public: ModbusRTU(QObject *parent = nullptr); ~ModbusRTU(); + +public slots: void write_regs_slot(int addr, const uint16_t data); void read_regs_slot(int addr, int nb, uint16_t *data, int row); @@ -25,7 +27,7 @@ public: int dataBit; int stopBit; -protected: +public: void run() override; private: @@ -70,6 +72,7 @@ signals: void sig_showModbusData_base_info_list_47_49_51_53_55(QList byteArray,int dataType); void sig_showReadHoldingRegs(QByteArray byteArray,int dataType, int row, int nb); + public slots: };