In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to achieve simulation tools in Qt". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to achieve simulation tools in Qt".
I. Preface
Simulation tools are particularly useful and needed in some programs involving hardware communication. Reviewing the projects done in the past decade, 95% of the projects are interactive between software and hardware, and it seems that the projects with the combination of software and hardware have more vitality. Pure software or pure hardware is not so easy to control. If it is a combination of hardware and software, even if the hardware does not make money, you can still make money by controlling software parts and services. And if the software is free, then you must buy hardware, and you must run on this hardware in order to give full play to the effect of the software. There are also many examples of software making money from hardware for free. Over the years, I have come into contact with dozens of companies of all kinds. It is a similar situation. The combination of software and hardware plus services, the products matched by the three have the strongest vitality and can go further.
Back to the topic of the article, the main purpose of the simulation tool is to write software to simulate the data of the lower computer according to the communication protocol agreed at the beginning, when the hardware is not fully mature, and then use it to test the main program to determine whether the data protocol parsing is correct. It is estimated that this is the case for most small companies. After the project starts, the software and hardware usually start at the same time. The hardware will not wait until the software is completed, and the software will not wait until the hardware is mature. those are impractical, and the two need to be adjusted continuously before they are finally mature and stable. hardware engineers generally use tools such as serial port debugging assistant and network debugging assistant to check whether the data of the lower computer is correct, and use the tool to send the corresponding data to see if the response of the lower computer is correct. And software engineers need to write their own programs to simulate hardware data, especially to do stress tests. after all, even if the hardware is done, it is impossible to connect a lot of devices to you for testing in most scenarios, and the site is not that large, so they need to write their own programs to do stress tests to simulate the sending and receiving of data from hundreds of devices. For software, it is nothing more than new classes or control the number. It is still easier than hardware engineers. Of course, these simulation tests belong to simulation tests, and the real scenarios still need to be tested by devices, but after the software simulation devices are debugged, compared with 80% of the testing functions, the external real device tests only need to deal with special cases.
II. Functional features
Collect data port, support serial port + network port, serial port support free setting of serial number + baud rate, network support free setting of IP address + communication port, each port supports collection cycle, default one address per second, support setting communication timeout times, default 3 times, support maximum reconnection time, used to re-read offline devices.
Controller information, you can add the controller name, select the controller address + controller model, and set the number of detectors under the controller.
Detector information, can add tag, free to choose detector type, gas type, gas symbol, high reported value, low reported value, buffer value, clear zero value, whether enabled, alarm sound, background map, storage cycle, numerical conversion decimal places, alarm delay time, alarm type (HH,LL,HL) and so on.
Controller model + detector type + gas type + gas symbol, all can be configured freely.
Maps can be imported and deleted, and all detectors can be dragged and saved freely.
Port information + controller information + detector information, support import and export + export to excel+ printing.
Run record + alarm record + user record, support multi-condition combination query, such as time period + controller + detector, etc., all records can be exported to excel+ printing.
Records exported to excel support all versions of table files such as excel+wps and do not rely on software such as excel.
You can delete data within a specified time range, support automatic cleaning of early data, and set the maximum number of saved records.
Support alarm short message forwarding, support multiple receiving mobile phone numbers, you can set the sending interval, such as instant sending or sending all alarm messages once every 6 hours, the text message content is too long, automatically split multiple text messages.
Support alarm email forwarding, support multiple receiving mailboxes, can set sending interval, such as immediate sending or sending all alarm messages once every 6 hours, support attachment sending.
Overreport color + underreport color + normal color + 0 value color + curve background + curve color, etc., are free to choose.
The Chinese title + English title + logo path + copyright of the software can be set freely.
Provide switch settings for boot operation + alarm sound + automatic login + remember password and so on.
Alarm sound can be set to play the number of times, the interface provides 17 kinds of skin file selection.
Cloud data synchronization is supported, and the information of cloud database can be set, such as database name, user name + password, etc.
Support network forwarding and network reception, after the network reception is turned on, the software receives data from udp for analysis. Network forwarding supports multiple target IP, so it realizes the software of local collection, and freely transfers the data to the client to view the detector data at any time.
Automatically remember the user's last stay in the interface + other information, restart and apply automatically.
The alarm automatically switches to the corresponding map, and the detector button flashes.
Double-click the detector icon to control it back.
Support user rights management, administrator + operator two categories, user login + user exit, can remember the password and automatic login, more than three error messages and close the program.
Support four monitoring modes, equipment panel monitoring + map monitoring + table data monitoring + curve data monitoring, free to switch, four synchronous applications.
Support alarm relay linkage, a tag can link multiple modules and relay numbers across serial ports, and support many-to-many.
The local data store supports sqlite+mysql and remote data synchronization to the cloud database. Automatically reconnect.
The data collected by the local device is uploaded to the cloud in real time so that it can be extracted by other methods such as APP or web.
Two kinds of data sources are supported, one is serial port and network to collect equipment data through protocol, the other is database collection. The database acquisition mode can be used as a general system.
Comes with a device simulation tool that supports 16 device data simulations, as well as database data simulations to test data when there is no device.
The default communication protocol uses modbus protocol, and later increases the support of mqtt and other Internet of things protocols to make a general system.
Supports all windows operating systems + linux operating systems and other operating systems.
Third, effect picture
4. Core code void frmTool::checkData (const QByteArray & data, bool isCom) {int dataLen = data.length (); if (dataLen cboxDeviceType- > currentText (); if (type = = "FC-1003-1") {for (int I = 0; I)
< 1; i++) { body.append(QUIHelper::ushortToByte(spinBox.at(i)->Value ());}} else if (type = = "FC-1003-8") {for (int I = 0; I)
< 8; i++) { body.append(QUIHelper::ushortToByte(spinBox.at(i)->Value ());}} else if (type = = "FC-1003-16") {for (int I = 0; I)
< 16; i++) { body.append(QUIHelper::ushortToByte(spinBox.at(i)->Value ());}} else {for (int I = 0; I)
< 4; i++) { body.append(QUIHelper::ushortToByte(spinBox.at(i)->Value ());}} / / Analog reply data 01 03 08 00 14 03 12 00 00 00 79 E6 QByteArray buffer; buffer.append (ui- > cboxDeviceAddr- > currentText (). ToInt ()); buffer.append (0x03); buffer.append (body.length ()); buffer.append (body); buffer.append (QUIHelper::getCRCCode (buffer)); if (isCom) {com- > write (buffer) Append (1, QUIHelper::byteArrayToHexStr (data)); append (0, QUIHelper::byteArrayToHexStr (buffer));} else {tcpSocket- > write (buffer); append (5, QUIHelper::byteArrayToHexStr (data)); append (4, QUIHelper::byteArrayToHexStr (buffer));} void frmTool::append (int type, const QString & data, bool clear) {static int currentCount = 0; static int maxCount = 100 If (clear) {ui- > txtMain- > clear (); currentCount = 0; return;} if (currentCount > = maxCount) {ui- > txtMain- > clear (); currentCount = 0;} if (ui- > btnShowData- > text () = = "continue to show") {return;} / / filter carriage return feed QString strData = data StrData = strData.replace ("\ r", "); strData = strData.replace ("\ n ","); / / different types and colors display QString strType; if (type = = 0) {strType =" Serial Port send > > "; ui- > txtMain- > setTextColor (QColor (" dodgerblue "));} else if (type = = 1) {strType =" Serial Port receiving > " Ui- > txtMain- > setTextColor (QColor ("gray"));} else if (type = = 3) {strType = "checking > >"; ui- > txtMain- > setTextColor (QColor ("green"));} else if (type = = 4) {strType = "Network sending > >"; ui- > txtMain- > setTextColor (QColor (24,189,155)) } else if (type = = 5) {strType = "Network reception >"; ui- > txtMain- > setTextColor (QColor (100,184,255));} strData = QString ("time [% 1]% 2% 3") .arg (TIMEMS) .arg (strType) .arg (strData); ui- > txtMain- > append (strData); currentCount++ } void frmTool::on_btnOpen_clicked () {if (ui- > btnOpen- > text () = = "Open Serial Port") {com = new QextSerialPort (ui- > cboxPortName- > currentText (), QextSerialPort::Polling); isComOk = com- > open (QIODevice::ReadWrite); if (isComOk) {com- > setBaudRate ((BaudRateType) ui- > cboxBaudRate- > currentText (). ToInt ()); com- > setFlowControl (FLOW_OFF) Com- > setTimeout (10); ui- > btnOpen- > setText ("close serial port"); timerRead- > start ();}} else {timerRead- > stop (); com- > close (); com- > deleteLater (); ui- > btnOpen- > setText ("open serial port"); on_btnClearData_clicked (); isComOk = false }} void frmTool::on_btnListen_clicked () {if (ui- > btnListen- > text () = = "listening service") {int port = ui- > txtListenPort- > text (). ToInt (); # if (QT_VERSION > QT_VERSION_CHECK (5L0)) isTcpOk = tcpServer- > listen (QHostAddress::AnyIPv4, port); # else isTcpOk = tcpServer- > listen (QHostAddress::Any, port) # endif if (isTcpOk) {ui- > btnListen- > setText ("stop service");}} else {if (tcpSocket! = 0) {tcpSocket- > disconnectFromHost ();} tcpServer- > close (); ui- > btnListen- > setText ("listening service"); on_btnClearData_clicked (); isTcpOk = false }} void frmTool::on_btnClearData_clicked () {append (0, ", true);} Thank you for reading, the above is the content of" how to implement the simulation tool in Qt ". After the study of this article, I believe you have a deeper understanding of how to implement the simulation tool in Qt, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.