import sys
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
from PySide6.QtSerialPort import QSerialPortInfo
class SerialPortInfoExample(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
layout = QVBoxLayout()
# 创建一个标签,用于显示串口信息
self.info_label = QLabel(self)
layout.addWidget(self.info_label)
self.setLayout(layout)
# 显示可用串口的信息
self.display_serial_port_info()
def display_serial_port_info(self):
info_text = "可用串口信息:\n"
# 获取所有可用的串口
available_ports = QSerialPortInfo.availablePorts()
if not available_ports:
info_text += "未找到可用串口。"
else:
for port in available_ports:
info_text += f"\n端口名称: {port.portName()}\n"
info_text += f"制造商: {port.manufacturer()}\n"
info_text += f"描述: {port.description()}\n"
info_text += f"系统位置: {port.systemLocation()}\n"
info_text += f"串口号: {port.serialNumber()}\n"
info_text += f"串口名: {port.portName()}\n"
info_text += f"制造商: {port.manufacturer()}\n"
info_text += f"描述: {port.description()}\n"
info_text += f"系统位置: {port.systemLocation()}\n"
info_text += f"串口号: {port.serialNumber()}\n"
info_text += "------------------------"
self.info_label.setText(info_text)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = SerialPortInfoExample()
example.show()
sys.exit(app.exec())
PySide6显示串口信息
于 2024-01-02 21:12:31 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)