├── EasySerial.pro ├── EasySerial.pro.user ├── LICENSE ├── README.md ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui /EasySerial.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2022-05-15T21:53:32 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui serialport 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = EasySerial 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | mainwindow.cpp 30 | 31 | HEADERS += \ 32 | mainwindow.h 33 | 34 | FORMS += \ 35 | mainwindow.ui 36 | 37 | # Default rules for deployment. 38 | qnx: target.path = /tmp/$${TARGET}/bin 39 | else: unix:!android: target.path = /opt/$${TARGET}/bin 40 | !isEmpty(target.path): INSTALLS += target 41 | -------------------------------------------------------------------------------- /EasySerial.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {4022a5c4-4497-4a67-b1f2-eec4e3924feb} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 0 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | -fno-delayed-template-parsing 60 | 61 | true 62 | 63 | 64 | 65 | ProjectExplorer.Project.Target.0 66 | 67 | Desktop Qt 5.12.1 MSVC2017 64bit 68 | Desktop Qt 5.12.1 MSVC2017 64bit 69 | qt.qt5.5121.win64_msvc2017_64_kit 70 | 1 71 | 0 72 | 0 73 | 74 | D:/qtstudy/build-EasySerial-Desktop_Qt_5_12_1_MSVC2017_64bit-Debug 75 | 76 | 77 | true 78 | qmake 79 | 80 | QtProjectManager.QMakeBuildStep 81 | true 82 | 83 | false 84 | false 85 | false 86 | 87 | 88 | true 89 | Make 90 | 91 | Qt4ProjectManager.MakeStep 92 | 93 | false 94 | 95 | 96 | false 97 | 98 | 2 99 | Build 100 | 101 | ProjectExplorer.BuildSteps.Build 102 | 103 | 104 | 105 | true 106 | Make 107 | 108 | Qt4ProjectManager.MakeStep 109 | 110 | true 111 | clean 112 | 113 | false 114 | 115 | 1 116 | Clean 117 | 118 | ProjectExplorer.BuildSteps.Clean 119 | 120 | 2 121 | false 122 | 123 | Debug 124 | Debug 125 | Qt4ProjectManager.Qt4BuildConfiguration 126 | 2 127 | true 128 | 129 | 130 | D:/qtstudy/build-EasySerial-Desktop_Qt_5_12_1_MSVC2017_64bit-Release 131 | 132 | 133 | true 134 | qmake 135 | 136 | QtProjectManager.QMakeBuildStep 137 | false 138 | 139 | false 140 | false 141 | true 142 | 143 | 144 | true 145 | Make 146 | 147 | Qt4ProjectManager.MakeStep 148 | 149 | false 150 | 151 | 152 | false 153 | 154 | 2 155 | Build 156 | 157 | ProjectExplorer.BuildSteps.Build 158 | 159 | 160 | 161 | true 162 | Make 163 | 164 | Qt4ProjectManager.MakeStep 165 | 166 | true 167 | clean 168 | 169 | false 170 | 171 | 1 172 | Clean 173 | 174 | ProjectExplorer.BuildSteps.Clean 175 | 176 | 2 177 | false 178 | 179 | Release 180 | Release 181 | Qt4ProjectManager.Qt4BuildConfiguration 182 | 0 183 | true 184 | 185 | 186 | D:/qtstudy/build-EasySerial-Desktop_Qt_5_12_1_MSVC2017_64bit-Profile 187 | 188 | 189 | true 190 | qmake 191 | 192 | QtProjectManager.QMakeBuildStep 193 | true 194 | 195 | false 196 | true 197 | true 198 | 199 | 200 | true 201 | Make 202 | 203 | Qt4ProjectManager.MakeStep 204 | 205 | false 206 | 207 | 208 | false 209 | 210 | 2 211 | Build 212 | 213 | ProjectExplorer.BuildSteps.Build 214 | 215 | 216 | 217 | true 218 | Make 219 | 220 | Qt4ProjectManager.MakeStep 221 | 222 | true 223 | clean 224 | 225 | false 226 | 227 | 1 228 | Clean 229 | 230 | ProjectExplorer.BuildSteps.Clean 231 | 232 | 2 233 | false 234 | 235 | Profile 236 | Profile 237 | Qt4ProjectManager.Qt4BuildConfiguration 238 | 0 239 | true 240 | 241 | 3 242 | 243 | 244 | 0 245 | 部署 246 | 247 | ProjectExplorer.BuildSteps.Deploy 248 | 249 | 1 250 | Deploy Configuration 251 | 252 | ProjectExplorer.DefaultDeployConfiguration 253 | 254 | 1 255 | 256 | 257 | false 258 | false 259 | 1000 260 | 261 | true 262 | 263 | false 264 | false 265 | false 266 | false 267 | true 268 | 0.01 269 | 10 270 | true 271 | 1 272 | 25 273 | 274 | 1 275 | true 276 | false 277 | true 278 | valgrind 279 | 280 | 0 281 | 1 282 | 2 283 | 3 284 | 4 285 | 5 286 | 6 287 | 7 288 | 8 289 | 9 290 | 10 291 | 11 292 | 12 293 | 13 294 | 14 295 | 296 | 2 297 | 298 | EasySerial 299 | 300 | Qt4ProjectManager.Qt4RunConfiguration:D:/qtstudy/EasySerial/EasySerial.pro 301 | EasySerial.pro 302 | 303 | 3768 304 | false 305 | true 306 | true 307 | false 308 | false 309 | true 310 | 311 | D:/qtstudy/build-EasySerial-Desktop_Qt_5_12_1_MSVC2017_64bit-Release 312 | 313 | 1 314 | 315 | 316 | 317 | ProjectExplorer.Project.TargetCount 318 | 1 319 | 320 | 321 | ProjectExplorer.Project.Updater.FileVersion 322 | 20 323 | 324 | 325 | Version 326 | 20 327 | 328 | 329 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasySerial 2 | EasySerial A cross-platform open source serial port debugging assistant based on QT 3 | 4 | Serial port debugging assistant is a very suitable tool for debugging serial port equipment. There are many useful serial port debugging assistants in windows, but it seems that there is no easy-to-use software with interface on Linux system (there are still many tools for debugging with command line), but it is not so convenient to use. Therefore, based on QT's good cross platform characteristics, a simple cross platform serial port debugging assistant is developed to meet the basic serial port debugging requirements. Finally, open source sharing. The functions currently implemented include: 5 | 6 | Search serial port equipment; 7 | 8 | ASCII / hex receiving; 9 | 10 | Save the received data to TXT; 11 | 12 | ASCII / hex transmission; 13 | 14 | Periodic transmission; 15 | 16 | Read txt and send; 17 | 18 | Transmit / receive byte count; -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | MainWindow::MainWindow(QWidget *parent) : 12 | QMainWindow(parent), 13 | ui(new Ui::MainWindow) 14 | { 15 | ui->setupUi(this); 16 | 17 | RXCounts = 0; 18 | TXCounts = 0; 19 | TXLabel.setText("0"); 20 | RXLabel.setText("0"); 21 | this -> ui -> statusBar -> addPermanentWidget(new QLabel("TX")); 22 | this -> ui -> statusBar -> addPermanentWidget(&TXLabel); 23 | this -> ui -> statusBar -> addPermanentWidget(new QLabel("RX")); 24 | this -> ui -> statusBar -> addPermanentWidget(&RXLabel); 25 | pushButton_countClear.setText("Reset"); 26 | connect(&pushButton_countClear,&QPushButton::clicked,this,[=](){ 27 | RXCounts = 0; 28 | TXCounts = 0; 29 | TXLabel.setText("0"); 30 | RXLabel.setText("0"); 31 | }); 32 | this -> ui -> statusBar -> addPermanentWidget(&pushButton_countClear); 33 | 34 | connect(&serial,&QSerialPort::readyRead,this,&MainWindow::readSerialData); 35 | connect(&serial,&QSerialPort::errorOccurred,this,[=](QSerialPort::SerialPortError portErr){ 36 | this -> ui -> statusBar -> showMessage(QString("Serial error %1").arg(portErr),1000); 37 | }); 38 | 39 | recvToFile = false; 40 | display = true; 41 | recvASCII = true; 42 | 43 | sendCyclic = false; 44 | connect(&sendTimer,&QTimer::timeout,this,&MainWindow::sendSerialData); 45 | } 46 | 47 | MainWindow::~MainWindow() 48 | { 49 | delete ui; 50 | } 51 | 52 | void MainWindow::on_pushButton_search_clicked() 53 | { 54 | this -> ui -> comboBox_name -> clear(); 55 | foreach (QSerialPortInfo avaiablePort, QSerialPortInfo::availablePorts()) { 56 | this -> ui -> comboBox_name -> addItem(avaiablePort.portName()); 57 | } 58 | } 59 | 60 | 61 | void MainWindow::on_pushButton_open_clicked() 62 | { 63 | if(this->ui->pushButton_open->text() == "Open") 64 | { 65 | serial.setPortName(this->ui->comboBox_name->currentText()); 66 | serial.setBaudRate(this->ui->comboBox_baud->currentText().toInt()); 67 | switch (this -> ui -> comboBox_paity -> currentIndex()){ 68 | case 0: serial.setParity(QSerialPort::NoParity); break; 69 | case 1: serial.setParity(QSerialPort::EvenParity); break; 70 | case 2: serial.setParity(QSerialPort::OddParity); break; 71 | case 3: serial.setParity(QSerialPort::SpaceParity); break; 72 | case 4: serial.setParity(QSerialPort::MarkParity); break; 73 | default: serial.setParity(QSerialPort::UnknownParity); break; 74 | } 75 | switch (this->ui->comboBox_dataBits->currentText().toInt()){ 76 | case 5: serial.setDataBits(QSerialPort::Data5); break; 77 | case 6: serial.setDataBits(QSerialPort::Data6); break; 78 | case 7: serial.setDataBits(QSerialPort::Data7); break; 79 | case 8: serial.setDataBits(QSerialPort::Data8); break; 80 | default: serial.setDataBits(QSerialPort::UnknownDataBits); break; 81 | } 82 | switch (this->ui->comboBox_stopBits->currentIndex()){ 83 | case 0: serial.setStopBits(QSerialPort::OneStop); break; 84 | case 1: serial.setStopBits(QSerialPort::OneAndHalfStop); break; 85 | case 2: serial.setStopBits(QSerialPort::TwoStop); break; 86 | default: serial.setStopBits(QSerialPort::UnknownStopBits); break; 87 | } 88 | serial.setFlowControl(QSerialPort::NoFlowControl); 89 | 90 | if(serial.open(QIODevice::ReadWrite)) 91 | { 92 | this -> ui -> pushButton_search -> setEnabled(false); 93 | this -> ui -> comboBox_name -> setEnabled(false); 94 | this -> ui -> comboBox_baud -> setEnabled(false); 95 | this -> ui -> comboBox_paity -> setEnabled(false); 96 | this -> ui -> comboBox_dataBits -> setEnabled(false); 97 | this -> ui -> comboBox_stopBits -> setEnabled(false); 98 | this -> ui -> pushButton_open -> setText("Close"); 99 | QSerialPortInfo serialInfo(serial); 100 | }else { 101 | QMessageBox::warning(this,"Open Error","Serialport Open Error!"); 102 | } 103 | }else{ 104 | serial.close(); 105 | this -> ui -> pushButton_search -> setEnabled(true); 106 | this -> ui -> comboBox_name -> setEnabled(true); 107 | this -> ui -> comboBox_baud -> setEnabled(true); 108 | this -> ui -> comboBox_paity -> setEnabled(true); 109 | this -> ui -> comboBox_dataBits -> setEnabled(true); 110 | this -> ui -> comboBox_stopBits -> setEnabled(true); 111 | this -> ui -> pushButton_open -> setText("Open"); 112 | } 113 | } 114 | 115 | void MainWindow::readSerialData() 116 | { 117 | QByteArray recvData = serial.readAll(); 118 | RXCounts += recvData.length(); 119 | RXLabel . setText(QString::number(RXCounts)); 120 | 121 | QString newData; 122 | if(recvASCII) 123 | newData = QString(recvData); 124 | else 125 | newData = QString(recvData.toHex(' ')); 126 | 127 | if(display) 128 | { 129 | this -> ui -> textBrowser -> append(newData); 130 | } 131 | 132 | if(recvToFile) 133 | { 134 | QTextStream out(&recvFile); 135 | out << newData; 136 | } 137 | } 138 | 139 | void MainWindow::on_radioButton_recv_hex_clicked() 140 | { 141 | recvASCII = false; 142 | } 143 | 144 | void MainWindow::on_radioButton_recv_ascii_clicked() 145 | { 146 | recvASCII = true; 147 | } 148 | 149 | void MainWindow::on_pushButton_clear_recv_clicked() 150 | { 151 | this -> ui -> textBrowser -> clear(); 152 | } 153 | 154 | void MainWindow::on_checkBox_stop_display_clicked(bool checked) 155 | { 156 | display = !checked; 157 | } 158 | 159 | void MainWindow::on_checkBox_recv_to_file_clicked(bool checked) 160 | { 161 | if(checked) 162 | { 163 | recvFile.setFileName(QString("%1_%2.txt").arg(QDate::currentDate().toString("yy_MM_dd")).arg(QTime::currentTime().toString("hh_mm_ss"))); 164 | if(!recvFile.open(QIODevice::WriteOnly)) 165 | this -> ui -> statusBar -> showMessage("File open failed, try again!",1000); 166 | else{ 167 | recvToFile = true; 168 | } 169 | }else{ 170 | recvToFile = false; 171 | recvFile.close(); 172 | } 173 | } 174 | 175 | void MainWindow::on_radioButton_send_ascii_clicked() 176 | { 177 | if(!sendASCII) 178 | { 179 | QString hexStr = this -> ui -> textEdit -> toPlainText(); 180 | QString str = QByteArray::fromHex(hexStr.toLatin1()); 181 | this -> ui -> textEdit -> setText(str); 182 | sendASCII = true; 183 | } 184 | } 185 | 186 | void MainWindow::on_radioButton_send_hex_clicked() 187 | { 188 | if(sendASCII) 189 | { 190 | QString str = this -> ui -> textEdit -> toPlainText(); 191 | QString hexStr = str.toLatin1().toHex(' ').toUpper(); 192 | this -> ui -> textEdit -> setText(hexStr); 193 | sendASCII = false; 194 | } 195 | } 196 | 197 | void MainWindow::on_pushButton_clear_send_clicked() 198 | { 199 | this -> ui -> textEdit ->clear(); 200 | } 201 | 202 | void MainWindow::on_pushButton_send_clicked() 203 | { 204 | if(this -> ui -> pushButton_send -> text() == "Send") 205 | { 206 | if(serial.isOpen()) 207 | { 208 | if(sendCyclic) 209 | { 210 | sendTimer.start(period); 211 | this -> ui -> pushButton_send -> setText("Stop"); 212 | this -> ui -> checkBox_send_cyclic -> setEnabled(false); 213 | this -> ui -> lineEdit_send_period -> setEnabled(false); 214 | }else{ 215 | sendSerialData(); 216 | } 217 | } 218 | else { 219 | this -> ui -> statusBar -> showMessage("Serial closed, please open first",1000); 220 | } 221 | } 222 | else if(this -> ui -> pushButton_send -> text() == "Stop") { 223 | sendTimer.stop(); 224 | this -> ui -> pushButton_send -> setText("Send"); 225 | this -> ui -> checkBox_send_cyclic -> setEnabled(true); 226 | this -> ui -> lineEdit_send_period -> setEnabled(true); 227 | } 228 | } 229 | 230 | void MainWindow::on_checkBox_send_cyclic_clicked(bool checked) 231 | { 232 | if(checked) 233 | { 234 | if(this->ui->lineEdit_send_period -> text().isEmpty()) 235 | { 236 | QMessageBox::information(this,"Waring","Please edit period first"); 237 | this -> ui -> checkBox_send_cyclic -> setChecked(false); 238 | }else { 239 | period = this->ui->lineEdit_send_period -> text().toInt(); 240 | sendCyclic = true; 241 | } 242 | }else{ 243 | sendCyclic = false; 244 | } 245 | } 246 | 247 | void MainWindow::sendSerialData() 248 | { 249 | QByteArray sendData; 250 | if(sendASCII) 251 | { 252 | sendData = this -> ui -> textEdit -> toPlainText().toLatin1(); 253 | }else{ 254 | sendData = QByteArray::fromHex(this -> ui -> textEdit -> toPlainText().toLatin1()); 255 | } 256 | 257 | TXCounts += serial.write(sendData); 258 | this -> TXLabel . setText(QString::number(TXCounts)); 259 | } 260 | 261 | void MainWindow::on_pushButton_read_clicked() 262 | { 263 | QString fileName = QFileDialog::getOpenFileName(this,"Please select file","./","TXT(*.txt)"); 264 | QFile sendFile(fileName); 265 | if(!sendFile.open(QIODevice::ReadOnly)) 266 | QMessageBox::warning(this,"Error","File open failed, please try again"); 267 | QString sendStr = sendFile.readAll(); 268 | this -> ui -> textEdit -> setText(sendStr); 269 | } 270 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Ui { 12 | class MainWindow; 13 | } 14 | 15 | class MainWindow : public QMainWindow 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit MainWindow(QWidget *parent = nullptr); 21 | ~MainWindow(); 22 | 23 | private slots: 24 | void readSerialData(); 25 | void sendSerialData(); 26 | 27 | void on_pushButton_search_clicked(); 28 | 29 | void on_pushButton_open_clicked(); 30 | 31 | void on_radioButton_recv_hex_clicked(); 32 | 33 | void on_radioButton_recv_ascii_clicked(); 34 | 35 | void on_pushButton_clear_recv_clicked(); 36 | 37 | void on_checkBox_stop_display_clicked(bool checked); 38 | 39 | void on_checkBox_recv_to_file_clicked(bool checked); 40 | 41 | void on_radioButton_send_ascii_clicked(); 42 | 43 | void on_radioButton_send_hex_clicked(); 44 | 45 | void on_pushButton_clear_send_clicked(); 46 | 47 | void on_pushButton_send_clicked(); 48 | 49 | void on_checkBox_send_cyclic_clicked(bool checked); 50 | 51 | void on_pushButton_read_clicked(); 52 | 53 | private: 54 | Ui::MainWindow *ui; 55 | 56 | QSerialPort serial; 57 | 58 | int TXCounts; 59 | QLabel TXLabel; 60 | int RXCounts; 61 | QLabel RXLabel; 62 | QPushButton pushButton_countClear; 63 | 64 | bool recvToFile; 65 | bool display; 66 | bool recvASCII; 67 | 68 | bool sendASCII; 69 | 70 | QFile recvFile; 71 | 72 | bool sendCyclic; 73 | int period; //ms 74 | QTimer sendTimer; 75 | }; 76 | 77 | #endif // MAINWINDOW_H 78 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1000 10 | 800 11 | 12 | 13 | 14 | EasySerial 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Connect Control 24 | 25 | 26 | Qt::AlignCenter 27 | 28 | 29 | 30 | 31 | 32 | PortName: 33 | 34 | 35 | Qt::AlignCenter 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Baud: 46 | 47 | 48 | Qt::AlignCenter 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 4800 57 | 58 | 59 | 60 | 61 | 9600 62 | 63 | 64 | 65 | 66 | 14400 67 | 68 | 69 | 70 | 71 | 19200 72 | 73 | 74 | 75 | 76 | 38400 77 | 78 | 79 | 80 | 81 | 57600 82 | 83 | 84 | 85 | 86 | 115200 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | Paity: 95 | 96 | 97 | Qt::AlignCenter 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | No 106 | 107 | 108 | 109 | 110 | Even 111 | 112 | 113 | 114 | 115 | Odd 116 | 117 | 118 | 119 | 120 | Space 121 | 122 | 123 | 124 | 125 | Mark 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | DataBits: 134 | 135 | 136 | Qt::AlignCenter 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 8 145 | 146 | 147 | 148 | 149 | 7 150 | 151 | 152 | 153 | 154 | 6 155 | 156 | 157 | 158 | 159 | 5 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | StopBits: 168 | 169 | 170 | Qt::AlignCenter 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 1 179 | 180 | 181 | 182 | 183 | 1.5 184 | 185 | 186 | 187 | 188 | 2 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | Open 197 | 198 | 199 | 200 | 201 | 202 | 203 | Search 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | Recv Option 214 | 215 | 216 | Qt::AlignCenter 217 | 218 | 219 | 220 | 221 | 222 | Save 223 | 224 | 225 | 226 | 227 | 228 | 229 | Stop Display 230 | 231 | 232 | 233 | 234 | 235 | 236 | ASCII 237 | 238 | 239 | true 240 | 241 | 242 | 243 | 244 | 245 | 246 | HEX 247 | 248 | 249 | 250 | 251 | 252 | 253 | Clear 254 | 255 | 256 | 257 | 258 | 259 | 260 | Recv to File 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | Send Option 271 | 272 | 273 | Qt::AlignCenter 274 | 275 | 276 | 277 | 278 | 279 | ASCII 280 | 281 | 282 | true 283 | 284 | 285 | 286 | 287 | 288 | 289 | Send Cyclic 290 | 291 | 292 | 293 | 294 | 295 | 296 | Read 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | ms 307 | 308 | 309 | 310 | 311 | 312 | 313 | HEX 314 | 315 | 316 | 317 | 318 | 319 | 320 | Period: 321 | 322 | 323 | Qt::AlignCenter 324 | 325 | 326 | 327 | 328 | 329 | 330 | Clear 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | Data Recv 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | Data Send 357 | 358 | 359 | 360 | 361 | 362 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 363 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 364 | p, li { white-space: pre-wrap; } 365 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 366 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Hello,developer</p></body></html> 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 0 375 | 0 376 | 377 | 378 | 379 | Send 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 0 394 | 0 395 | 1000 396 | 17 397 | 398 | 399 | 400 | 401 | 402 | TopToolBarArea 403 | 404 | 405 | false 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | --------------------------------------------------------------------------------