【问题标题】:Usage of Pyserial and Pexpect in WindowsWindows 中 Pyserial 和 Pexpect 的使用
【发布时间】:2018-11-22 13:05:10
【问题描述】:

我有一个在 Ubuntu 中完美运行的脚本,但是我希望让它在 Windows 机器上运行,以便在生产环境中使用。该脚本的一般用途是对 PCB 进行编程。

我在研究和调整这部分代码时遇到了问题:

try: 
  fd = serial.Serial(Port, Baud) #Opens the specified port
  child = pexpect.fdpexpect.fdspawn(fd, timeout=180)
except:
  input('There has been an error making the connection, check your connections and try again\nPress enter to exit')
  sys.exit()
input('Press enter to continue, then apply 24V power to the unit')

存在的问题:

child = pexpect.fdpexpect.fdspawn(fd, timeout=180)

非常感谢任何建议或修改!

【问题讨论】:

    标签: python windows pyserial pexpect


    【解决方案1】:

    Windows 似乎存在一些差异。 PySerial 上没有 fileno。

    基于this github issue,您可以尝试使用以下内容:

    import os
    import pexpect.fdpexpect
    port = "COM5"
    reader = pexpect.fdpexpect.fdspawn(os.open(port, os.O_RDWR))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多