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 shows you "Qt how to achieve serial port acquisition", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn "Qt how to achieve serial port acquisition" this article bar.
I. Foreword
Data source is the core soul of configuration software, less data source, configuration is a shelf without eggs, general data source has three ways to obtain, serial port, network, database, as for what the data rules are, the user himself specified, the designer all use the first byte as data to demonstrate. Serial communication in a large number of industrial control areas with the most, because of stability two words, long-term occupation of decades of communication rules, and now there are a large number of industrial control equipment is used serial communication, Qt5 after the encapsulation of serial communication class, but it is said that not easy to use, not stable, I used several times in the early Qt version such as Qt5.3 era, is a bit inexplicable problem, simply not with the back, Instead, I use a third-party open source qextserialport, mainly because a large number of hardware devices I have done are Qt versions of Qt4.8, and I can't use Qt5. I haven't upgraded to Qt5 yet, which may also be due to stability considerations.
II. Functions achieved
Automatically loads all controls in the plug-in file to generate a list, with more than 120 controls by default.
Drag to canvas to automatically generate corresponding controls, WYSIWYG.
Chinese property bar on the right, change the corresponding property immediately applied to the corresponding selected control, intuitive and concise, very suitable for Xiaobai use.
Original attribute bar text translation mapping mechanism, very efficient, can be very convenient to expand the attribute bar of other languages.
All control properties are automatically extracted and displayed in the right property bar, including enumeration value drop-down boxes, etc.
Support manual selection of plug-in files, external import plug-in files.
You can export all control configuration information for the current canvas to an xml file.
You can manually select an xml file to open the control layout and automatically load the controls according to the xml file.
You can pull the slider bar, check the analog data check box, and enter the text box. There are three ways to generate data. Apply all controls.
Control support eight azimuth pull resize, adaptive arbitrary resolution, keyboard up and down left and right fine-tuning position.
Open up the serial port acquisition, network acquisition, database acquisition three ways to set data.
The code is extremely concise and the comments are very detailed. It can be used as a prototype of configuration to expand more functions by itself.
Pure Qt writing, support any Qt version + any compiler + any system.
III. Effect Drawing
void frmData::initServer(){ //instantiate serial class, bind signal slot com = new QextSerialPort(QextSerialPort::EventDriven, this); connect(com, SIGNAL(readyRead()), this, SLOT(readDataCom())); //instantiate network communication client classes, bind signal slots tcpClient = new QTcpSocket(this); connect(tcpClient, SIGNAL(readyRead()), this, SLOT(readDataClient())); //instantiate the network communication server class, bind the signal slot tcpSocket = NULL; tcpServer = new QTcpServer(this); connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection())); //Start timer to read database and collect data timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(readDataDb())); timer->setInterval(1000);}void frmData::on_btnOpenCom_clicked(){ if (ui->btnOpenCom->text() == "Open") { com->setPortName(App::PortName); bool ok = com->open(QIODevice::ReadWrite); if (ok) { com->setBaudRate((BaudRateType)App::BaudRate); setEnable(ui->btnOpenCom, false); ui->btnOpenCom->setText("Close"); } } else { com->close(); setEnable(ui->btnOpenCom, true); ui->btnOpenCom->setText("Open"); }}void frmData::readDataCom(){ QByteArray data = com->readAll(); if (data.length() txtValue->setText(QString::number(value)); append(1, data.toHex());} The above is "Qt how to achieve serial port collection" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.