gpd_xxx.py
126 lines
| 3.6 KiB
| text/x-python
|
PythonLexer
/ lppinstru / gpd_xxx.py
|
r1 | #!/usr/bin/env python | ||
#-*- coding: utf-8 -*- | ||||
"""Simple python library to communicate with GW Instek GPD-Series power supplies. | ||||
""" | ||||
import time | ||||
import sys | ||||
import os | ||||
import matplotlib.pyplot as plt | ||||
import numpy as np | ||||
import serial | ||||
__author__ = "Alexis Jeandet" | ||||
__copyright__ = "Copyright 2015, Laboratory of Plasma Physics" | ||||
__credits__ = [] | ||||
__license__ = "GPLv2" | ||||
__version__ = "1.0.0" | ||||
__maintainer__ = "Alexis Jeandet" | ||||
__email__ = "alexis.jeandet@member.fsf.org" | ||||
__status__ = "Development" | ||||
|
r3 | class gpd_xxx(object): | ||
|
r1 | conf = {"GPD-3303S" : (2,0.0,30.0), | ||
"GPD-3303" : (), | ||||
} | ||||
trackingMode = {"Independent" : '0', | ||||
"Series" : '1', | ||||
"Parallel" : '2', | ||||
} | ||||
trackingModeStat = {"01": "Independent", | ||||
"11" : "Series", | ||||
"10" : "Parallel", | ||||
} | ||||
def __init__(self,port): | ||||
self.i=0 | ||||
self.__port=serial.Serial(port,timeout=0.5) | ||||
def idn(self): | ||||
self.__port.setTimeout(0.1) | ||||
self.__port.write(b"*IDN?\n") | ||||
return self.__port.readall() | ||||
def setVoltage(self,index,tension): | ||||
if index < 2: | ||||
self.__port.write("VSET"+str(index+1)+":"+str(tension)+"\n") | ||||
else: | ||||
raise UserWarning("Parameter out of bound") | ||||
def voltageSet(self,index): | ||||
if index < 2: | ||||
self.__port.setTimeout(0.1) | ||||
self.__port.write("VSET"+str(index+1)+"?\n") | ||||
V=self.__port.readall() | ||||
return float(V.split("V")[0]) | ||||
else: | ||||
raise UserWarning("Parameter out of bound") | ||||
def voltage(self,index): | ||||
if index < 2: | ||||
self.__port.setTimeout(0.1) | ||||
self.__port.write("VOUT"+str(index+1)+"?\n") | ||||
V=self.__port.readall() | ||||
return float(V.split("V")[0]) | ||||
else: | ||||
raise UserWarning("Parameter out of bound") | ||||
def setCurrentLimit(self,index,limit): | ||||
if index < 2: | ||||
self.__port.write("ISET"+str(index+1)+":"+str(limit)+"\n") | ||||
else: | ||||
raise UserWarning("Parameter out of bound") | ||||
def currentLimit(self,index): | ||||
if index < 2: | ||||
self.__port.setTimeout(0.1) | ||||
self.__port.write("ISET"+str(index+1)+"?\n") | ||||
I = self.__port.readall() | ||||
return float(I.split("A")[0]) | ||||
else: | ||||
raise UserWarning("Parameter out of bound") | ||||
def current(self,index): | ||||
if index < 2: | ||||
self.__port.setTimeout(0.1) | ||||
self.__port.write("IOUT"+str(index+1)+"?\n") | ||||
I = self.__port.readall() | ||||
return float(I.split("A")[0]) | ||||
else: | ||||
raise UserWarning("Parameter out of bound") | ||||
def turnOn(self,on=True): | ||||
if on: | ||||
self.__port.write("OUT1\n") | ||||
else: | ||||
self.__port.write("OUT0\n") | ||||
def setTracking(self,mode="Independent"): | ||||
self.__port.write("TRACK"+self.trackingMode.get(mode)+"\n") | ||||
def setBeep(self,on=True): | ||||
if on: | ||||
self.__port.write("BEEP1\n") | ||||
else: | ||||
self.__port.write("BEEP0\n") | ||||
def tracking(self): | ||||
self.__port.write("STATUS?\n") | ||||
self.__port.setTimeout(0.1) | ||||
STAT = self.__port.readall() | ||||
BITS = STAT.split(" ") | ||||
return self.trackingModeStat.get(''.join(BITS[2:4])) | ||||
def save(self,mem=1): | ||||
if mem>=1 and mem<=4: | ||||
self.__port.write("SAV"+str(mem)+"\n") | ||||
else: | ||||
raise UserWarning("Parameter mem of bound 1-4") | ||||
def recal(self,mem=1): | ||||
if mem>=1 and mem<=4: | ||||
self.__port.write("RCL"+str(mem)+"\n") | ||||
else: | ||||
raise UserWarning("Parameter mem of bound 1-4") | ||||
if __name__ == '__main__': | ||||
print("") | ||||