no message

This commit is contained in:
95384 2024-11-29 18:23:27 +08:00
parent 195bc81c75
commit 3a93a67778
5 changed files with 794 additions and 10 deletions

View File

@ -1,4 +1,4 @@
QT += core gui QT += core gui serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.12.2, 2024-11-29T17:24:27. --> <!-- Written by QtCreator 4.12.2, 2024-11-29T18:23:12. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -54,7 +54,22 @@
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.PluginSettings</variable> <variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/> <valuemap type="QVariantMap">
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
<value type="QString">-fno-delayed-template-parsing</value>
</valuelist>
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
<value type="QString" key="ClangCodeModel.WarningConfigId">Builtin.Questionable</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">8</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.Target.0</variable> <variable>ProjectExplorer.Project.Target.0</variable>
@ -293,19 +308,19 @@
</valuelist> </valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/Y/QT/HSD_Config/HSD_Config.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value> <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">E:/Y/QT/HSD_Config/HSD_Config.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="QString" key="RunConfiguration.Arguments"></value> <value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value> <value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value> <value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value> <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value> <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value> <value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/Y/QT/build-HSD_Config-Desktop_Qt_5_12_9_MinGW_32_bit-Debug</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>

View File

@ -6,6 +6,17 @@ Widget::Widget(QWidget *parent)
, ui(new Ui::Widget) , ui(new Ui::Widget)
{ {
ui->setupUi(this); 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() Widget::~Widget()
@ -13,3 +24,152 @@ Widget::~Widget()
delete ui; delete ui;
} }
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;
}

View File

@ -2,6 +2,9 @@
#define WIDGET_H #define WIDGET_H
#include <QWidget> #include <QWidget>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QMessageBox>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class Widget; } namespace Ui { class Widget; }
@ -15,7 +18,16 @@ public:
Widget(QWidget *parent = nullptr); Widget(QWidget *parent = nullptr);
~Widget(); ~Widget();
private slots:
void on_SerialPort_refresh_pushButton_clicked();
void on_Open_Serial_pushButton_clicked();
private: private:
Ui::Widget *ui; Ui::Widget *ui;
private:
//串口
QSerialPort * Serial_port;
}; };
#endif // WIDGET_H #endif // WIDGET_H

603
widget.ui
View File

@ -6,13 +6,610 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>530</width>
<height>600</height> <height>231</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Widget</string> <string>HSD变频器控制</string>
</property> </property>
<property name="styleSheet">
<string notr="true"/>
</property>
<widget class="QWidget" name="widget" native="true">
<property name="geometry">
<rect>
<x>11</x>
<y>10</y>
<width>171</width>
<height>211</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QComboBox" name="SerialPort_comboBox">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="SerialPort_refresh_pushButton">
<property name="text">
<string>刷新</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_19" stretch="3,5">
<item>
<widget class="QLabel" name="BaudRate_label">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>波特率:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="BaudRate_comboBox">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="currentIndex">
<number>6</number>
</property>
<item>
<property name="text">
<string>110</string>
</property>
</item>
<item>
<property name="text">
<string>300</string>
</property>
</item>
<item>
<property name="text">
<string>600</string>
</property>
</item>
<item>
<property name="text">
<string>1200</string>
</property>
</item>
<item>
<property name="text">
<string>2400</string>
</property>
</item>
<item>
<property name="text">
<string>4800</string>
</property>
</item>
<item>
<property name="text">
<string>9600</string>
</property>
</item>
<item>
<property name="text">
<string>14400</string>
</property>
</item>
<item>
<property name="text">
<string>19200</string>
</property>
</item>
<item>
<property name="text">
<string>38400</string>
</property>
</item>
<item>
<property name="text">
<string>43000</string>
</property>
</item>
<item>
<property name="text">
<string>57600</string>
</property>
</item>
<item>
<property name="text">
<string>76800</string>
</property>
</item>
<item>
<property name="text">
<string>115200</string>
</property>
</item>
<item>
<property name="text">
<string>128000</string>
</property>
</item>
<item>
<property name="text">
<string>230400</string>
</property>
</item>
<item>
<property name="text">
<string>256000</string>
</property>
</item>
<item>
<property name="text">
<string>460800</string>
</property>
</item>
<item>
<property name="text">
<string>921600</string>
</property>
</item>
<item>
<property name="text">
<string>1000000</string>
</property>
</item>
<item>
<property name="text">
<string>2000000</string>
</property>
</item>
<item>
<property name="text">
<string>3000000</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_20" stretch="3,5">
<item>
<widget class="QLabel" name="DataBits_label">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>数据位:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="DataBits_comboBox">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="currentIndex">
<number>3</number>
</property>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_21" stretch="3,5">
<item>
<widget class="QLabel" name="CheckBits_label">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>校验位:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="CheckBits_comboBox">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<item>
<property name="text">
<string>无</string>
</property>
</item>
<item>
<property name="text">
<string>奇</string>
</property>
</item>
<item>
<property name="text">
<string>偶</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_22" stretch="3,5">
<item>
<widget class="QLabel" name="StopBits_label">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>停止位:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="StopBits_comboBox">
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>1.5</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_23" stretch="1,1">
<item>
<widget class="QPushButton" name="Open_Serial_pushButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>宋体</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>打开串口</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="serial_status_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(184, 0, 0); /* 背景 */
border-radius: 10px; /* 圆角半径 */</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>190</x>
<y>280</y>
<width>291</width>
<height>271</height>
</rect>
</property>
<property name="text">
<string>01062000000143CA 开
0106200000054209 关
0106100003E88DB4 5Hz
0106100002E2 0C23 6.5Hz
0106100007D0 8EA6 10Hz
010610000A64 8A41 13.3Hz
010610000C1C 89C3 15.5Hz
010610000E38 88B8 18.2Hz
010610000FA0 8882 20Hz
0106100010048109 20.5Hz
0106100014A0 8272 26.4Hz
010610001608 82AC 28.2Hz
010610001770 831E 30Hz
010610001A04 87A9 33.3Hz
010610001AE0 87E2 34.4Hz
010610001BBC 864B 35.5Hz</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>190</x>
<y>10</y>
<width>218</width>
<height>211</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="6,1">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>常用频率</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>5Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>10Hz</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>15Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_10">
<property name="text">
<string>20Hz</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>25Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>30Hz</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="pushButton_6">
<property name="text">
<string>35Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_7">
<property name="text">
<string>40Hz</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="pushButton_9">
<property name="text">
<string>45Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_8">
<property name="text">
<string>50Hz</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7" stretch="4,1">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QLineEdit" name="Input_lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_11">
<property name="text">
<string>设定频率</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>420</x>
<y>10</y>
<width>101</width>
<height>211</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="Start_BTM">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>500</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>启动</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="Stop_BTM">
<property name="minimumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>500</height>
</size>
</property>
<property name="text">
<string>停机</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>