|
- /***********************************************************************
- * Copyright (C) 2025-, XINJE Co., Ltd.
- *
- * File Name: mainwindow.h
- * Description: Modbus主站的人机交互界面头文件,包含其成员变量与成员函数声明
- * Others:
- * Version: v1.0
- * Author: weikai XINJE
- * Date: 2025-7-30
- ***********************************************************************/
-
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
-
- #include <QMainWindow>
- #include <QTimer>
- #include <QDateTime>
- #include "serial_communication.h"
- #include "modbus_master.h"
-
- namespace Ui
- {
- class MainWindow;
- }
-
- const int DEFAULT_TIMEOUT = 1000; //默认超时时间
- const int DEFAULT_MAXRETRISE = 3; //默认最大重发次数
-
- /********************************************************************
- * Iterates over the contents of a MainWindow.
- *人机交互界面:
- *通过SerialCommunicator实例serialComm实现串口通信
- *通过ModbusRTUMaster实例modbusMaster实现Modbus请求帧生成与响应帧解析
- *通过QTimer实例serialPortTimer实现串口下拉框定时刷新
- ***********************************************************************/
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
-
- public:
- explicit MainWindow(QWidget *parent = nullptr);
- ~MainWindow();
-
-
- private slots:
- // UI按钮槽函数
- void onConnectButtonClicked();//连接按钮
- void onDisconnectButtonClicked();//断开连接按钮
- void onReadButtonClicked();//读取按钮
- void onWriteButtonClicked();//写入按钮
- void onClearLogButtonClicked();//清空日志框
- void onExportHistoryButtonClicked();//导出通信历史
-
- // 串口通信信号处理槽
- /***********************************************************************
- * @brief : 串口接收数据到达信号的处理槽函数
- * @param : data 串口接收到的数据字节流
- ***********************************************************************/
- void onSerialDataReceived(const QString &data);
-
- /***********************************************************************
- * @brief : 串口接收状态变化信号的处理槽函数
- * @param : 串口status状态变化的描述字符串
- ***********************************************************************/
- void onSerialStatusChanged(const QString &status);
-
- /***********************************************************************
- * @brief : 串口接收错误发生信号的处理槽函数
- * @param : error 串口错误的描述字符串
- ***********************************************************************/
- void onSerialErrorOccurred(const QString &error);
-
- //断开连接信号处理槽
- void onConnectionDisconnected();
-
- // 定时刷新槽函数
- void onRefreshSerialPorts();
-
- private:
- //界面初始化
- void init();
-
- /***********************************************************************
- * @brief : 日志输出函数
- * @param : message 日志字符串
- ***********************************************************************/
- void logToBox(const QString &message);
-
- /***********************************************************************
- * @brief : 刷新串口下拉框
- ***********************************************************************/
- void refreshSerialPorts();
-
- Ui::MainWindow *ui_;
- SerialCommunicator *serialComm_; // 串口通信实例
- ModbusRTUMaster *modbusMaster_;//Modbus协议实例
- QTimer *serialPortTimer_;//用于定时刷新可用串口下拉栏的定时器
- };
-
- #endif // MAINWINDOW_H
-
-
|