PySide6.QtSerialPort.QSerialPortInfo

class QSerialPortInfo

提供有关现有串行端口的信息。更多

概要

方法

静态函数

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

警告

本节包含从C++自动翻译到Python的代码片段,可能包含错误。

使用静态函数 availablePorts() 生成一个 QSerialPortInfo 对象列表。列表中的每个 QSerialPortInfo 对象代表一个串行端口,并且可以查询 port namesystem locationdescriptionmanufacturer 以及其他一些硬件参数。QSerialPortInfo 类也可以作为 QSerialPort 类的 setPort() 方法的输入参数。

示例用法

示例代码枚举所有可用的串行端口并将其参数打印到控制台:

serialPortInfos = QSerialPortInfo.availablePorts()
for portInfo in serialPortInfos:
    print("\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)
super().__init__())

另请参阅

QSerialPort

__init__()

构造一个空的 QSerialPortInfo 对象。

另请参阅

isNull()

__init__(port)
Parameters:

端口QSerialPort

从串行port构造一个QSerialPortInfo对象。

__init__(other)
Parameters:

其他QSerialPortInfo

构造other的副本。

__init__(name)
Parameters:

name – str

从串口 name 构造一个 QSerialPortInfo 对象。

此构造函数根据端口名称 name 在可用的串行端口中找到相关的串行端口,并为该端口构建串行端口信息实例。

static availablePorts()
Return type:

QSerialPortInfo的列表

返回系统上可用的串行端口列表。

description()
Return type:

字符串

返回串口的描述字符串(如果可用);否则返回空字符串。

hasProductIdentifier()
Return type:

布尔

如果存在有效的16-bit产品编号,则返回true;否则返回false

hasVendorIdentifier()
Return type:

布尔

如果存在有效的16-bit供应商编号,则返回true;否则返回false

isNull()
Return type:

布尔

返回此QSerialPortInfo对象是否包含串口定义。

manufacturer()
Return type:

字符串

返回串行端口的制造商字符串(如果可用);否则返回空字符串。

portName()
Return type:

字符串

返回串口的名称。

另请参阅

systemLocation()

productIdentifier()
Return type:

整数

返回串行端口的16位产品编号(如果可用);否则返回零。

serialNumber()
Return type:

字符串

返回串行端口的序列号字符串(如果可用);否则返回空字符串。

注意

序列号可能包含字母。

static standardBaudRates()
Return type:

.qint32的列表

返回目标平台支持的可用标准波特率列表。

swap(other)
Parameters:

其他QSerialPortInfo

QSerialPortInfo other与此QSerialPortInfo交换。此操作非常快速且永远不会失败。

systemLocation()
Return type:

字符串

返回串口的系统位置。

另请参阅

portName()

vendorIdentifier()
Return type:

整数

返回串行端口的16位供应商编号(如果可用);否则返回零。