尝试在 WinXP 上使用 pyserial 打开串行端口 ->“拒绝访问"

2023-07-23Python开发问题
84

本文介绍了尝试在 WinXP 上使用 pyserial 打开串行端口 ->“拒绝访问"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 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 打开串行端口 -&gt;“拒绝访问"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11