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

What is the method of Qt port management

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the method of Qt port management". In the daily operation, I believe that many people have doubts about the method of Qt port management. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the method of Qt port management?" Next, please follow the editor to study!

I. Preface

There are three main points in the information configuration of all devices: Port management, controller management and detector management. the architecture of the whole hardware system is that there are several different communication ports (mainly serial port and network). Under each communication port, there are multiple controllers (each controller has a unique address, from 1-255), and multiple detectors are hung under each controller (each detector has a unique address). From 1-255), so that the maximum number of devices that can be connected to the whole system can reach 2552555535, while most modbus systems are 255.This cleverly breaks through the limit of 255. the data of multiple detectors under a controller are uniformly managed and reported by the controller, while the communication between the host computer is actually communication with the controller, and the data interaction between the detectors is handled by the controller. After processing, the data of the corresponding detector is put into the corresponding data bit, and the data bit is finally set in the detector management.

At present, the port supports two major categories, serial port and tcp client. As for tcp server or udp mode, it can be expanded by itself without technical difficulties. Because most of the application scenarios are either serial port or tcp client, that is, the device is the server, and the software takes the initiative to connect the device and communicate with the serial port, although the qserialport class has been added after Qt5, and the individual feels a bit problematic after using it, it always feels strange to receive data, so I am still more inclined to use the third-party open source qextserialport component to implement it. After all, I have used more than a dozen commercial projects. On WIN, UBUNTU and embedded linux, there is no problem in running, and it has withstood a large number of practical tests.

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

Core code # include "frmconfigport.h" # include "ui_frmconfigport.h" # include "quiwidget.h" # include "dbhelper.h" # include "dbdelegate.h" # include "excelapi.h" # include "printapi.h" # include "api.h" frmConfigPort::frmConfigPort (QWidget * parent): QWidget (parent), ui (new Ui::frmConfigPort) {ui- > setupUi (this); this- > initForm (); this- > initData (); this- > changeStyle () } frmConfigPort::~frmConfigPort () {delete ui;} void frmConfigPort::showEvent (QShowEvent *) {model- > select ();} void frmConfigPort::initForm () {API::initTableView (ui- > tableView); ui- > widgetTop- > setProperty ("flag", "navbtn"); if (QUIHelper::deskWidth ()

