Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement Network debugging Assistant with Qt

Shulou Source: shulou.com Published: 2022-06-01 13:19:32 09月17日 Update

Editor to share with you how to achieve Qt network debugging assistant, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

I. Preface

The network debugging assistant and the serial port debugging assistant are a pair. Most of the communication between the Qt development project and the hardware is either serial communication (RS232 RS485 Modbus, etc.), or network communication (TCP UDP HTTP, etc.), so once these two aspects are involved, it is more or less inseparable from the corresponding debugging assistant to assist in program debugging, especially the hardware engineer. What's more, independent debugging tools of the third party are needed to verify whether the hardware is working properly, which can greatly avoid wrangling. Since there is no problem with the third party tools tested and the data sent and received are normal, it can basically be concluded that it is the problem of the software. At this time, it is estimated that the software engineer is in a panic.

Basic functions:

Hexadecimal data and ASCII data sending and receiving.

The timer sends automatically.

Automatically loads the last interface settings from the configuration file.

Automatically loads data from the configuration file and sends data from the drop-down box. You can fill in the frequently used data in send.txt.

The device analog reply can be enabled, and when a certain data is received, the analog device automatically replies to the data. Fill in the corresponding data format in device.txt.

You can send data to a single online connection, or you can check all to send.

Multiple client connections are supported for concurrency.

Single thread is used.

Four modes, tcp client, tcp server, udp client, udp server.

Second, the first step of the code: instantiate the corresponding class 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 (connect, tcpServer (tcpServer, tcpServer, tcpServer)), SIGNAL (SIGNAL, SIGNAL, SIGNAL)); (receiveData (SIGNAL,)); Connect (udpSocket, SIGNAL (readyRead ()), this, SLOT (readData (); second step: send and receive data void frmTcpClient::readData () {QByteArray data = tcpSocket- > readAll (); if (data.length () 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 ("[% 1QString str% 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) ) {if (App::Keys.at (I) = = buffer) {sendData (ip, port, App::Values.at (I)); break;}} 3. Effect diagram

The above is all the contents of this article "how to implement Network debugging Assistant in Qt". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data assistant network customer client hardware article communication serial port content multiple tools engineering engineer file server third party or device software Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Shulou Technology Xiaomi NVidia