commit bbd47b34867e3641427b88c97049171e986d2598 Author: 95384 <664090429@qq.com> Date: Fri Nov 29 17:19:38 2024 +0800 no message diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b0a4ec2 --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/micro_climate_config.pro b/micro_climate_config.pro new file mode 100644 index 0000000..a8fdb29 --- /dev/null +++ b/micro_climate_config.pro @@ -0,0 +1,31 @@ +QT += core gui serialport + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +FORMS += \ + widget.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/micro_climate_config.pro.user b/micro_climate_config.pro.user new file mode 100644 index 0000000..fdc5055 --- /dev/null +++ b/micro_climate_config.pro.user @@ -0,0 +1,340 @@ + + + + + + EnvironmentId + {2e637976-36d5-4449-a887-0e5257dff12a} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 8 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.9 MinGW 32-bit + Desktop Qt 5.12.9 MinGW 32-bit + qt.qt5.5129.win32_mingw73_kit + 0 + 0 + 0 + + true + 0 + E:\Y\QT\build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + E:/Y/QT/build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + E:\Y\QT\build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Release + E:/Y/QT/build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + E:\Y\QT\build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Profile + E:/Y/QT/build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:E:/Y/QT/micro_climate_config/micro_climate_config.pro + E:/Y/QT/micro_climate_config/micro_climate_config.pro + + false + + false + true + true + false + false + true + + E:/Y/QT/build-micro_climate_config-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/widget.cpp b/widget.cpp new file mode 100644 index 0000000..db14b36 --- /dev/null +++ b/widget.cpp @@ -0,0 +1,190 @@ +#include "widget.h" +#include "ui_widget.h" + +Widget::Widget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::Widget) +{ + ui->setupUi(this); + // 启动时刷新串口 + QStringList serialNamePort; + foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) + { + serialNamePort << info.portName() + "|" + info.description(); + } + ui -> SerialPort_comboBox -> clear(); + ui -> SerialPort_comboBox -> addItems(serialNamePort); + + Serial_port = new QSerialPort(this); +} + +Widget::~Widget() +{ + delete ui; +} + +void Widget::closeEvent(QCloseEvent *event) +{ +// 退出提醒弹窗 + QMessageBox *Close_msgBox = new QMessageBox(QMessageBox::Question, "提示", "是否退出", QMessageBox::Yes | QMessageBox::No, this, Qt::WindowStaysOnTopHint); + Close_msgBox -> setDefaultButton(QMessageBox::No); + Close_msgBox -> button(QMessageBox::No) -> setText(u8"不退出"); + Close_msgBox -> button(QMessageBox::Yes) -> setText(u8"退出"); + int val = Close_msgBox -> exec(); + if(val == QMessageBox::No) + { + event -> ignore(); + } + if(val == QMessageBox::Yes) + { + event -> accept(); + } +} + +//串口刷新 +void Widget::on_SerialPort_refresh_pushButton_clicked() +{ + QStringList serialNamePort; + foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) + { + serialNamePort << info.portName() + "|" + info.description(); + } + ui -> SerialPort_comboBox -> clear(); + ui -> SerialPort_comboBox -> addItems(serialNamePort); +} + +//打开关闭按钮状态 +//1将打开按钮 +//0将关闭按钮 +int8_t open_button_status = 1; +void Widget::on_Open_Serial_pushButton_clicked() +{ + if(open_button_status == 1) + { + QSerialPort::BaudRate Baudrate = QSerialPort::Baud9600; + QSerialPort::DataBits Databits = QSerialPort::Data8; + QSerialPort::Parity Parity = QSerialPort::NoParity; + QSerialPort::StopBits Stopbits = QSerialPort::OneStop; + + QComboBox *SerialPortbox = ui -> SerialPort_comboBox; + QComboBox *Baudbox = ui -> BaudRate_comboBox; + QComboBox *Databitsbox = ui -> DataBits_comboBox; + QComboBox *Checkbitsbox = ui -> CheckBits_comboBox; + QComboBox *Stopbitsbox = ui -> StopBits_comboBox; + + //波特率 + if(Baudbox -> currentText() == "4800"){ + Baudrate = QSerialPort::Baud4800; + } + else if(Baudbox -> currentText() == "9600"){ + Baudrate = QSerialPort::Baud9600; + } + else if(Baudbox -> currentText() == "19200"){ + Baudrate = QSerialPort::Baud19200; + } + else if(Baudbox -> currentText() == "38400"){ + Baudrate = QSerialPort::Baud38400; + } + else if(Baudbox -> currentText() == "57600"){ + Baudrate = QSerialPort::Baud57600; + } + else if(Baudbox -> currentText() == "115200"){ + Baudrate = QSerialPort::Baud115200; + } + else { + QMessageBox::warning(this, "错误", "波特率未设置"); + return; + } + + //数据位 + if(Databitsbox -> currentText() == "6"){ + Databits = QSerialPort::Data6; + } + else if(Databitsbox -> currentText() == "7"){ + Databits = QSerialPort::Data7; + } + else if(Databitsbox -> currentText() == "8"){ + Databits = QSerialPort::Data8; + } + else { + QMessageBox::warning(this, "错误", "数据位未设置"); + return; + } + + //校验位 + if(Checkbitsbox -> currentText() == "无"){ + Parity = QSerialPort::NoParity; + } + else if(Checkbitsbox -> currentText() == "奇"){ + Parity = QSerialPort::OddParity; + } + else if(Checkbitsbox -> currentText() == "偶"){ + Parity = QSerialPort::EvenParity; + } + else { + QMessageBox::warning(this, "错误", "校验位未设置"); + return; + } + + //停止位 + if(Stopbitsbox -> currentText() == "1"){ + Stopbits = QSerialPort::OneStop; + } + else if(Stopbitsbox -> currentText() == "1.5"){ + Stopbits = QSerialPort::OneAndHalfStop; + } + else if(Stopbitsbox -> currentText() == "2"){ + Stopbits = QSerialPort::TwoStop; + } + else { + QMessageBox::warning(this, "错误", "停止位未设置"); + return; + } + + //设置参数 + Serial_port -> setPort((const QSerialPortInfo)(SerialPortbox -> currentText().section('|', 0, 0))); + Serial_port -> setBaudRate(Baudrate); + Serial_port -> setDataBits(Databits); + Serial_port -> setParity(Parity); + Serial_port -> setStopBits(Stopbits); + Serial_port -> setReadBufferSize(4096); + if(Serial_port -> open(QIODevice::ReadWrite) == true){ + // 打开后将按钮变为关闭按钮,绿色指示标志 + ui -> Open_Serial_pushButton -> setText("关闭串口"); + ui -> serial_status_label -> setStyleSheet("QLabel { background-color :rgb(0, 144, 0); border-radius: 10px;}"); + //打开串口后禁止配置 + ui -> SerialPort_comboBox -> setEnabled(false); + ui -> BaudRate_comboBox -> setEnabled(false); + ui -> DataBits_comboBox -> setEnabled(false); + ui -> CheckBits_comboBox -> setEnabled(false); + ui -> StopBits_comboBox -> setEnabled(false); + ui -> SerialPort_refresh_pushButton -> setEnabled(false); + ui -> BaudRate_label -> setEnabled(false); + ui -> DataBits_label -> setEnabled(false); + ui -> CheckBits_label -> setEnabled(false); + ui -> StopBits_label -> setEnabled(false); + } + else{ + QMessageBox::critical(this, "提示", "串口打开失败"); + return; + } + } + else { + //将按钮变为打开按钮,红色指示标志 + ui -> Open_Serial_pushButton ->setText("打开串口"); + ui -> serial_status_label ->setStyleSheet("QLabel { background-color :rgb(184, 0, 0); border-radius: 10px;}"); + Serial_port -> close(); + //关闭串口后允许配置 + ui -> SerialPort_comboBox -> setEnabled(true); + ui -> BaudRate_comboBox -> setEnabled(true); + ui -> DataBits_comboBox -> setEnabled(true); + ui -> CheckBits_comboBox -> setEnabled(true); + ui -> StopBits_comboBox -> setEnabled(true); + ui -> SerialPort_refresh_pushButton -> setEnabled(true); + ui -> BaudRate_label -> setEnabled(true); + ui -> DataBits_label -> setEnabled(true); + ui -> CheckBits_label -> setEnabled(true); + ui -> StopBits_label -> setEnabled(true); + } + open_button_status = !open_button_status; +} diff --git a/widget.h b/widget.h new file mode 100644 index 0000000..ac27474 --- /dev/null +++ b/widget.h @@ -0,0 +1,36 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class Widget; } +QT_END_NAMESPACE + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); + +private slots: + void on_SerialPort_refresh_pushButton_clicked(); + + void on_Open_Serial_pushButton_clicked(); + +private: + Ui::Widget *ui; + //关闭窗口提示 + void closeEvent(QCloseEvent *event) override; + //串口 + QSerialPort * Serial_port; + +}; +#endif // WIDGET_H diff --git a/widget.ui b/widget.ui new file mode 100644 index 0000000..100b369 --- /dev/null +++ b/widget.ui @@ -0,0 +1,420 @@ + + + Widget + + + + 0 + 0 + 684 + 427 + + + + 微气象传感器调试助手 + + + + + + 0 + + + + 串口配置 + + + + + 50 + 50 + 156 + 207 + + + + + + + + + + 宋体 + 12 + + + + + + + + + + 刷新 + + + + + + + + + + 宋体 + 12 + + + + 波特率: + + + + + + + + 宋体 + 12 + + + + 6 + + + + 110 + + + + + 300 + + + + + 600 + + + + + 1200 + + + + + 2400 + + + + + 4800 + + + + + 9600 + + + + + 14400 + + + + + 19200 + + + + + 38400 + + + + + 43000 + + + + + 57600 + + + + + 76800 + + + + + 115200 + + + + + 128000 + + + + + 230400 + + + + + 256000 + + + + + 460800 + + + + + 921600 + + + + + 1000000 + + + + + 2000000 + + + + + 3000000 + + + + + + + + + + + + + 宋体 + 12 + + + + 数据位: + + + + + + + + 宋体 + 12 + + + + 3 + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + + + + + + + + + 宋体 + 12 + + + + 校验位: + + + + + + + + 宋体 + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 宋体 + 12 + + + + 停止位: + + + + + + + + 宋体 + 12 + + + + + 1 + + + + + 1.5 + + + + + 2 + + + + + + + + + + + + + 0 + 0 + + + + + 宋体 + 12 + + + + 打开串口 + + + + + + + + 0 + 0 + + + + + 20 + 20 + + + + + 20 + 20 + + + + background-color:rgb(184, 0, 0); /* 背景 */ +border-radius: 10px; /* 圆角半径 */ + + + + + + + + + + + + + + HSD变频器控制 + + + + + 20 + 20 + 75 + 23 + + + + PushButton + + + + + + 310 + 0 + 211 + 221 + + + + + + + + + + +