From 9aa354ffbce38810cc71d321e771f762ba413c94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B7=E5=BA=8A=E5=B0=B1=E7=8A=AF=E5=9B=B0?=
<11730503+psx123456@user.noreply.gitee.com>
Date: Sat, 11 Jan 2025 14:30:12 +0800
Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E6=8E=A7=E5=88=B6=E7=9B=92?=
=?UTF-8?q?=E4=B8=8A=E4=BD=8D=E6=9C=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
chargControlBox_cfgFile.pro | 35 +++
chargControlBox_cfgFile.pro.user | 340 ++++++++++++++++++++++
main.cpp | 11 +
mainwindow.cpp | 148 ++++++++++
mainwindow.h | 39 +++
mainwindow.ui | 473 +++++++++++++++++++++++++++++++
6 files changed, 1046 insertions(+)
create mode 100644 chargControlBox_cfgFile.pro
create mode 100644 chargControlBox_cfgFile.pro.user
create mode 100644 main.cpp
create mode 100644 mainwindow.cpp
create mode 100644 mainwindow.h
create mode 100644 mainwindow.ui
diff --git a/chargControlBox_cfgFile.pro b/chargControlBox_cfgFile.pro
new file mode 100644
index 0000000..131ce98
--- /dev/null
+++ b/chargControlBox_cfgFile.pro
@@ -0,0 +1,35 @@
+QT += core gui
+
+# 添加串口模块支持
+QT += 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 \
+ mainwindow.cpp
+
+HEADERS += \
+ mainwindow.h
+
+FORMS += \
+ mainwindow.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/chargControlBox_cfgFile.pro.user b/chargControlBox_cfgFile.pro.user
new file mode 100644
index 0000000..9c2b202
--- /dev/null
+++ b/chargControlBox_cfgFile.pro.user
@@ -0,0 +1,340 @@
+
+
+
+
+
+ EnvironmentId
+ {844cf8e3-8231-4057-928d-29ec52433497}
+
+
+ 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
+ D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug
+ D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-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
+ D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Release
+ D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-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
+ D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Profile
+ D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-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:D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro
+ D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro
+
+ false
+
+ false
+ true
+ true
+ false
+ false
+ true
+
+ D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..fd3e533
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+
+#include
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
diff --git a/mainwindow.cpp b/mainwindow.cpp
new file mode 100644
index 0000000..383f094
--- /dev/null
+++ b/mainwindow.cpp
@@ -0,0 +1,148 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include
+#include
+#include
+#include
+#include
+
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+ , ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+
+ Init();
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::openFile()
+{
+ QString s = QFileDialog::getOpenFileName(this,"选择文件","/", "Files(*.json)");
+ qDebug() << s << endl;
+}
+
+void MainWindow::scanSerialPort()
+{
+ /* 查找可用串口 */
+ foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
+// ui->SerialPort->addItem(info.portName());
+ ui->SerialPort->addItem(info.portName() + ":" +info.description());
+ }
+
+}
+
+void MainWindow::parityItemInit()
+{
+ QList list;
+ list<<"None"<<"Even"<<"Odd"<<"Space"<<"Mark";
+ for (int i = 0; i < 5; i++) {
+ ui->comboBox_4->addItem(list[i]);
+ }
+ ui->comboBox_4->setCurrentIndex(0);
+}
+
+void MainWindow::Init()
+{
+ scanSerialPort();
+ parityItemInit();
+ serialPort = new QSerialPort(this);
+
+ connect(ui->openFile,SIGNAL(clicked()),this,SLOT(openFile()));
+ connect(ui->SerialPortPushButton,SIGNAL(clicked())
+ ,this,SLOT(openSerialPortPushButtonClicked()));
+
+}
+
+void MainWindow::openSerialPortPushButtonClicked()
+{
+ if (ui->SerialPortPushButton->text() == "打开串口") {
+ /* 设置串口名 */
+// serialPort->setPortName(ui->SerialPort->currentText());
+ serialPort->setPort((const QSerialPortInfo)(ui->SerialPort->currentText().section(':', 0, 0)));
+
+ /* 设置波特率 */
+ serialPort->setBaudRate(ui->comboBox_2->currentText().toInt());
+
+ /* 设置数据位数 */
+ switch (ui->comboBox_3->currentText().toInt()) {
+ case 5:
+ serialPort->setDataBits(QSerialPort::Data5);
+ break;
+ case 6:
+ serialPort->setDataBits(QSerialPort::Data6);
+ break;
+ case 7:
+ serialPort->setDataBits(QSerialPort::Data7);
+ break;
+ case 8:
+ serialPort->setDataBits(QSerialPort::Data8);
+ break;
+ default: break;
+ }
+
+ /* 设置奇偶校验 */
+ switch (ui->comboBox_4->currentIndex()) {
+ case 0:
+ serialPort->setParity(QSerialPort::NoParity);
+ break;
+ case 1:
+ serialPort->setParity(QSerialPort::EvenParity);
+ break;
+ case 2:
+ serialPort->setParity(QSerialPort::OddParity);
+ break;
+ case 3:
+ serialPort->setParity(QSerialPort::SpaceParity);
+ break;
+ case 4:
+ serialPort->setParity(QSerialPort::MarkParity);
+ break;
+ default: break;
+ }
+
+ /* 设置停止位 */
+ switch (ui->comboBox_5->currentText().toInt()) {
+ case 1:
+ serialPort->setStopBits(QSerialPort::OneStop);
+ break;
+ case 2:
+ serialPort->setStopBits(QSerialPort::TwoStop);
+ break;
+ default: break;
+ }
+
+ /* 设置流控制 */
+ serialPort->setFlowControl(QSerialPort::NoFlowControl);
+ if (!serialPort->open(QIODevice::ReadWrite))
+ QMessageBox::about(NULL, "错误",
+ "串口无法打开!可能串口已经被占用!");
+ else {
+ ui->SerialPort->setEnabled(false);
+ ui->comboBox_2->setEnabled(false);
+ ui->comboBox_3->setEnabled(false);
+ ui->comboBox_4->setEnabled(false);
+ ui->comboBox_5->setEnabled(false);
+
+ ui->SerialPortPushButton->setText("关闭串口");
+ ui->label_6->setStyleSheet("color: red;");
+// pushButton[0]->setEnabled(true);
+ }
+
+ } else {
+ serialPort->close();
+ ui->SerialPort->setEnabled(true);
+ ui->comboBox_2->setEnabled(true);
+ ui->comboBox_3->setEnabled(true);
+ ui->comboBox_4->setEnabled(true);
+ ui->comboBox_5->setEnabled(true);
+ ui->label_6->setStyleSheet("color: block;");
+ ui->SerialPortPushButton->setText("打开串口");
+ }
+}
diff --git a/mainwindow.h b/mainwindow.h
new file mode 100644
index 0000000..fbe372a
--- /dev/null
+++ b/mainwindow.h
@@ -0,0 +1,39 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include
+
+#include
+#include
+#include
+#include
+
+QT_BEGIN_NAMESPACE
+namespace Ui { class MainWindow; }
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = nullptr);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+
+ /* 串口对象 */
+ QSerialPort *serialPort;
+ QLineEdit *fileLineEdit;
+
+ void Init();
+ void scanSerialPort();
+ void parityItemInit();
+
+private slots:
+ void openFile();
+ void openSerialPortPushButtonClicked();
+
+};
+#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
new file mode 100644
index 0000000..f06d288
--- /dev/null
+++ b/mainwindow.ui
@@ -0,0 +1,473 @@
+
+
+ MainWindow
+
+
+
+ 0
+ 0
+ 841
+ 665
+
+
+
+ MainWindow
+
+
+
+
+
+ 10
+ 10
+ 821
+ 611
+
+
+
+ -
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+
+ 117
+ 20
+
+
+
+
+
+
+
+ 串口
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 停止位
+
+
+
+ -
+
+
+ -
+
+
+ 串口号
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 校验位
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
-
+
+ 1
+
+
+ -
+
+ 2
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 数据位
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
-
+
+ 115200
+
+
+ -
+
+ 4800
+
+
+ -
+
+ 9600
+
+
+ -
+
+ 19200
+
+
+ -
+
+ 38400
+
+
+ -
+
+ 57600
+
+
+
+
+ -
+
+
+ 波特率
+
+
+
+ -
+
+
-
+
+ 8
+
+
+ -
+
+ 5
+
+
+ -
+
+ 6
+
+
+ -
+
+ 7
+
+
+
+
+ -
+
+
+ 打开串口
+
+
+
+
+
+ -
+
+
+ -
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 打开文件
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 读取配置文件
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ 下发配置文件
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 58
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+