在 Python/Win7 上使用串行 [英] Using Serial on Python / Win7

查看:72
本文介绍了在 Python/Win7 上使用串行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to interface with a serial WWAN modem (for diagnostics /signal strength measurement purposes). This is via the onboard COM1 (115200-8-n-1) on my desktop, the connection works via PuTTY. I can script the AT commands using Python, but I am having a tough time getting it to open the serial port .

我已经按照说明安装了 Python 2.7.1 和 PySerial.我是我机器的本地管理员,并且在有和没有管理员权限的情况下运行 Python,但是当我尝试打开端口时,我得到以下信息:

I have installed Python 2.7.1 and PySerial according to instructions. I am the local administrator of my machine and have run Python with and without admin privileges, but I get the following when I try to open the port:

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.

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

It is my understanding that 8-N-1 is the default, and even when I try to set them manually it throws the same exception.

谁能给点建议?提前致谢.

Can anyone offer advice? Thanks in advance.

推荐答案

你不需要调用 open.构造函数已经这样做了,并且在 Windows 上,打开 COM 端口的任何人都可以独占访问它,直到他们关闭它.

You don't need to call open. The constructor already does that, and on Windows whoever opens a COM port has exclusive access to it until they close it.

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

这篇关于在 Python/Win7 上使用串行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