首页下载资源后端Qt 串口,多线程(子线程处理串口信号)

ZIPQt 串口,多线程(子线程处理串口信号)

qq_377306637.45MB需要积分:1

资源文件列表:

th-mcv.zip 大约有130个文件
  1. chart.cpp 2.56KB
  2. chart.h 1.95KB
  3. global.h 1.11KB
  4. image/
  5. image/0.png 6.29KB
  6. image/1.png 80.56KB
  7. image/11.png 83.5KB
  8. image/2.png 89.99KB
  9. image/22.png 92.5KB
  10. image/3.png 88.19KB
  11. image/33.png 90.42KB
  12. image/4.png 80.96KB
  13. image/44.png 83.83KB
  14. image/5.png 77.32KB
  15. image/6.png 83.22KB
  16. image/7.png 79.76KB
  17. image/8.png 81.89KB
  18. image/9.png 85.98KB
  19. image/99.png 88.52KB
  20. image/banben.png 65.59KB
  21. image/bg.png 565B
  22. image/cai.png 70.29KB
  23. image/cai2.png 70.8KB
  24. image/clear.png 1.07KB
  25. image/close.png 70.18KB
  26. image/close2.png 70.95KB
  27. image/dot.png 563B
  28. image/fold.png 909B
  29. image/frame.jpg 119.01KB
  30. image/frame.png 1.17MB
  31. image/go-previous.png 1.11KB
  32. image/image/
  33. image/image/1.png 80.56KB
  34. image/image/11.png 83.5KB
  35. image/image/2.png 89.99KB
  36. image/image/22.png 92.5KB
  37. image/image/3.png 88.19KB
  38. image/image/33.png 90.42KB
  39. image/image/360logo.png 67.22KB
  40. image/image/4.png 80.96KB
  41. image/image/44.png 83.83KB
  42. image/image/5.png 77.32KB
  43. image/image/55.png 79.86KB
  44. image/image/6.png 83.22KB
  45. image/image/66.png 86.49KB
  46. image/image/7.png 79.76KB
  47. image/image/77.png 82.3KB
  48. image/image/8.png 81.89KB
  49. image/image/88.png 84.66KB
  50. image/image/9.png 85.98KB
  51. image/image/99.png 88.52KB
  52. image/image/cai.png 70.29KB
  53. image/image/cai2.png 70.8KB
  54. image/image/close.png 70.18KB
  55. image/image/close2.png 70.95KB
  56. image/image/e.ico 167.01KB
  57. image/image/frame.jpg 119.01KB
  58. image/image/frame.png 1.21MB
  59. image/image/frame1.png 1.09MB
  60. image/image/max.png 70.04KB
  61. image/image/max2.png 70.33KB
  62. image/image/min.png 70.2KB
  63. image/image/min2.png 70.44KB
  64. image/image/screen.png 4.26KB
  65. image/image/title.ico 16.56KB
  66. image/images/
  67. image/images/0.png 6.29KB
  68. image/images/1.png 3.36KB
  69. image/images/2.png 5.85KB
  70. image/images/3.png 5.49KB
  71. image/images/4.png 6.36KB
  72. image/images/5.png 5.1KB
  73. image/images/6.png 5.68KB
  74. image/images/7.png 5.45KB
  75. image/images/8.png 6.41KB
  76. image/images/9.png 5.77KB
  77. image/images/bg.png 565B
  78. image/images/dot.png 563B
  79. image/images/title.ico 16.56KB
  80. image/main_about.png 13.77KB
  81. image/main_company.png 16.99KB
  82. image/main_config.png 21.15KB
  83. image/main_data.png 19.94KB
  84. image/main_exit.png 21.9KB
  85. image/main_help.png 13.85KB
  86. image/main_main.png 19.13KB
  87. image/main_person.png 23.94KB
  88. image/max.png 70.04KB
  89. image/max2.png 70.33KB
  90. image/min.png 70.2KB
  91. image/min2.png 70.44KB
  92. image/qt-logo.png 5.03KB
  93. image/redo.png 1.71KB
  94. image/screen.png 4.26KB
  95. image/services.png 3.66KB
  96. image/snowIcons/
  97. image/snowIcons/01.png 32.2KB
  98. image/snowIcons/02.png 30.1KB
  99. image/snowIcons/03.png 11.82KB
  100. image/snowIcons/04.png 21.4KB
  101. image/snowIcons/05.png 19.3KB
  102. image/snowIcons/06.png 20.4KB
  103. image/snowIcons/07.png 17.03KB
  104. image/snowIcons/08.png 18.97KB
  105. image/snowIcons/09.png 19.81KB
  106. image/snowIcons/10.png 16.72KB
  107. image/snowIcons/11.png 18.95KB
  108. image/snowIcons/12.png 17.83KB
  109. image/snowIcons/13.png 21.7KB
  110. image/snowIcons/14.png 22.19KB
  111. image/snowIcons/15.png 15.2KB
  112. image/snowIcons/16.png 18.04KB
  113. image/snowIcons/17.png 19.75KB
  114. image/snowIcons/18.png 19.23KB
  115. image/snowIcons/19.png 21.61KB
  116. image/snowIcons/20.png 20.51KB
  117. image/snowIcons/21.png 17.12KB
  118. image/snowIcons/22.png 12.13KB
  119. image/title.ico 16.56KB
  120. image/undo.png 1.73KB
  121. image/unfold.png 963B
  122. main.cpp 173B
  123. masterthread.cpp 6.51KB
  124. masterthread.h 3.34KB
  125. mianw.cpp 5.41KB
  126. mianw.h 912B
  127. mianw.ui 10.54KB
  128. myss.qrc 501B
  129. th-mcv.pro 1.35KB
  130. th-mcv.pro.user 23.4KB

