在Python/Win7上使用Serial

Ton*_*dig 0 python serial-port pyserial windows-7

我正在尝试与串行WWAN调制解调器接口(用于诊断/信号强度测量目的).这是通过我桌面上的板载COM1(115200-8-n-1),连接通过PuTTY工作.我可以使用Python编写AT命令脚本,但是我很难让它打开串口.

我根据说明安装了Python 2.7.1和PySerial.我是我的机器的本地管理员,并且运行带有和没有管理员权限的Python,但是当我尝试打开端口时,我得到以下内容:

Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> s = serial.Serial(
...     port='COM1',
...     baudrate=115200
... )
>>> s.open()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 56, in open
raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.W
inError()))
serial.serialutil.SerialException: could not open port COM1: [Error 5] Access is
 denied.
Run Code Online (Sandbox Code Playgroud)

我的理解是8-N-1是默认值,即使我尝试手动设置它们也会抛出相同的异常.

有人可以提供建议吗?提前致谢.

NPE*_*NPE 5

你不需要打电话open.构造函数已经这样做了,并且在Windows上,无论谁打开COM端口,都可以对它进行独占访问,直到它们关闭它为止.

至于第二个问题,请看一下如何修复"[错误6]句柄无效." 与PySerial