Trying to open a serial port with pyserial on WinXP -gt; quot;Access deniedquot;(尝试在 WinXP 上使用 pyserial 打开串行端口 -gt;“拒绝访问)
问题描述
我正在尝试使用 python 和 pyserial 通过串行端口将数据发送到 hplc 泵.我在 linux(gentoo 衍生产品)下测试了电缆和泵,尽管它是 root 用户,但它工作得很好.现在我必须在 WinXP 机器上使用代码,在尝试打开端口时总是出现拒绝访问"错误(我将参数调整为 COMxx 而不是 ttySxx,找到了端口).我试过电脑的串口,还有一个USB2Serial适配器.我听说 WinXP 在尝试使用自写代码解决某些端口时非常严格.有没有比安装 linux 更简单的解决方法?
I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port (i adjusted the parameters to COMxx instead of ttySxx, the port is found). I tried the serial port of the computer, as well as a USB2Serial adapter. I heard that WinXP was quite restrictive when it comes to trying to address some port with self written code. Is there a simpler workaround for this problem than installing linux?
# -*- coding: utf-8 -*-
import sys
import time
import serial
from threading import Thread
"""
usage: cmdCapture workDirectory pictureTime pressureTime
"""
print 'successful import is successful'
workDir=sys.argv[1]
pressureThresh=float(sys.argv[3])
class doCapture(Thread):
def __init__ (self, workDir, pressureThresh):
Thread.__init__(self)
self.workDir=workDir
self.pressureThresh=pressureThresh
self.pressureTimer=0
->这里我设置了串口
self.ser=serial.Serial(port='\.COM1', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)
->这里发生错误
self.ser.open()
def getPressure(self):
self.ser.write('PR')
return self.ser.read(size=8), timer.timer()
def run(self):
self.pressureTimer=time.timer()
while 1:
if self.pressureTimer<=(time.timer()-self.pressureTime):
self.p=getPressure()
print self.p
myCapture=doCapture(workDir, pressureThresh)
myCapture.start()
推荐答案
尝试打开端口为\.COMxx
还要确保端口尚未从其他应用程序打开.我建议你使用超级终端查看端口是否打开.
Also make sure that the port isn't already open from another application. I recommend that you use Hyperterminal to see if the port is open.
这篇关于尝试在 WinXP 上使用 pyserial 打开串行端口 ->“拒绝访问"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尝试在 WinXP 上使用 pyserial 打开串行端口 ->“拒绝访问"
基础教程推荐
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
