【问题标题】:Detect which /dev/ttyACM is open检测打开的 /dev/ttyACM
【发布时间】:2015-11-25 14:28:40
【问题描述】:

他们的命令是否返回 /dev/ttyACM* 的打开状态。在脚本的某个阶段,它会断开 USB 并重新连接,但此后 ACM 会递增,因此变量 port = /dev/ttyACM0 现在是 /dev/ttyACM1。我想检测哪个 /dev/ttyACM* 是打开的。所以port = return (command to find ACM)

【问题讨论】:

    标签: python bash tty


    【解决方案1】:

    使用globserial,应该可以解决问题:

    import glob
    import serial
    
    def find_ports():
        ports = glob.glob('/dev/ttyACM[0-9]*')
    
        res = []
        for port in ports:
            try:
                s = serial.Serial(port)
                s.close()
                res.append(port)
            except:
                pass
        return res
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 2017-01-18
      • 1970-01-01
      相关资源
      最近更新 更多