日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python写网络调试助手_Qt开源作品4-网络调试助手

發布時間:2024/8/5 python 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python写网络调试助手_Qt开源作品4-网络调试助手 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

## 一、前言

網絡調試助手和串口調試助手是一對的,用Qt開發項目與硬件通信絕大部分都是要么串口通信(RS232 RS485 Modbus等),要么就是網絡通信(TCP UDP HTTP等),所以一旦涉及到這兩方面,多多少少肯定離不開對應的調試助手協助進行程序的調試,尤其是硬件工程師,更加需要第三方的獨立的調試工具來驗證硬件工作是否正常,這可以大大避免扯皮的事情發生,既然第三方的工具測試下來沒有問題,收發數據都正常的話,那基本上可以斷定是軟件的問題,此時估計軟件工程師心里慌得一逼啊!

基本功能:

  • 1. 16進制數據和ASCII數據收發。
  • 2. 定時器自動發送。
  • 3. 自動從配置文件加載最后一次的界面設置。
  • 4. 自動從配置文件加載數據發送下拉框的數據。可以將經常使用的數據填寫在send.txt中。
  • 5. 可啟用設備模擬回復,當收到某個數據時,模擬設備自動回復數據。對應數據格式填寫在device.txt中。
  • 6. 可對單個在線連接發送數據,也可勾選全部進行發送。
  • 7. 支持多個客戶端連接并發。
  • 8. 采用單線程。
  • 9. 四種模式,tcp客戶端、tcp服務器、udp客戶端、udp服務器。
  • ## 二、代碼思路

    第一步:實例化對應的類tcpSocket = new QTcpSocket(this);connect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(disconnected()));connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));tcpServer = new TcpServer(this);connect(tcpServer, SIGNAL(clientConnected(QString, int)), this, SLOT(clientConnected(QString, int)));connect(tcpServer, SIGNAL(clientDisconnected(QString, int)), this, SLOT(clientDisconnected(QString, int)));connect(tcpServer, SIGNAL(sendData(QString, int, QString)), this, SLOT(sendData(QString, int, QString)));connect(tcpServer, SIGNAL(receiveData(QString, int, QString)), this, SLOT(receiveData(QString, int, QString)));udpSocket = new QUdpSocket(this);connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readData()));第二步:收發數據void frmTcpClient::readData(){ QByteArray data = tcpSocket->readAll(); if (data.length() <= 0) { return; } QString buffer; if (App::HexReceiveTcpClient) { buffer = QUIHelper::byteArrayToHexStr(data); } else if (App::AsciiTcpClient) { buffer = QUIHelper::byteArrayToAsciiStr(data); } else { buffer = QString(data); } append(1, buffer); //自動回復數據,可以回復的數據是以;隔開,每行可以帶多個;所以這里不需要繼續判斷 if (App::DebugTcpClient) { int count = App::Keys.count(); for (int i = 0; i < count; i++) { if (App::Keys.at(i) == buffer) { sendData(App::Values.at(i)); break; } } }}void frmUdpClient::readData(){ QHostAddress host; quint16 port; QByteArray data; QString buffer; while (udpSocket->hasPendingDatagrams()) { data.resize(udpSocket->pendingDatagramSize()); udpSocket->readDatagram(data.data(), data.size(), &host, &port); if (App::HexReceiveUdpClient) { buffer = QUIHelper::byteArrayToHexStr(data); } else if (App::AsciiUdpClient) { buffer = QUIHelper::byteArrayToAsciiStr(data); } else { buffer = QString(data); } QString ip = host.toString(); ip = ip.replace("::ffff:", ""); if (ip.isEmpty()) { continue; } QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(buffer); append(1, str); if (App::DebugUdpClient) { int count = App::Keys.count(); for (int i = 0; i < count; i++) { if (App::Keys.at(i) == buffer) { sendData(ip, port, App::Values.at(i)); break; } } } }}

    ## 三、效果圖

    ## 四、開源主頁

    1. 國內站點:[https://gitee.com/feiyangqingyun/QWidgetDemo](https://gitee.com/feiyangqingyun/QWidgetDemo)

    2. 國際站點:[https://github.com/feiyangqingyun/QWidgetDemo](https://github.com/feiyangqingyun/QWidgetDemo)

    總結

    以上是生活随笔為你收集整理的python写网络调试助手_Qt开源作品4-网络调试助手的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。