【问题标题】:No ports found: Error while listing all the ports in python未找到端口:在 python 中列出所有端口时出错
【发布时间】:2021-01-03 22:04:58
【问题描述】:

我尝试列出所有的 com 端口,以便可以连接到它们。我正在使用 Ubuntu 20.04。我尝试了各种在 stackoverflow 上得到解答的事情。 我尝试从命令行列表output of the command line

import serial
import serial.tools.list_ports
ports = serial.tools.list_ports.comports()
print(ports)
for port, desc, hwid in sorted(ports):
        print('hello')
        print("{}: {} [{}]".format(port, desc, hwid))

方法 serial.tools.list_ports.comports() 返回一个空列表。 我尝试了一切并用谷歌搜索了很多,但我无法找到解决方案。 请帮助某人,否则我的项目将停止。

【问题讨论】:

  • 从终端运行dmesg | grep -i serial会得到什么?
  • [0.555970] 序列号:8250/16550 驱动程序,32 个端口,已启用 IRQ 共享 [0.562116] usb usb1:新 USB 设备字符串:Mfr=3,Product=2,SerialNumber=1 [0.562120] usb usb1: 序列号: 0000:00:14.0 [0.563893] usb usb2: 新 USB 设备字符串: Mfr=3, Product=2, SerialNumber=1 [0.563896] usb usb2: 序列号: 0000:00:14.0 [1.078359] usb 1- 1:新 USB 设备字符串:Mfr=1,Product=2,SerialNumber=0 [1.333481] usb 1-4:新 USB 设备字符串:Mfr=1,Product=2,SerialNumber=3
  • 我没有看到 tty 你在这台机器上实际上有一个 com 端口吗?

标签: python-3.x port pyserial ubuntu-20.04


【解决方案1】:

对我来说,serial.tools.port_lists 显示“未找到端口”,但 dmesg 显示 ttyS3 端口确实存在:

[root@localhost ngt]# dmesg | egrep --color 'serial|ttyS'
[00.751594] serial8250: ttyS3 at I/O 0x2e8 (irq = 3) is a 16550A
[0.866102] usbcore: registered new interface driver usbserial
[0.866117] usbcore: registered new interface driver usbserial_generic
[0.866129] usbserial: USB Serial support registered for generic

[root@localhost ngt]# python3 -m serial.tools.list_ports -v
no ports found

所以我可以使用serial.Serial() 连接到这个ttyS3 端口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多