提供现有串口的有关信息。 更多...
| 头: |
#include <QSerialPortInfo>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS SerialPort)
target_link_libraries(mytarget PRIVATE Qt6::SerialPort)
|
| qmake: |
QT += serialport
|
| QSerialPortInfo () | |
| QSerialPortInfo (const QSerialPort & port ) | |
| QSerialPortInfo (const QString & name ) | |
| QSerialPortInfo (const QSerialPortInfo & other ) | |
| ~QSerialPortInfo () | |
| QString | description () const |
| bool | hasProductIdentifier () const |
| bool | hasVendorIdentifier () const |
| bool | isNull () const |
| QString | manufacturer () const |
| QString | portName () const |
| quint16 | productIdentifier () const |
| QString | serialNumber () const |
| void | swap (QSerialPortInfo & other ) |
| QString | systemLocation () const |
| quint16 | vendorIdentifier () const |
| QSerialPortInfo & | operator= (const QSerialPortInfo & other ) |
| QList<QSerialPortInfo> | availablePorts () |
| QList<qint32> | standardBaudRates () |
使用静态 availablePorts () 函数能生成 QSerialPortInfo 对象列表。列表中的每个 QSerialPortInfo 对象表示单个串口,且可以查询为 端口名 , 系统位置 , description , manufacturer ,和某些其它硬件参数。QSerialPortInfo 类也可以用作输入参数为 setPort () 方法对于 QSerialPort 类。
范例代码枚举所有可用的串口,并把其参数打印到控制台:
const auto serialPortInfos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &portInfo : serialPortInfos) {
qDebug() << "\n"
<< "Port:" << portInfo.portName() << "\n"
<< "Location:" << portInfo.systemLocation() << "\n"
<< "Description:" << portInfo.description() << "\n"
<< "Manufacturer:" << portInfo.manufacturer() << "\n"
<< "Serial number:" << portInfo.serialNumber() << "\n"
<< "Vendor Identifier:"
<< (portInfo.hasVendorIdentifier()
? QByteArray::number(portInfo.vendorIdentifier(), 16)
: QByteArray()) << "\n"
<< "Product Identifier:"
<< (portInfo.hasProductIdentifier()
? QByteArray::number(portInfo.productIdentifier(), 16)
: QByteArray());
}
默认情况下,Linux 使用
libudev
来枚举可用端口。若库不可用,它回退到读取文件在
/sys/class/tty
目录。
已知的是,某些版本的
libudev
有 Bug,且会不正确报告 USB 集线器的 VID 和 PID (进程标识),而不是实际设备。在这种情况下,定义
QT_SERIALPORT_SKIP_UDEV_LOOKUP
环境变量能跳过
libudev
查找且使用信息仅来自
/sys/class/tty
目录。
另请参阅 QSerialPort .
构造空的 QSerialPortInfo 对象。
另请参阅 isNull ().
[explicit]
QSerialPortInfo::
QSerialPortInfo
(const
QSerialPort
&
port
)
构造 QSerialPortInfo 对象从串行 port .
[explicit]
QSerialPortInfo::
QSerialPortInfo
(const
QString
&
name
)
构造 QSerialPortInfo 对象从串口 name .
此构造函数在可用串口中找到相关串口,根据端口名称 name ,并为该端口构造串口信息实例。
构造副本为 other .
[noexcept]
QSerialPortInfo::
~QSerialPortInfo
()
销毁 QSerialPortInfo 对象。引用对象中的值变为无效。
[static]
QList
<
QSerialPortInfo
> QSerialPortInfo::
availablePorts
()
返回系统可用串口的列表。
另请参阅 Linux 的端口枚举 .
返回串口的描述字符串,若可用;否则返回空字符串。
另请参阅 manufacturer () 和 serialNumber ().
返回
true
若存在有效
16-bit
产品编号呈现;否则返回
false
.
另请参阅 productIdentifier (), vendorIdentifier (),和 hasVendorIdentifier ().
返回
true
若存在有效
16-bit
供应商编号存在;否则返回
false
.
另请参阅 vendorIdentifier (), productIdentifier (),和 hasProductIdentifier ().
返回是否此 QSerialPortInfo 对象保持串口定义。
返回串口的制造商字符串,若可用;否则返回空字符串。
另请参阅 description () 和 serialNumber ().
返回串口的名称。
另请参阅 systemLocation ().
返回串口的 16 位产品编号,若可用;否则返回 0。
另请参阅 hasProductIdentifier (), vendorIdentifier (),和 hasVendorIdentifier ().
返回串口的序列号字符串,若可用;否则返回空字符串。
注意: 序列号可能包含字母。
另请参阅 description () 和 manufacturer ().
[static]
QList
<
qint32
> QSerialPortInfo::
standardBaudRates
()
返回由目标平台支持的,可用标准波特率列表。
交换 QSerialPortInfo other 采用此 QSerialPortInfo 。此操作很快且从不失败。
返回串口的系统位置。
另请参阅 portName ().
返回串口的 16 位供应商编号,若可用;否则返回 0。
另请参阅 hasVendorIdentifier (), productIdentifier (),和 hasProductIdentifier ().
设置 QSerialPortInfo 对象等于 other .