PySide6.QtSerialPort.QSerialPortInfo¶
- class QSerialPortInfo¶
Provides information about existing serial ports. More…
Synopsis¶
Methods¶
def
__init__()def
description()def
isNull()def
manufacturer()def
portName()def
serialNumber()def
swap()def
systemLocation()
Static functions¶
def
availablePorts()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Use the static
availablePorts()function to generate a list ofQSerialPortInfoobjects. EachQSerialPortInfoobject in the list represents a single serial port and can be queried for theport name,system location,description,manufacturer, and some other hardware parameters. TheQSerialPortInfoclass can also be used as an input parameter for thesetPort()method of theQSerialPortclass.Example Usage¶
The example code enumerates all available serial ports and prints their parameters to console:
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__())Port enumeration on Linux¶
By default Linux uses
libudevto enumerate the available serial ports. If the library is not available, it falls back to reading files in the/sys/class/ttydirectory.It is known that some versions of
libudevhave a bug and incorrectly report VID and PID of a USB hub instead of the actual device. In such cases, define theQT_SERIALPORT_SKIP_UDEV_LOOKUPenvironment variable to skip thelibudevlookup and only use the information from the/sys/class/ttydirectory.See also
- __init__()¶
Constructs an empty
QSerialPortInfoobject.See also
- __init__(port)
- Parameters:
port –
QSerialPort
Constructs a
QSerialPortInfoobject from serialport.- __init__(other)
- Parameters:
other –
QSerialPortInfo
Constructs a copy of
other.- __init__(name)
- Parameters:
name – str
Constructs a
QSerialPortInfoobject from serial portname.This constructor finds the relevant serial port among the available ones according to the port name
name, and constructs the serial port info instance for that port.- static availablePorts()¶
- Return type:
.list of QSerialPortInfo
Returns a list of available serial ports on the system.
See also
Port enumeration on Linux- description()¶
- Return type:
str
Returns the description string of the serial port, if available; otherwise returns an empty string.
See also
- hasProductIdentifier()¶
- Return type:
bool
Returns
trueif there is a valid16-bitproduct number present; otherwise returnsfalse.- hasVendorIdentifier()¶
- Return type:
bool
Returns
trueif there is a valid16-bitvendor number present; otherwise returnsfalse.- isNull()¶
- Return type:
bool
Returns whether this
QSerialPortInfoobject holds a serial port definition.- manufacturer()¶
- Return type:
str
Returns the manufacturer string of the serial port, if available; otherwise returns an empty string.
See also
- portName()¶
- Return type:
str
Returns the name of the serial port.
See also
- productIdentifier()¶
- Return type:
int
Returns the 16-bit product number for the serial port, if available; otherwise returns zero.
- serialNumber()¶
- Return type:
str
Returns the serial number string of the serial port, if available; otherwise returns an empty string.
- static standardBaudRates()¶
- Return type:
.list of qint32
Returns a list of available standard baud rates supported by the target platform.
- swap(other)¶
- Parameters:
other –
QSerialPortInfo
Swaps
QSerialPortInfootherwith thisQSerialPortInfo. This operation is very fast and never fails.- systemLocation()¶
- Return type:
str
Returns the system location of the serial port.
See also
- vendorIdentifier()¶
- Return type:
int
Returns the 16-bit vendor number for the serial port, if available; otherwise returns zero.