diff --git a/instruments/AG34461A.py b/instruments/AG34461A.py new file mode 100644 index 0000000..6cef3cf --- /dev/null +++ b/instruments/AG34461A.py @@ -0,0 +1,85 @@ +from abstract_instrument import abstract_instrument +import socket + +#============================================================================== + +ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" + +#============================================================================== + +class AG34461A(abstract_instrument): + def __init__(self, adress="192.168.0.61", vtype="DCV"): + self.adress = adress + self.port = 5025 + self.vtype = vtype + + def model(self): + self.send("*IDN?") + return self.read() + + def connect(self): + try: + print('Connecting to device @%s:%s...' %(self.adress, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.adress, self.port)) + print(' --> Ok') + + print(self.model()) + + if self.vtype == "DCV": + self.send("CONF:VOLT:DC") + elif self.vtype == "ACV": + self.send("CONF:VOLT:AC") + elif self.vtype == "DCI": + self.send("CONF:CURR:DC") + elif self.vtype == "ACI": + self.send("CONF:CURR:AC") + elif self.vtype == "RES2W": + self.send("CONF:RES") + elif self.vtype == "RES4W": + self.send("CONF:FRES") + elif self.vtype == "FREQ": + self.send("CONF:FREQ") + else: + print("Wrong -v argument") + raise + + except socket.timeout: + print("Socket timeout error during connection.") + raise + except socket.error as er: + print("Socket error during connection: " + str(er)) + raise + except Exception as er: + print("Unexpected error during connection: " + str(er)) + raise + + def getValue(self): + self.send("READ?") + return self.read() + + def read(self): + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise + + def disconnect(self): + self.send('*RST') + self.sock.close() + + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/AG34972A.py b/instruments/AG34972A.py new file mode 100644 index 0000000..a30206c --- /dev/null +++ b/instruments/AG34972A.py @@ -0,0 +1,85 @@ +from abstract_instrument import abstract_instrument +import socket + +#============================================================================== + +ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" + +#============================================================================== + +class AG34972A(abstract_instrument): + def __init__(self, adress="192.168.0.72", vtype="DCV"): + self.adress = adress + self.port = 5025 + self.vtype = vtype + + def model(self): + self.send("*IDN?") + return self.read() + + def connect(self): + try: + print('Connecting to device @%s:%s...' %(self.adress, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(2.0) # Don't hang around forever + self.sock.connect((self.adress, self.port)) + print(' --> Ok') + + print(self.model()) + + if self.vtype == "DCV": + self.send("CONF:VOLT:DC (@102:103)") + elif self.vtype == "ACV": + self.send("CONF:VOLT:AC (@102:103)") + elif self.vtype == "DCI": + self.send("CONF:CURR:DC (@102:103)") + elif self.vtype == "ACI": + self.send("CONF:CURR:AC (@102:103)") + elif self.vtype == "RES2W": + self.send("CONF:RES (@102:103)") + elif self.vtype == "RES4W": + self.send("CONF:FRES (@102:103)") + elif self.vtype == "FREQ": + self.send("CONF:FREQ (@102:103)") + else: + print("Wrong -v argument") + raise + + except socket.timeout: + print("Socket timeout error during connection.") + raise + except socket.error as er: + print("Socket error during connection: " + str(er)) + raise + except Exception as er: + print("Unexpected error during connection: " + str(er)) + raise + + def getValue(self): + self.send("MEAS? AUTO,DEF,(@102:103)") + return self.read() + + def read(self): + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise + + def disconnect(self): + self.send('*RST') + self.sock.close() + + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/LS350.py b/instruments/LS350.py new file mode 100644 index 0000000..5a4dc71 --- /dev/null +++ b/instruments/LS350.py @@ -0,0 +1,80 @@ +from abstract_instrument import abstract_instrument +import socket + +#============================================================================== + +ALL_VAL_TYPE = "TEMP, RES" + +#============================================================================== + +class LS350(abstract_instrument): + def __init__(self, adress="192.168.0.12", vtype="TEMP"): + self.adress = adress + self.port = 7777 + self.vtype = vtype + + def model(self): + self.send("*IDN?") + return self.read() + + def connect(self): + try: + print('Connecting to device @%s:%s...' %(self.adress, self.port)) + self.sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM, + socket.IPPROTO_TCP) + self.sock.settimeout(10.0) # Don't hang around forever + self.sock.connect((self.adress, self.port)) + print(' --> Ok') + + print(self.model()) + + if self.vtype == "TEMP": + 1 + elif self.vtype == "RES": + 1 + else: + print("Wrong -v argument") + raise + + except socket.timeout: + print("Socket timeout error during connection.") + raise + except socket.error as er: + print("Socket error during connection: " + str(er)) + raise + except Exception as er: + print("Unexpected error during connection: " + str(er)) + raise + + def getValue(self): + if self.vtype == 'TEMP': + self.send('krdg? a;krdg? b;krdg? c;krdg? d') + return self.read() + elif self.vtype == 'RES': + self.send('srdg? a;srdg? b;srdg? c;srdg? d') + return self.read() + + def read(self): + self.send("++read eoi") + ans = '' + nb_data_list = [] + nb_data = '' + try: + while ans != '\n': + ans = self.sock.recv(1) + nb_data_list.append(ans) # Return the number of data + list_size = len(nb_data_list) + for j in range (0, list_size): + nb_data = nb_data+nb_data_list[j] + return nb_data + except socket.timeout: + print "Socket timeout error when reading." + raise + + def disconnect(self): + self.send('MODE0') + self.sock.close() + + def send(self, command): + self.sock.send("%s\n"%command) diff --git a/instruments/PM100D.py b/instruments/PM100D.py new file mode 100644 index 0000000..9d9c69a --- /dev/null +++ b/instruments/PM100D.py @@ -0,0 +1,48 @@ +from abstract_instrument import abstract_instrument +import os + +#============================================================================== + +ALL_VAL_TYPE = "PWR" + +#============================================================================== + +class PM100D(abstract_instrument): + def __init__(self, adress="/dev/usbtmc0", vtype="PWR"): + self.adress = adress + self.vtype = vtype + + def model(self): + self.send("*IDN?") + return self.read() + + def connect(self): + try: + print('Connecting to device @%s...' %(self.adress)) + self.FILE = os.open(self.adress, os.O_RDWR) + print(' --> Ok') + + print(self.model()) + + if self.vtype == "PWR": + 1 + else: + print("Wrong -v argument") + raise + + except Exception as er: + print("Unexpected error during connection: " + str(er)) + raise + + def getValue(self): + self.send("READ?") + return self.read() + + def read(self): + return os.read(self.FILE, 300) + + def disconnect(self): + self.send('*RST') + + def send(self, command): + os.write(self.FILE, command) diff --git a/instruments/T7Pro.py b/instruments/T7Pro.py new file mode 100644 index 0000000..6dad733 --- /dev/null +++ b/instruments/T7Pro.py @@ -0,0 +1,155 @@ +from abstract_instrument import abstract_instrument +from labjack import ljm +import numpy + +#============================================================================== + +ALL_VAL_TYPE = "TEMP, RES" + +#============================================================================== + +class T7Pro(abstract_instrument): + def __init__(self, adress="192.168.0.26", vtype="TEMP"): + self.adress = adress + self.vtype = vtype + self.names = ["TEMPERATURE_AIR_K", + "CURRENT_SOURCE_200UA_CAL_VALUE", + "AIN0",# "AIN1", + "AIN2",# "AIN3", + "AIN4",# "AIN5", + "AIN6",# "AIN7" + ] + + def model(self): + return 'T7Pro' + + def connect(self): + try: + print('Connecting to device @%s...' %(self.adress)) + self.handle = ljm.openS("T7", "ETHERNET", self.adress) + self.configureAINs() + print(' --> Ok') + + print(self.model()) + + if self.vtype == "TEMP": + 1 + elif self.vtype == "RES": + 1 + else: + print("Wrong -v argument") + raise + + except Exception as er: + print("Unexpected error during connection: " + str(er)) + raise + + def getValue(self): + results = self.read(self.names) + temp = results[0] + res1 = results[2]/results[1] + res2 = results[3]/results[1] + res3 = results[4]/results[1] + res4 = results[5]/results[1] + + if self.vtype == 'TEMP': + # Temperature calculation + temp1 = self.res2tempSensor(628, res1) + temp2 = self.res2tempSensor(16947, res2) + temp3 = self.res2tempSensor(625, res3) + temp4 = self.res2tempSensor(100, res4) + string = '%f\t%f\t%f\t%f\t%f\n'%(temp, temp1, temp2, temp3, temp4) + elif self.vtype == 'RES': + string = '%f\t%f\t%f\t%f\t%f\n'%(temp, res1, res2, res3, res4) + else: + string = '' + + return string + + def read(self, names): + return ljm.eReadNames(self.handle, len(names), names) + + def disconnect(self): + ljm.close(self.handle) + + def send(self, command): + pass + + def configureAINs(self): + # Setup and call eWriteNames to configure AINs on the LabJack. + names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", + #"AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", + "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", + #"AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", + "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", + #"AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", + "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", + #"AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX" + ] + l_names = len(names) + aValues = [1, 1, 12, + #199, 0.01, 0, + 3, 1, 12, + #199, 0.01, 0, + 5, 1, 12, + #199, 0.01, 0, + 7, 0.1, 12, + #199, 0.01, 0 + ] + ljm.eWriteNames(self.handle, l_names, names, aValues) +# print("\nSet configuration:") +# for i in range(len(names)): +# print(" %s : %f" % (names[i], aValues[i])) + + def res2tempSensor(self, sensor, res): + if sensor==627: + K = [0.399341181655472610, + 10.8420092277810909, + -26.4597939187660813, + 245.9828566655493379, + -668.069876596331596, + 1001.69882618263364, + -267.272089680656791] + if sensor==625: + K = [0.333548856582638109, + 11.7361551595386118, + -31.32988932320903987, + 262.878643524833024, + -704.163538021035492, + 1056.6040485650301, + -307.057196729816496] + if sensor==628: + K = [0.463200932294057566, + 13.5049710820894688, + -30.5191222755238414, + 231.098593852017075, + -550.122691885568202, + 806.038547554984689, + -198.510489917360246] + if sensor==16945: + K = [3.2497, 5.1777, 2.499] + if sensor==16943: + K = [3.4738, 5.1198, 2.3681] + if sensor==16944: + K = [3.3674, 5.2874, 2.5165] + if sensor==16941: + K = [2.9486, 4.5862, 2.266] + if sensor==16947: + K = [3.4597, 5.2422, 2.4169] + if sensor==100: + K = [0.003850] + return self.res2temp(K, res) + + def res2temp(K, res): + temp = 0 + tmp = 1000./res + if len(K)==7: + for i in range(len(K)): + temp += K[i]*tmp**i + if len(K)==3: + for i in range(len(K)): + temp += K[i]*numpy.log10(tmp)**(2-i) + temp = 10**temp + if len(K)==1: + temp = (res/100.-1)/K[0]+273.15 + return temp diff --git a/instruments/__init__.py b/instruments/__init__.py index 257cc56..fbbc134 100644 --- a/instruments/__init__.py +++ b/instruments/__init__.py @@ -1 +1,9 @@ -foo +from os import listdir +from os.path import dirname + +for module in listdir(dirname(__file__)): + if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': + continue + __import__(module[:-3], locals(), globals()) + +del module, listdir, dirname \ No newline at end of file diff --git a/instruments/abstract_instrument.py b/instruments/abstract_instrument.py new file mode 100644 index 0000000..23dfc51 --- /dev/null +++ b/instruments/abstract_instrument.py @@ -0,0 +1,39 @@ +import abc + +class abstract_instrument(object): + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def __init__(self, adress, vtype): + """Build the class""" + return + + @abc.abstractmethod + def model(self): + """return the instrument model""" + return + + @abc.abstractmethod + def connect(self): + """Create a connection with the instrument""" + return + + @abc.abstractmethod + def disconnect(self): + """Disconnect the instrument""" + return + + @abc.abstractmethod + def read(self): + """read the buffer""" + return + + @abc.abstractmethod + def send(self): + """send a command""" + return + + @abc.abstractmethod + def getValue(self): + """return the value of measurment""" + return diff --git a/instruments/testDevice.py b/instruments/testDevice.py new file mode 100644 index 0000000..28499ef --- /dev/null +++ b/instruments/testDevice.py @@ -0,0 +1,55 @@ +from abstract_instrument import abstract_instrument +import numpy, time + +#============================================================================== + +ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" + +#============================================================================== + +class testDevice(abstract_instrument): + def __init__(self, adress="123.456.789.123", vtype="DCV"): + self.adress = adress + self.port = 9999 + self.vtype = vtype + + def model(self): + return 'test device' + + def connect(self): + print('Connecting to device @%s:%s...' %(self.adress, self.port)) + time.sleep(1) + print(' --> Ok') + + print(self.model()) + + if self.vtype == "DCV": + print("CONF:VOLT:DC") + elif self.vtype == "ACV": + print("CONF:VOLT:AC") + elif self.vtype == "DCI": + print("CONF:CURR:DC") + elif self.vtype == "ACI": + print("CONF:CURR:AC") + elif self.vtype == "RES2W": + print("CONF:RES") + elif self.vtype == "RES4W": + print("CONF:FRES") + elif self.vtype == "FREQ": + print("CONF:FREQ") + else: + print("Wrong -v argument") + raise + + def getValue(self): + return str(numpy.random.rand()) + + def read(self): + print('reading') + return 1 + + def disconnect(self): + print('reset') + + def send(self, command): + print('send %s'%command)