From 133ffc843497fea0b3b312b87b8316a6ac2f8d4a Mon Sep 17 00:00:00 2001
From: daniao2017 <2868108923@qq.com>
Date: Fri, 18 Sep 2020 10:15:52 +0800
Subject: [PATCH] first commit
---
code/Serial/Serial.pro | 31 +++
code/Serial/Serial.pro.user | 319 +++++++++++++++++++++++++++++
code/Serial/favicon.ico | Bin 0 -> 1150 bytes
code/Serial/main.cpp | 11 +
code/Serial/mainwindow.cpp | 140 +++++++++++++
code/Serial/mainwindow.h | 38 ++++
code/Serial/mainwindow.ui | 211 +++++++++++++++++++
code/Serial/mainwindow.ui.autosave | 216 +++++++++++++++++++
8 files changed, 966 insertions(+)
create mode 100644 code/Serial/Serial.pro
create mode 100644 code/Serial/Serial.pro.user
create mode 100644 code/Serial/favicon.ico
create mode 100644 code/Serial/main.cpp
create mode 100644 code/Serial/mainwindow.cpp
create mode 100644 code/Serial/mainwindow.h
create mode 100644 code/Serial/mainwindow.ui
create mode 100644 code/Serial/mainwindow.ui.autosave
diff --git a/code/Serial/Serial.pro b/code/Serial/Serial.pro
new file mode 100644
index 0000000..d237438
--- /dev/null
+++ b/code/Serial/Serial.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 \
+ mainwindow.cpp
+
+HEADERS += \
+ mainwindow.h
+
+FORMS += \
+ mainwindow.ui
+RC_ICONS = favicon.ico
+# 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/code/Serial/Serial.pro.user b/code/Serial/Serial.pro.user
new file mode 100644
index 0000000..1fb0929
--- /dev/null
+++ b/code/Serial/Serial.pro.user
@@ -0,0 +1,319 @@
+
+
+
+
+
+ EnvironmentId
+ {2b3fd6c7-596f-41ff-b2c9-c86048cf1ead}
+
+
+ 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
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop Qt 5.9.9 MinGW 32bit
+ Desktop Qt 5.9.9 MinGW 32bit
+ qt.qt5.599.win32_mingw53_kit
+ 0
+ 0
+ 0
+
+ D:/qt_study/Serial/build-Serial-Desktop_Qt_5_9_9_MinGW_32bit-Debug
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ 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
+
+
+ D:/qt_study/Serial/build-Serial-Desktop_Qt_5_9_9_MinGW_32bit-Release
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ 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
+
+
+ D:/qt_study/Serial/build-Serial-Desktop_Qt_5_9_9_MinGW_32bit-Profile
+
+
+ true
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ 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
+
+ 3
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ 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:/qt_study/Serial/Serial/Serial.pro
+ D:/qt_study/Serial/Serial/Serial.pro
+
+ false
+
+ false
+ true
+ true
+ false
+ false
+ true
+
+ D:/qt_study/Serial/build-Serial-Desktop_Qt_5_9_9_MinGW_32bit-Debug
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
diff --git a/code/Serial/favicon.ico b/code/Serial/favicon.ico
new file mode 100644
index 0000000000000000000000000000000000000000..67613b94014f1e09354443468d236317fdd109f3
GIT binary patch
literal 1150
zcmcJOu}T9$6h*JmR@urrl~`E3$`24fB3PtOxwT!$7fFgB2=OmOtWyWEmgL-I1_ox;
z4Z#g3Z|1&xGc(IXI^oka;(MscnRF@X8jw)-Iz^)QA5Yu1BUr(@C-#o=UQ%{Kjh@)M
zD)L@8^8Bxw)>vmB^Ie|mb4+1S^gLe{*b~r|ze0b91^D%gdJE%%A>)85pZpEIIefrP
z-bY!{13L5RHwN@)@CEl}HuVF&PyQ3%-647W4fybt=mFLG_Jhy;1Q%5>3G@QG
z@(<{b@KbcB(+{ZfzlMrtN8b1OnEQLw|EJj6!Nbi)dOekv-+LD4(wy-#yd*rfmOZY{
GIJ*TB4iv)x
literal 0
HcmV?d00001
diff --git a/code/Serial/main.cpp b/code/Serial/main.cpp
new file mode 100644
index 0000000..fd3e533
--- /dev/null
+++ b/code/Serial/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/code/Serial/mainwindow.cpp b/code/Serial/mainwindow.cpp
new file mode 100644
index 0000000..78e8f11
--- /dev/null
+++ b/code/Serial/mainwindow.cpp
@@ -0,0 +1,140 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+ , ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+ //user
+ system_init();
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+/*-------------------------------------
+ * funtions
+ * -----------------------------------*/
+
+void MainWindow::system_init(){
+ //port config
+ global_port.setParity(QSerialPort::NoParity);
+ global_port.setDataBits(QSerialPort::Data8);
+ global_port.setStopBits(QSerialPort::OneStop);
+
+ //connect
+ connect(ui->btn_open,&QPushButton::clicked,this,&MainWindow::btn_open_port);
+ connect(ui->btn_send_data,&QPushButton::clicked,this,&MainWindow::btn_open_port);
+ connect(&global_port,&QSerialPort::readyRead,this,&MainWindow::receive_data);
+ connect(ui->btn_close,&QPushButton::clicked,this,&MainWindow::btn_close_port);
+
+ //fix
+ this->setFixedSize( this->width (),this->height ());
+
+
+
+}
+
+/*------------------------------------
+ * slot
+ * ---------------------------------*/
+
+void MainWindow::btn_open_port(bool){
+
+ //qDebug()<< ui->cmb_port_name->currentIndex();
+ /*----------------------port---------------*/
+ switch (ui->cmb_port_name->currentIndex()) {
+ case 0 :
+ global_port.setPortName("COM1");
+ break;
+ case 1 :
+ global_port.setPortName("COM2");
+ break;
+ case 2 :
+ global_port.setPortName("COM3");
+ break;
+ case 3 :
+ global_port.setPortName("COM4");
+ break;
+ case 4 :
+ global_port.setPortName("COM5");
+ break;
+ case 5 :
+ global_port.setPortName("COM6");
+ break;
+ case 6 :
+ global_port.setPortName("COM7");
+ break;
+ default:
+ global_port.setPortName("COM8");
+ break;
+ }
+ /*----------------baud_rate--------------------*/
+ switch (ui->cmb_baud_rate->currentIndex()) {
+ case 0 :
+ global_port.setBaudRate(QSerialPort::Baud115200);
+ break;
+ case 1 :
+ global_port.setBaudRate(QSerialPort::Baud57600);
+ break;
+ case 2 :
+ global_port.setBaudRate(QSerialPort::Baud38400);
+ break;
+ case 3 :
+ global_port.setBaudRate(QSerialPort::Baud19200);
+ break;
+ case 4 :
+ global_port.setBaudRate(QSerialPort::Baud9600);
+ break;
+ case 5 :
+ global_port.setBaudRate(QSerialPort::Baud4800);
+ break;
+ case 6 :
+ global_port.setBaudRate(QSerialPort::Baud2400);
+ break;
+ case 7 :
+ global_port.setBaudRate(QSerialPort::Baud1200);
+ break;
+ default:
+ global_port.setBaudRate(QSerialPort::Baud9600);
+ break;
+ }
+
+ /*--------------------open---------------------*/
+ global_port.open(QIODevice::ReadWrite);
+ ui->lab_status->setText("Connected");
+
+
+}
+/*---------------sending data -------------------*/
+void MainWindow::btn_send_data(bool){
+
+ QString data = ui->lineEdit->text();
+ QByteArray array = data.toLatin1();
+ global_port.write(array);
+
+}
+
+/*------------------receive data -----------------*/
+void MainWindow::receive_data(){
+ QByteArray array = global_port.readAll();
+ qDebug() <checkBox->checkState() == Qt::Checked){
+ ui ->plainTextEdit ->insertPlainText(QString(array.toHex(' ')).append(' '));
+ }
+ else{
+ ui ->plainTextEdit ->insertPlainText(QString(array));
+ }
+
+}
+
+/*-----------------------close port----------------------*/
+void MainWindow::btn_close_port(bool){
+ global_port.close();
+ ui->lab_status->setText("Disconnected");
+}
+
+
diff --git a/code/Serial/mainwindow.h b/code/Serial/mainwindow.h
new file mode 100644
index 0000000..2033bcd
--- /dev/null
+++ b/code/Serial/mainwindow.h
@@ -0,0 +1,38 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include
+/*-----------user-----------*/
+//port
+#include
+//debug
+#include
+/*-------------------------*/
+QT_BEGIN_NAMESPACE
+namespace Ui { class MainWindow; }
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = nullptr);
+ ~MainWindow();
+public slots:
+ //button
+ void btn_open_port(bool);
+ void btn_send_data(bool);
+ void btn_close_port(bool);
+
+ //receive_data
+ void receive_data();
+
+private:
+ Ui::MainWindow *ui;
+ /*----------funtion-----------*/
+ void system_init();
+ /*----------variable----------*/
+ QSerialPort global_port ;
+};
+#endif // MAINWINDOW_H
diff --git a/code/Serial/mainwindow.ui b/code/Serial/mainwindow.ui
new file mode 100644
index 0000000..7ce84e3
--- /dev/null
+++ b/code/Serial/mainwindow.ui
@@ -0,0 +1,211 @@
+
+
+ MainWindow
+
+
+
+ 0
+ 0
+ 557
+ 362
+
+
+
+ MainWindow
+
+
+
+
+
+ 30
+ 50
+ 281
+ 261
+
+
+
+
+
+
+
+
+ 20
+ 80
+ 231
+ 161
+
+
+
+
+
+
+ 10
+ 30
+ 272
+ 30
+
+
+
+ -
+
+
+ -
+
+
+ send
+
+
+
+
+
+
+
+
+
+ 340
+ 50
+ 151
+ 241
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
-
+
+ COM1
+
+
+ -
+
+ COM2
+
+
+ -
+
+ COM3
+
+
+ -
+
+ COM4
+
+
+ -
+
+ COM5
+
+
+ -
+
+ COM6
+
+
+ -
+
+ COM7
+
+
+ -
+
+ COM8
+
+
+
+
+ -
+
+
-
+
+ 115200
+
+
+ -
+
+ 57600
+
+
+ -
+
+ 38400
+
+
+ -
+
+ 19200
+
+
+ -
+
+ 9600
+
+
+ -
+
+ 4800
+
+
+ -
+
+ 2400
+
+
+ -
+
+ 1200
+
+
+
+
+ -
+
+
+ Hex
+
+
+
+ -
+
+
+ Open
+
+
+
+ -
+
+
+ Close
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/code/Serial/mainwindow.ui.autosave b/code/Serial/mainwindow.ui.autosave
new file mode 100644
index 0000000..3697012
--- /dev/null
+++ b/code/Serial/mainwindow.ui.autosave
@@ -0,0 +1,216 @@
+
+
+ MainWindow
+
+
+
+ 0
+ 0
+ 579
+ 407
+
+
+
+ MainWindow
+
+
+
+
+ true
+
+
+
+ 30
+ 50
+ 281
+ 261
+
+
+
+
+
+
+
+
+ 20
+ 80
+ 231
+ 161
+
+
+
+
+
+
+ 10
+ 30
+ 272
+ 30
+
+
+
+ -
+
+
+ -
+
+
+ send
+
+
+
+
+
+
+
+
+
+ 340
+ 50
+ 151
+ 241
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
-
+
+ COM1
+
+
+ -
+
+ COM2
+
+
+ -
+
+ COM3
+
+
+ -
+
+ COM4
+
+
+ -
+
+ COM5
+
+
+ -
+
+ COM6
+
+
+ -
+
+ COM7
+
+
+ -
+
+ COM8
+
+
+
+
+ -
+
+
-
+
+ 115200
+
+
+ -
+
+ 57600
+
+
+ -
+
+ 38400
+
+
+ -
+
+ 19200
+
+
+ -
+
+ 9600
+
+
+ -
+
+ 4800
+
+
+ -
+
+ 2400
+
+
+ -
+
+ 1200
+
+
+
+
+ -
+
+
+ Hex
+
+
+
+ -
+
+
+ Open
+
+
+
+ -
+
+
+ Close
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+ groupBox_2
+ groupBox
+
+
+
+
+
+