< 1440) { ui->

LabTip- > setText ("prompt → to restart the application");} else {ui- > labTip- > setText ("prompt that the → must be consistent with the field port information, and restart the application after the change");}} void frmConfigPort::initData () {model = new QSqlTableModel (this); model- > setTable ("PortInfo"); model- > setSort (0, Qt::AscendingOrder); model- > setEditStrategy (QSqlTableModel::OnManualSubmit) Model- > select (); ui- > tableView- > setModel (model); ui- > tableView- > setProperty ("model", true); columnNames.clear (); columnNames index (count-1,8). Data (). ToInt (); if (portName.startsWith ("communication port -")) {portName = QString ("communication port -% 1") .arg (portID);} QStringList list = tcpIP.split (".") If (list.count () = = 4) {tcpIP = QString ("% 1% 2.% 3.% 4") .arg (list.at (0)) .arg (list.at (1)) .arg (list.at (2)) .arg (list.at (3). ToInt () + 1);} if (count = 0) {portID = 1; portName = "Communication Port-1"; comName = "COM1" BaudRate = 9600; tcpIP = ""; tcpPort = 502; readInterval = 1; readTimeout = 3; readMaxtime = 60;} / / set the newly added row default model- > setData (model- > index (count, 0), portID); model- > setData (model- > index (count, 1), portName); model- > setData (model- > index (count, 2), comName) Model- > setData (model- > index (count, 3), baudRate); model- > setData (model- > index (count, 4), tcpIP); model- > setData (model- > index (count, 5), tcpPort); model- > setData (model- > index (count, 6), readInterval); model- > setData (model- > index (count, 7), readTimeout); model- > setData (model- > index (count, 8), readMaxtime); readMaxtime > ui- > ui- (ui- > tableView- (readMaxtime, 0) } void frmConfigPort::on_btnSave_clicked () {model- > database () .transaction (); if (model- > submitAll ()) {model- > database () .commit (); DBHelper::loadPortInfo (); / / synchronously update the port name corresponding to the device table emit portNameChanged ();} else {model- > database (). Rollback () QUIHelper::showMessageBoxError ("failed to save information, information cannot be empty, please fill in again!");}} void frmConfigPort::on_btnDelete_clicked () {if (ui- > tableView- > currentIndex () .row ()

< 0) { QUIHelper::showMessageBoxError("请选择要删除的端口!"); return; } if (QUIHelper::showMessageBoxQuestion("确定要删除该端口吗? 对应端口的所有控制器会一并删除!") == QMessageBox::Yes) { int row = ui->

TableView- > currentIndex (). Row (); QString portName = model- > index (row, 1). Data (). ToString (); DBHelper::deleteDeviceInfo (portName); model- > removeRow (row); model- > submitAll (); int count = model- > rowCount (); ui- > tableView- > setCurrentIndex (model- > index (count-1,0);} void frmConfigPort::on_btnReturn_clicked () {model- > revertAll () } void frmConfigPort::on_btnClear_clicked () {int count = model- > rowCount (); if (count select ();}} void frmConfigPort::on_btnExcel_clicked () {QString name = "port information"; QString fileName = QString ("% 1% 2") .arg (name) .arg (QDateTime::currentDateTime (). ToString ("yyyy-MM-dd-HH-mm-ss")); QString file = API::getSaveFileNames (fileName, "Excel (* .xls)") If (file.isEmpty ()) {return;} QString columns = "PortID,PortName,ComName,BaudRate,TcpIP,TcpPort,ReadInterval,ReadTimeout,ReadMaxtime"; QString where = "order by PortID asc"; QStringList content = DBHelper::getContent ("PortInfo", columns, where, "", ";"); int rowCount = content.count (); if (rowCount = = 0) {QUIHelper::showMessageBoxError ("No data to be processed!") Return;} ExcelAPI::Instance ()-> saveExcel (file, name, name, ", columnNames, columnWidths, content); QString msg = QString (" Export% 1 to Excel ") .arg (name); DBHelper::addUserLog (" user actions ", msg); if (QUIHelper::showMessageBoxQuestion (msg +" success! Are you sure you want to open it now?) = QMessageBox::Yes) {QString url = QString ("file:///%1").arg(file); QDesktopServices::openUrl (QUrl (url, QUrl::TolerantMode));}} void frmConfigPort::on_btnPrint_clicked () {QString name =" port information "; QString columns =" PortID,PortName,ComName,BaudRate,TcpIP,TcpPort,ReadInterval,ReadTimeout,ReadMaxtime "; QString where =" order by PortID asc " QStringList content = DBHelper::getContent ("PortInfo", columns, where, "", ";); int rowCount = content.count (); if (rowCount = = 0) {QUIHelper::showMessageBoxError (" No data to be processed! "); return;} PrintAPI::Instance ()-> print (name,", columnNames, columnWidths, content); QString msg = QString (" print% 1 ") .arg (name) DBHelper::addUserLog ("user Action", msg);} void frmConfigPort::on_btnInput_clicked () {QString fileName; bool ok = DBHelper::inputData (columnNames.count (), App::FileFilter, "PortInfo", fileName, QUIHelper::appPath () + "/ db", true); if (! fileName.isEmpty ()) {DBHelper::addUserLog ("user Action", "Import Port Information") If (ok) {QUIHelper::showMessageBoxInfo ("Import port information succeeded!", 3); model- > select ();} else {QUIHelper::showMessageBoxError ("Import port information failed!", 3);} void frmConfigPort::on_btnOutput_clicked () {QString columns = "*"; QString where = "order by PortID asc" QString title = columnNames.join (App::FileSpliter); QStringList content = DBHelper::getContent ("PortInfo", columns, where, title); QString fileName; bool ok = DBHelper::outputData ("Port Information", App::FileFilter, content, fileName, QUIHelper::appPath () + "/ db"); if (! fileName.isEmpty ()) {DBHelper::addUserLog ("user actions", "Export Port Information") If (ok) {QUIHelper::showMessageBoxInfo ("successfully exporting port information!", 3);} else {QUIHelper::showMessageBoxError ("failed to export port information!", 3);} at this point, the study on "what is the method of Qt port management" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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