首页 > 解决方案 > 执行脚本时出现 Python 错误

问题描述

在此处输入图像描述我正在尝试使用 python 脚本控制 I/O 模块。我看到与未定义端口有关的错误。有任何想法吗?

我从以下链接中获取了代码

https://github.com/jkesanen/usbrly08/blob/master/usbrly08.py

谢谢。

更新

您好,感谢您的回复。我尝试使用添加的端口参数再次执行脚本。我现在看到一个不同的错误。我的中继模块连接到 com 端口 9。我在最初的帖子中添加了运行上述脚本后看到的错误。还有其他建议吗?谢谢

Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。版权所有。

C:\Users\A1037648>cd \python

C:\Python>test.py -p9
Traceback (most recent call last):
  File "C:\Python\Test.py", line 260, in <module>
    main()
  File "C:\Python\Test.py", line 217, in main
    s = serial.Serial(args.port, timeout=args.timeout)
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 31, in 
__init__
    super(Serial, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\serialutil.py", line 240, in 
__init__
    self.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 62, in 
open
    raise SerialException("could not open port {!r}: 
{!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port '9': WindowsError(2, 
'The system cannot find
the file specified.')

C:\Python>

标签: pythonio

解决方案


感谢您对此的帮助。我刚回来再次尝试它,它的工作原理!我附上了我用来控制 IO 模块的代码,如果有人觉得它有用的话。

echo[

cd..

timeout /t 1

cd..

timeout /t 1

cd..

timeout /t 1

cd python27

timeout /t 1

test.py -p com6 -n 0

推荐阅读