【问题标题】:MacPython: programmatically finding all serial portsMacPython:以编程方式查找所有串行端口
【发布时间】:2012-10-05 02:11:51
【问题描述】:

我正在寻找一种使用 python 以编程方式返回所有可用串行端口的解决方案。

目前我正在终端中输入ls /dev/tty.*ls /dev/cu.* 以列出端口并将它们硬编码到pyserial 类中。

【问题讨论】:

    标签: python macos serial-port


    【解决方案1】:

    你可以这样做:

    import glob
    def scan():
        return glob.glob('/dev/tty*') + glob.glob('/dev/cu*')
    
    for port in scan():
       # do something to check this port is open.
    

    然后,看看pyserial 的一些很好的实用功能来检查端口是否打开等等。

    【讨论】:

    【解决方案2】:

    如果只执行 os.listdir / glob 等效于 ls 来执行等效于 ls 呢?当然,某些可用设备不会连接到每个这样的特殊文件(但是,ls 也适用;-),而是用于“查找所有串行端口” ,正如您在 Q 的标题中所问的那样,我不确定您可能会如何否则

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多