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?
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()
user250608