Trying to open serial port using pyserial on WinXP & # 8594; "Access is denied"

I am trying to send data to a hplc pump through a serial port using python and pyserial. I tested the cable and pump under linux (a derivative of gentoo), where it worked fine, although it was root. Now I need to use the code on the WinXP machine, where I always get the "Access Denied" error when I try to open the port (I adjusted COMxx parameters instead of ttySxx, the port was found). I tried the serial port of the computer, as well as the USB2Serial adapter. I heard that WinXP was pretty restrictive when it came to trying to access some port with a recorder. 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

→ here I set the serial port

    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()
+5
7

\\.\COMxx

, . Hyperterminal, , .

+11

.close(), .open(), ,

+8

.open, / !

+4

self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) 

. Windows , .open(), , Linux. .

+3

.close() , !

64- , com0com, .

Windows 7 box - nada - XP Mode. ( ). , HyperTerminal .

4 , .

... GAH!

+1

, TI Chronos. COM- .

0

Make sure that the port is not opened by any other program. (It worked for me)

0
source

All Articles