Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Curve Monitoring by Qt

2025-01-19 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 curve monitoring by Qt". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Qt how to achieve curve monitoring" it!

I. Preface

The curve monitoring module is rarely used. It is mainly used to observe the real-time data collected by a device and the data collected by history. The data can be played back, and the corresponding communication port and controller can be selected on the right. Then the designated detector is selected for observation. From the time of selection, each data corresponds to a data point. As for the acquisition interval, this is set in the port management. Generally speaking, it is collected once a second.

Display curve chart controls, individuals strongly recommend open source qcustomplot or qwt,Qt5.7 after the integration of the qchart module also has curve controls, I think the use is still not friendly, and many people reflect that a large amount of data is basically off, can only do a small amount of data display, I have seen the complete source code of the qchart module, the writing is not very good, perhaps a lot of improvements later, or the Qt4 era if the quality assurance The quality of the code is leveraged, but it's a pity that Kia sold the Qt.

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 frmViewPlot::initPlot () {ui- > customPlot- > addGraph (); ui- > customPlot- > graph (0)-> setName ("concentration value"); ui- > customPlot- > graph (0)-> setPen (QColor (App::ColorPlotLine), LineWidth)) Ui- > customPlot- > graph (0)-> setScatterStyle (QCPScatterStyle (QCPScatterStyle::ssCircle, Qt::NoPen, QBrush (QColor (App::ColorPlotLine)), DotWidth); QFont font; font.setPixelSize (11); ui- > customPlot- > legend- > setFont (font); ui- > customPlot- > xAxis- > setLabelFont (font); ui- > customPlot- > yAxis- > setLabelFont (font) Ui- > customPlot- > xAxis- > setTickLabelFont (font); ui- > customPlot- > yAxis- > setTickLabelFont (font); ui- > customPlot- > xAxis- > setTickLabelType (QCPAxis::ltDateTime); ui- > customPlot- > xAxis- > setDateTimeFormat ("hh:mm:ss"); ui- > customPlot- > xAxis- > setAutoTickStep (false); ui- > customPlot- > xAxis- > setTickStep (TickStep); ui- > customPlot- > xAxis- > setRange (0, XMax, Qt::AlignRight); ui- > ui- (0100) Ui- > customPlot- > legend- > setVisible (true); QColor textColor = QColor (App::ColorPlotText); ui- > customPlot- > yAxis- > setLabelColor (textColor); ui- > customPlot- > xAxis- > setTickLabelColor (textColor); ui- > customPlot- > yAxis- > setTickLabelColor (textColor); ui- > customPlot- > xAxis- > setBasePen (QPen (textColor)); ui- > customPlot- > yAxis- > setBasePen (QPen (textColor); ui- > customPlot- > customPlot- > customPlot- (xAxis-); > xAxis- > xAxis- > (xAxis-)) Ui- > customPlot- > xAxis- > setSubTickPen (QPen (textColor)); ui- > customPlot- > yAxis- > setSubTickPen (QPen (textColor)); ui- > customPlot- > xAxis- > grid ()-> setPen (QPen (textColor)); ui- > customPlot- > yAxis- > grid ()-> setPen (QPen (textColor)); ui- > customPlot- > yAxis- > grid ()-> setZeroLinePen (QPen (textColor); ui- > customPlot- > setBackground (setBackground); / / QColor > App::ColorPlotBg > App::ColorPlotBg > App::ColorPlotBg (90) Ui- > customPlot- > yAxis- > setAutoTickCount (30); ui- > customPlot- > replot (); / / ui- > customPlot- > installEventFilter (this);} void frmViewPlot::loadPlot () {/ / remove the first data and add one data to ensure that each collection data is consistent labs.remove (0,1); labs.append (TIME); values.remove (0,1); values.append (currentValue); ui- > customPlot- > graph (0)-> setData (keys, values) Ui- > customPlot- > xAxis- > setTickVector (keys); ui- > customPlot- > xAxis- > setTickVectorLabels (labs); ui- > customPlot- > replot ();} void frmViewPlot::initData () {whereSql = "where 1y1"; columnNames btnFirst, ui- > btnPre, ui- > btnNext, ui- > btnLast, "LogID"); dbPage- > setWhereSql (whereSql); dbPage- > select () / / bind button toggles load data connect (ui- > btnFirst, SIGNAL (clicked ()), this, SLOT (loadData ()); connect (ui- > btnPre, SIGNAL (clicked ()), this, SLOT (loadData (); connect (ui- > btnNext, SIGNAL (clicked ()), this, SLOT (loadData (); connect (ui- > btnLast, SIGNAL (clicked ()), this, SLOT (loadData ();} void frmViewPlot::loadData () {keys.clear () Labs.clear (); values.clear (); / / load the data in the current table QAbstractItemModel * model = ui- > tableView- > model (); int count = model- > rowCount (); for (int I = 0; I

< count; i++) { QModelIndex modelIndex = model->

Index (I, 4); QModelIndex labIndex = model- > index (I, 6); double value = model- > data (modelIndex). ToDouble (); QString strDate = model- > data (labIndex). ToString (). Right (8); keys setData (keys, values); ui- > customPlot- > xAxis- > setTickVector (keys); ui- > customPlot- > xAxis- > setTickVectorLabels (labs); ui- > customPlot- > replot () } void frmViewPlot::receiveValue (const QString & positionID, float value) {if (ui- > ckPause- > isChecked ()) {return;} / / must be a real-time curve to display if (ui- > cboxType- > currentText ()! = "real-time curve") {return } / / find the index corresponding to the current tag, and take out the value of the corresponding index location QString id = ui- > cboxNodeName- > itemData (ui- > cboxNodeName- > currentIndex ()). ToString (); if (id! = positionID) {return;} currentValue = value; / / the following increment shows the received data curve QVector keys; QVector datas; double key = QDateTime::currentDateTime (). ToMSecsSinceEpoch () / 1000.0 Keys.append (key); datas.append (currentValue); ui- > customPlot- > graph (0)-> addData (keys, datas); ui- > customPlot- > graph (0)-> removeDataBefore (key-XMax); ui- > customPlot- > xAxis- > setRange (key, XMax, Qt::AlignRight); ui- > customPlot- > replot ();} void frmViewPlot::receiveValue (const QString & portName, quint8 addr, const QList & values) {if (ui- > ckPause- > isChecked ()) {return } / / if (ui- > cboxType- > currentText ()! = "real-time curve") {return;} / / filter port if (ui- > cboxPortName- > currentText ()! = portName) {return;} / / filter device if (ui- > cboxDeviceName- > itemData (ui- > cboxDeviceName- > currentIndex ()). ToInt ()! = addr) {return } / / find the index corresponding to the current tag, and fetch the value of the corresponding index location QString positionID = ui- > cboxNodeName- > itemData (ui- > cboxNodeName- > currentIndex ()) .toString () / / find the device address of the current index position corresponds to the minimum register address of the detector / / if the starting register address read is 5, the first data bit returned is the data of register address 5, followed by quint16 nodeMinAddr = DBHelper::getNodeMinAddr (portName, addr); int index = DBData::NodeInfo_PositionID.indexOf (positionID); int startIndex = DBData::NodeInfo_NodeAddr.at (index)-nodeMinAddr-1 / / sometimes it is possible to add a total of 8 detectors but actually read 4 detectors if (startIndex > = values.count ()) {return;} currentValue = values.at (startIndex); / / the following addition shows QVector keys; QVector datas; double key = QDateTime::currentDateTime (). ToMSecsSinceEpoch () / 1000.0; keys.append (key) Datas.append (currentValue); ui- > customPlot- > graph (0)-> addData (keys, datas); ui- > customPlot- > graph (0)-> removeDataBefore (key-XMax); ui- > customPlot- > xAxis- > setRange (key, XMax, Qt::AlignRight); ui- > customPlot- > replot (); at this point, I believe you have a deeper understanding of "Qt how to achieve curve monitoring", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report