资源介绍:

个人demo,看私信挺多的,免费分享
/**************************************************************************** ** ** Copyright (C) 2012 Denis Shienkov ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "masterthread.h" #include #include QT_USE_NAMESPACE MasterThread::MasterThread(QObject *parent) : QThread(parent), waitTimeout(0), quit(false) { } //! [0] MasterThread::~MasterThread() { mutex.lock(); quit = true; cond.wakeOne(); mutex.unlock(); wait(); } //! [0] //! [1] //! [2] void MasterThread::transaction(const QString &portName, int waitTimeout, const QString &request) { //! [1] QMutexLocker locker(&mutex); this->portName = portName; this->waitTimeout = waitTimeout; this->request = request; //! [3] if (!isRunning()) start(); else cond.wakeOne(); } void MasterThread::sendcmd(const QString &portName, int waitTimeout, char *txbuf, int lenth) { //! [1] QMutexLocker locker(&mutex); this->portName = portName; this->waitTimeout = waitTimeout; this->cmdBuf=txbuf; this->cmdLenth = lenth; //! [3] if (!isRunning()) start(); else cond.wakeOne(); } //! [2] //! [3] //! [4] void MasterThread::run() { bool currentPortNameChanged = false; mutex.lock(); //! [4] //! [5] QString currentPortName; if (currentPortName != portName) { currentPortName = portName; currentPortNameChanged = true; } int currentWaitTimeout = waitTimeout; QString currentRequest = request; mutex.unlock(); //! [5] //! [6] QSerialPort serial; if (currentPortName.isEmpty()) { emit error(tr("No port name specified")); return; } while (!quit) { //![6] //! [7] if (currentPortNameChanged) { serial.close(); serial.setPortName(currentPortName); // serial.setBaudRate(QSerialPort::Baud115200); serial.setDataBits(QSerialPort::Data8); serial.setParity(QSerialPort::NoParity); serial.setStopBits(QSerialPort::OneStop); serial.setFlowControl(QSerialPort::NoFlowControl); serial.setReadBufferSize(8); if (!serial.open(QIODevice::ReadWrite)) { emit error(tr("Can't open %1, error code %2") .arg(portName).arg(serial.error())); return; } } //! [7] //! [8] // write request //QByteArray requestData = currentRequest.toLocal8Bit(); //serial.write(requestData); //serial.write(this->cmdBuf, this->cmdLenth); QByteArray ba2(this->cmdBuf,this->cmdLenth); serial.write(ba2); if (serial.waitForBytesWritten(waitTimeout)) { //! [8] //! [10] // read response if (serial.waitForReadyRead(currentWaitTimeout)) { QByteArray responseData = serial.readAll(); while (serial.waitForReadyRead(10)) responseData += serial.readAll(); this->rxBufSize=responseData.size(); this->rxBuf= responseData.data(); QString response(responseData); //! [12] emit this->response(response); //! [10] //! [11] //! [12] } else { emit timeout(tr("Wait read response timeout %1") .arg(QTime::currentTime().toString())); } //! [9] //! [11] } else { emit timeout(tr("Wait write request timeout %1") .arg(QTime::currentTime().toString())); } //! [9] //! [13] mutex.lock(); cond.wait(&mutex); if (currentPortName != portName) { currentPortName = portName; currentPortNameChanged = true; } else { currentPortNameChanged = false; } currentWaitTimeout = waitTimeout; currentRequest = request; mutex.unlock(); } //! [13] } void MasterThread::stop(){ quit =true; }
100+评论
captcha