首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python PySerial,如何打开串口?

Python PySerial,如何打开串口?
EN

Stack Overflow用户
提问于 2015-01-03 05:52:34
回答 1查看 5K关注 0票数 2

我正在尝试运行PySerial文档中的这个示例程序来打开串行端口。来源:http://pyserial.sourceforge.net/shortintro.html我尝试在Python2.7和3.4版本中运行代码,但仍然得到相同的错误。

代码语言:javascript
复制
>>> import serial
>>> ser = serial.Serial(0)  # open first serial port
>>> print ser.name          # check which port was really used
>>> ser.write("hello")      # write a string
>>> ser.close()             # close port

在运行第二行代码后,我得到了以下错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    ser = serial.Serial(0)
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 38, in __init__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\serialutil.py", line 282, in __init__
    self.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 66, in open
    raise SerialException("could not open port %r: %r" % (self.portstr,     ctypes.WinError()))
SerialException: could not open port 'COM1': WindowsError(2, 'The system cannot find the file specified.')
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27749025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档