PySerial [错误 5] 访问被拒绝 [英] PySerial [Error 5] Access is Denied

查看:61
本文介绍了PySerial [错误 5] 访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 Python 编写一个程序,该程序将循环以不断检查串行端口 (COM4) 并在从串行端口读取字符1"时打印出一条消息.我想通过按下按钮从 Arduino 小工具的串行端口发送1".

I am trying to write a program in Python that will loop to keep checking the serial port (COM4) and print out a message when the character "1" is read from the serial port. I want to send "1" over the serial port from an Arduino gadget upon the push of a button.

但是,当我尝试创建串行对象的实例时,出现错误[错误 5]:拒绝访问".(它会在实例化时自动尝试打开,这是错误所在,从我从处理此问题的 PySerial 包中的文件中可以看出.)

However, I get the error "[Error 5]: Access is Denied" when I try to create an instance of a serial object. (It automatically tries to open upon instantiation, which is where the error is, from what I can see from the file in the PySerial package that handles this.)

我的代码:

c = serial.Serial('COM4', 9600)
while True:
    signal = c.read()
    print signal
    print "running"
    time.sleep(2)
    c.flushOutput()

不过,它永远不会超过c = serial.Serial('COM4', 9600).这就是错误弹出的地方.我该如何解决这个问题?

It never gets past the "c = serial.Serial('COM4', 9600), though. That's where the error pops up. How can I fix this?

推荐答案

更新:这在 PySerial 3.0 中显然不再可能.

UPDATE: This is apparently no longer possible in PySerial 3.0.

在 Windows 下,我一直使用 port=<int>成功的方法.

Under Windows, I've always used the port=<int> approach with success.

即将您的代码更改为:

c = serial.Serial(3, 9600)

这篇关于PySerial [错误 5] 访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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