Commit 6b29ff49 authored by Philipp Oleynik's avatar Philipp Oleynik
Browse files

Added a class for interaction with Agilent pump

parent 70e48b9c
# -*- coding: utf-8 -*-
#
# Copyright 2017 uberdaff
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
# Requirement: pyserial
#
# getIdn() - Get instrument identification
# setVolt(tal) - Set the voltage on the output
# getVolt() - Get the 'set' voltage
# readVolt() - Get a measurement of the voltage
# setAmp(tal) - Set the current limit
# getAmp() - Get the 'set' current limit
# readAmp() - Get a measurement of the output current
# setOut(bool) - Set the state of the output
# setOcp(bool) - Set the state of the over current protection
# getStatus() - Get the state of the output and CC/CV
#
import sys
import time
import serial
class pumpAgilent:
isConnected = False
pump_com = None
status = None
def __init__(self, dev_com):
try:
dev_com = serial.Serial(
port = dev_com,
baudrate = 9600,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS
)
dev_com.isOpen()
self.pump_com = dev_com
self.isConnected = True
# self.status = self.getStatus()
except:
print("COM port failure:")
print(sys.exc_info())
self.pump_com = None
self.isConnected = False
def close(self):
self.pump_com.close()
def serWriteAndRecieve(self, data, delay = 0.05):
self.pump_com.write(data)
out = ''
time.sleep(delay)
while self.pump_com.inWaiting() > 0:
out += self.pump_com.read(1).decode(encoding = 'ascii', errors = 'ignore')
if out != '':
return out
return None
def getPressure(self):
return float(self.serWriteAndRecieve(b"\002\200\062\062\064\060\003\070\067")[4:12])
def getRpm(self):
stat = self.serWriteAndRecieve(b"\002\200\062\062\066\060\003\070\065")[4:11]
return int(stat)
def getStatus(self):
stat = self.serWriteAndRecieve(b"\002\200\062\062\066\060\003\070\065")[4:11]
if int(stat) > 100:
self.status = 1
else:
self.status = 0
return self.status
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment