You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 regels
3.5 KiB

  1. /***********************************************************************
  2. * Copyright (C) 2025-, XINJE Co., Ltd.
  3. *
  4. * File Name: mainwindow.h
  5. * Description: Modbus主站的人机交互界面头文件,包含其成员变量与成员函数声明
  6. * Others:
  7. * Version: v1.0
  8. * Author: weikai XINJE
  9. * Date: 2025-7-30
  10. ***********************************************************************/
  11. #ifndef MAINWINDOW_H
  12. #define MAINWINDOW_H
  13. #include <QMainWindow>
  14. #include <QTimer>
  15. #include <QDateTime>
  16. #include "serial_communication.h"
  17. #include "modbus_master.h"
  18. namespace Ui
  19. {
  20. class MainWindow;
  21. }
  22. const int DEFAULT_TIMEOUT = 1000; //默认超时时间
  23. const int DEFAULT_MAXRETRISE = 3; //默认最大重发次数
  24. /********************************************************************
  25. * Iterates over the contents of a MainWindow.
  26. *人机交互界面:
  27. *通过SerialCommunicator实例serialComm实现串口通信
  28. *通过ModbusRTUMaster实例modbusMaster实现Modbus请求帧生成与响应帧解析
  29. *通过QTimer实例serialPortTimer实现串口下拉框定时刷新
  30. ***********************************************************************/
  31. class MainWindow : public QMainWindow
  32. {
  33. Q_OBJECT
  34. public:
  35. explicit MainWindow(QWidget *parent = nullptr);
  36. ~MainWindow();
  37. private slots:
  38. // UI按钮槽函数
  39. void onConnectButtonClicked();//连接按钮
  40. void onDisconnectButtonClicked();//断开连接按钮
  41. void onReadButtonClicked();//读取按钮
  42. void onWriteButtonClicked();//写入按钮
  43. void onClearLogButtonClicked();//清空日志框
  44. void onExportHistoryButtonClicked();//导出通信历史
  45. // 串口通信信号处理槽
  46. /***********************************************************************
  47. * @brief : 串口接收数据到达信号的处理槽函数
  48. * @param : data 串口接收到的数据字节流
  49. ***********************************************************************/
  50. void onSerialDataReceived(const QString &data);
  51. /***********************************************************************
  52. * @brief : 串口接收状态变化信号的处理槽函数
  53. * @param : 串口status状态变化的描述字符串
  54. ***********************************************************************/
  55. void onSerialStatusChanged(const QString &status);
  56. /***********************************************************************
  57. * @brief : 串口接收错误发生信号的处理槽函数
  58. * @param : error 串口错误的描述字符串
  59. ***********************************************************************/
  60. void onSerialErrorOccurred(const QString &error);
  61. //断开连接信号处理槽
  62. void onConnectionDisconnected();
  63. // 定时刷新槽函数
  64. void onRefreshSerialPorts();
  65. private:
  66. //界面初始化
  67. void init();
  68. /***********************************************************************
  69. * @brief : 日志输出函数
  70. * @param : message 日志字符串
  71. ***********************************************************************/
  72. void logToBox(const QString &message);
  73. /***********************************************************************
  74. * @brief : 刷新串口下拉框
  75. ***********************************************************************/
  76. void refreshSerialPorts();
  77. Ui::MainWindow *ui_;
  78. SerialCommunicator *serialComm_; // 串口通信实例
  79. ModbusRTUMaster *modbusMaster_;//Modbus协议实例
  80. QTimer *serialPortTimer_;//用于定时刷新可用串口下拉栏的定时器
  81. };
  82. #endif // MAINWINDOW_H