日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

【Qt5.8】Qt5.8中串口信息类QSerialPortInfo

發(fā)布時(shí)間:2024/4/21 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Qt5.8】Qt5.8中串口信息类QSerialPortInfo 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

00. 目錄

    • 00. 目錄
    • 01. QSerialPortInfo簡(jiǎn)介
    • 02. QSerialPortInfo類(lèi)成員函數(shù)
    • 03. 程序示例一
    • 04. 程序示例二

01. QSerialPortInfo簡(jiǎn)介

QSerialPortInfo類(lèi)提供已存在串口設(shè)備的信息。使用QSerialPortInfo類(lèi)的靜態(tài)成員函數(shù)生成QSerialPortInfo對(duì)象的鏈表。鏈表中的每個(gè)QSerialPortInfo對(duì)象代表一個(gè)串口,每個(gè)串口可以使用端口名、系統(tǒng)定位、描述、制造商查詢(xún)。QSerialPortInfo類(lèi)對(duì)象也可以用做QSerialPort類(lèi)的setPort()成員函數(shù)的參數(shù)。

02. QSerialPortInfo類(lèi)成員函數(shù)

//構(gòu)造函數(shù) QSerialPortInfo() QSerialPortInfo(const QSerialPort &port) QSerialPortInfo(const QString &name) QSerialPortInfo(const QSerialPortInfo &other)//析構(gòu)函數(shù) ~QSerialPortInfo()//返回當(dāng)前系統(tǒng)可用串口的鏈表 [static] QList<QSerialPortInfo> QSerialPortInfo::availablePorts()//如果串口可用,返回串口的描述信息 QString QSerialPortInfo::description() const//如果有一個(gè)合法的16位生產(chǎn)碼,返回true bool QSerialPortInfo::hasProductIdentifier() const//如果有一個(gè)合法的16位制造商編碼,返回true bool QSerialPortInfo::hasVendorIdentifier() const//如果串口當(dāng)前正忙,返回true bool QSerialPortInfo::isBusy() const//如果串口可用,返回串口的制造商的名字 QString QSerialPortInfo::manufacturer() const//返回串口的名字 QString QSerialPortInfo::portName() const//如果串口可用,返回串口的16位的生產(chǎn)編碼 quint16 QSerialPortInfo::productIdentifier() const//如果串口可用,返回串口的序列號(hào) QString QSerialPortInfo::serialNumber() const//返回目標(biāo)平臺(tái)支持的可用的標(biāo)準(zhǔn)波特率的鏈表 [static] QList<qint32> QSerialPortInfo::standardBaudRates()//使用other交換QSerialPortInfo對(duì)象 void QSerialPortInfo::swap(QSerialPortInfo &other)//返回串口的系統(tǒng)位置 QString QSerialPortInfo::systemLocation() const//如果串口可用,返回16位的制造商編碼 quint16 QSerialPortInfo::vendorIdentifier() const

03. 程序示例一

#include "widget.h" #include <QDebug> #include <QList> #include <QtSerialPort/QSerialPortInfo>Widget::Widget(QWidget *parent): QWidget(parent) {//獲取當(dāng)前系統(tǒng)下所有可以用的串口QList<QSerialPortInfo> serialPortInfo = QSerialPortInfo::availablePorts();qDebug() << "串口的個(gè)數(shù): " << serialPortInfo.count();//顯示目標(biāo)串口支持的波特率列表QList<qint32> baudRates = QSerialPortInfo::standardBaudRates();qDebug() << baudRates;qDebug() << "串口的描述:" << serialPortInfo.at(0).description();qDebug() << "hasProductIdentifier(): " << serialPortInfo.at(0).hasProductIdentifier();qDebug() << "hasVendorIdentifier(): " << serialPortInfo.at(0).hasVendorIdentifier();qDebug() << "isBusy: " << serialPortInfo.at(0).isBusy();qDebug() << "manufacturer: " << serialPortInfo.at(0).manufacturer();qDebug() << "portName: " << serialPortInfo.at(0).portName();qDebug() << "productIdentifier: " << serialPortInfo.at(0).productIdentifier();qDebug() << "serialNumber: " << serialPortInfo.at(0).serialNumber();qDebug() << "vendorIdentifier: " << serialPortInfo.at(0).vendorIdentifier();qDebug() << "systemLocation: " << serialPortInfo.at(0).systemLocation();}Widget::~Widget() {}

運(yùn)行結(jié)果:

04. 程序示例二

int main(int argc, char *argv[]) {QCoreApplication a(argc, argv);QTextStream out(stdout);const auto serialPortInfos = QSerialPortInfo::availablePorts();out << QObject::tr("Total number of ports available: ") << serialPortInfos.count() << endl;const QString blankString = QObject::tr("N/A");QString description;QString manufacturer;QString serialNumber;for (const QSerialPortInfo &serialPortInfo : serialPortInfos) {description = serialPortInfo.description();manufacturer = serialPortInfo.manufacturer();serialNumber = serialPortInfo.serialNumber();out << endl<< QObject::tr("Port: ") << serialPortInfo.portName() << endl<< QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl<< QObject::tr("Description: ") << (!description.isEmpty() ? description : blankString) << endl<< QObject::tr("Manufacturer: ") << (!manufacturer.isEmpty() ? manufacturer : blankString) << endl<< QObject::tr("Serial number: ") << (!serialNumber.isEmpty() ? serialNumber : blankString) << endl<< QObject::tr("Vendor Identifier: ") << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier(), 16) : blankString) << endl<< QObject::tr("Product Identifier: ") << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier(), 16) : blankString) << endl<< QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl;}return 0; }

運(yùn)行結(jié)果:

總結(jié)

以上是生活随笔為你收集整理的【Qt5.8】Qt5.8中串口信息类QSerialPortInfo的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。