Commit 90e45ebe9dbf970c62e8a864a3462d161ea969d0
Committed by
GitHub
1 parent
ccf79815aa
Exists in
master
Add files via upload
Showing 8 changed files with 556 additions and 1 deletions Inline Diff
instruments/AG34461A.py
File was created | 1 | from abstract_instrument import abstract_instrument | ||
2 | import socket | |||
3 | ||||
4 | #============================================================================== | |||
5 | ||||
6 | ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | |||
7 | ||||
8 | #============================================================================== | |||
9 | ||||
10 | class AG34461A(abstract_instrument): | |||
11 | def __init__(self, adress="192.168.0.61", vtype="DCV"): | |||
12 | self.adress = adress | |||
13 | self.port = 5025 | |||
14 | self.vtype = vtype | |||
15 | ||||
16 | def model(self): | |||
17 | self.send("*IDN?") | |||
18 | return self.read() | |||
19 | ||||
20 | def connect(self): | |||
21 | try: | |||
22 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |||
23 | self.sock = socket.socket(socket.AF_INET, | |||
24 | socket.SOCK_STREAM, | |||
25 | socket.IPPROTO_TCP) | |||
26 | self.sock.settimeout(10.0) # Don't hang around forever | |||
27 | self.sock.connect((self.adress, self.port)) | |||
28 | print(' --> Ok') | |||
29 | ||||
30 | print(self.model()) | |||
31 | ||||
32 | if self.vtype == "DCV": | |||
33 | self.send("CONF:VOLT:DC") | |||
34 | elif self.vtype == "ACV": | |||
35 | self.send("CONF:VOLT:AC") | |||
36 | elif self.vtype == "DCI": | |||
37 | self.send("CONF:CURR:DC") | |||
38 | elif self.vtype == "ACI": | |||
39 | self.send("CONF:CURR:AC") | |||
40 | elif self.vtype == "RES2W": | |||
41 | self.send("CONF:RES") | |||
42 | elif self.vtype == "RES4W": | |||
43 | self.send("CONF:FRES") | |||
44 | elif self.vtype == "FREQ": | |||
45 | self.send("CONF:FREQ") | |||
46 | else: | |||
47 | print("Wrong -v argument") | |||
48 | raise | |||
49 | ||||
50 | except socket.timeout: | |||
51 | print("Socket timeout error during connection.") | |||
52 | raise | |||
53 | except socket.error as er: | |||
54 | print("Socket error during connection: " + str(er)) | |||
55 | raise | |||
56 | except Exception as er: | |||
57 | print("Unexpected error during connection: " + str(er)) | |||
58 | raise | |||
59 | ||||
60 | def getValue(self): | |||
61 | self.send("READ?") | |||
62 | return self.read() | |||
63 | ||||
64 | def read(self): | |||
65 | ans = '' | |||
66 | nb_data_list = [] | |||
67 | nb_data = '' | |||
68 | try: | |||
69 | while ans != '\n': | |||
70 | ans = self.sock.recv(1) | |||
71 | nb_data_list.append(ans) # Return the number of data | |||
72 | list_size = len(nb_data_list) |
instruments/AG34972A.py
File was created | 1 | from abstract_instrument import abstract_instrument | ||
2 | import socket | |||
3 | ||||
4 | #============================================================================== | |||
5 | ||||
6 | ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | |||
7 | ||||
8 | #============================================================================== | |||
9 | ||||
10 | class AG34972A(abstract_instrument): | |||
11 | def __init__(self, adress="192.168.0.72", vtype="DCV"): | |||
12 | self.adress = adress | |||
13 | self.port = 5025 | |||
14 | self.vtype = vtype | |||
15 | ||||
16 | def model(self): | |||
17 | self.send("*IDN?") | |||
18 | return self.read() | |||
19 | ||||
20 | def connect(self): | |||
21 | try: | |||
22 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |||
23 | self.sock = socket.socket(socket.AF_INET, | |||
24 | socket.SOCK_STREAM, | |||
25 | socket.IPPROTO_TCP) | |||
26 | self.sock.settimeout(2.0) # Don't hang around forever | |||
27 | self.sock.connect((self.adress, self.port)) | |||
28 | print(' --> Ok') | |||
29 | ||||
30 | print(self.model()) | |||
31 | ||||
32 | if self.vtype == "DCV": | |||
33 | self.send("CONF:VOLT:DC (@102:103)") | |||
34 | elif self.vtype == "ACV": | |||
35 | self.send("CONF:VOLT:AC (@102:103)") | |||
36 | elif self.vtype == "DCI": | |||
37 | self.send("CONF:CURR:DC (@102:103)") | |||
38 | elif self.vtype == "ACI": | |||
39 | self.send("CONF:CURR:AC (@102:103)") | |||
40 | elif self.vtype == "RES2W": | |||
41 | self.send("CONF:RES (@102:103)") | |||
42 | elif self.vtype == "RES4W": | |||
43 | self.send("CONF:FRES (@102:103)") | |||
44 | elif self.vtype == "FREQ": | |||
45 | self.send("CONF:FREQ (@102:103)") | |||
46 | else: | |||
47 | print("Wrong -v argument") | |||
48 | raise | |||
49 | ||||
50 | except socket.timeout: | |||
51 | print("Socket timeout error during connection.") | |||
52 | raise | |||
53 | except socket.error as er: | |||
54 | print("Socket error during connection: " + str(er)) | |||
55 | raise | |||
56 | except Exception as er: | |||
57 | print("Unexpected error during connection: " + str(er)) | |||
58 | raise | |||
59 | ||||
60 | def getValue(self): | |||
61 | self.send("MEAS? AUTO,DEF,(@102:103)") | |||
62 | return self.read() | |||
63 | ||||
64 | def read(self): | |||
65 | ans = '' | |||
66 | nb_data_list = [] | |||
67 | nb_data = '' | |||
68 | try: | |||
69 | while ans != '\n': | |||
70 | ans = self.sock.recv(1) | |||
71 | nb_data_list.append(ans) # Return the number of data | |||
72 | list_size = len(nb_data_list) |
instruments/LS350.py
File was created | 1 | from abstract_instrument import abstract_instrument | ||
2 | import socket | |||
3 | ||||
4 | #============================================================================== | |||
5 | ||||
6 | ALL_VAL_TYPE = "TEMP, RES" | |||
7 | ||||
8 | #============================================================================== | |||
9 | ||||
10 | class LS350(abstract_instrument): | |||
11 | def __init__(self, adress="192.168.0.12", vtype="TEMP"): | |||
12 | self.adress = adress | |||
13 | self.port = 7777 | |||
14 | self.vtype = vtype | |||
15 | ||||
16 | def model(self): | |||
17 | self.send("*IDN?") | |||
18 | return self.read() | |||
19 | ||||
20 | def connect(self): | |||
21 | try: | |||
22 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |||
23 | self.sock = socket.socket(socket.AF_INET, | |||
24 | socket.SOCK_STREAM, | |||
25 | socket.IPPROTO_TCP) | |||
26 | self.sock.settimeout(10.0) # Don't hang around forever | |||
27 | self.sock.connect((self.adress, self.port)) | |||
28 | print(' --> Ok') | |||
29 | ||||
30 | print(self.model()) | |||
31 | ||||
32 | if self.vtype == "TEMP": | |||
33 | 1 | |||
34 | elif self.vtype == "RES": | |||
35 | 1 | |||
36 | else: | |||
37 | print("Wrong -v argument") | |||
38 | raise | |||
39 | ||||
40 | except socket.timeout: | |||
41 | print("Socket timeout error during connection.") | |||
42 | raise | |||
43 | except socket.error as er: | |||
44 | print("Socket error during connection: " + str(er)) | |||
45 | raise | |||
46 | except Exception as er: | |||
47 | print("Unexpected error during connection: " + str(er)) | |||
48 | raise | |||
49 | ||||
50 | def getValue(self): | |||
51 | if self.vtype == 'TEMP': | |||
52 | self.send('krdg? a;krdg? b;krdg? c;krdg? d') | |||
53 | return self.read() | |||
54 | elif self.vtype == 'RES': | |||
55 | self.send('srdg? a;srdg? b;srdg? c;srdg? d') | |||
56 | return self.read() | |||
57 | ||||
58 | def read(self): | |||
59 | self.send("++read eoi") | |||
60 | ans = '' | |||
61 | nb_data_list = [] | |||
62 | nb_data = '' | |||
63 | try: | |||
64 | while ans != '\n': | |||
65 | ans = self.sock.recv(1) | |||
66 | nb_data_list.append(ans) # Return the number of data | |||
67 | list_size = len(nb_data_list) |
instruments/PM100D.py
File was created | 1 | from abstract_instrument import abstract_instrument | ||
2 | import os | |||
3 | ||||
4 | #============================================================================== | |||
5 | ||||
6 | ALL_VAL_TYPE = "PWR" | |||
7 | ||||
8 | #============================================================================== | |||
9 | ||||
10 | class PM100D(abstract_instrument): | |||
11 | def __init__(self, adress="/dev/usbtmc0", vtype="PWR"): | |||
12 | self.adress = adress | |||
13 | self.vtype = vtype | |||
14 | ||||
15 | def model(self): | |||
16 | self.send("*IDN?") | |||
17 | return self.read() | |||
18 | ||||
19 | def connect(self): | |||
20 | try: | |||
21 | print('Connecting to device @%s...' %(self.adress)) | |||
22 | self.FILE = os.open(self.adress, os.O_RDWR) | |||
23 | print(' --> Ok') | |||
24 | ||||
25 | print(self.model()) | |||
26 | ||||
27 | if self.vtype == "PWR": | |||
28 | 1 | |||
29 | else: | |||
30 | print("Wrong -v argument") | |||
31 | raise | |||
32 | ||||
33 | except Exception as er: | |||
34 | print("Unexpected error during connection: " + str(er)) | |||
35 | raise |
instruments/T7Pro.py
File was created | 1 | from abstract_instrument import abstract_instrument | ||
2 | from labjack import ljm | |||
3 | import numpy | |||
4 | ||||
5 | #============================================================================== | |||
6 | ||||
7 | ALL_VAL_TYPE = "TEMP, RES" | |||
8 | ||||
9 | #============================================================================== | |||
10 | ||||
11 | class T7Pro(abstract_instrument): | |||
12 | def __init__(self, adress="192.168.0.26", vtype="TEMP"): | |||
13 | self.adress = adress | |||
14 | self.vtype = vtype | |||
15 | self.names = ["TEMPERATURE_AIR_K", | |||
16 | "CURRENT_SOURCE_200UA_CAL_VALUE", | |||
17 | "AIN0",# "AIN1", | |||
18 | "AIN2",# "AIN3", | |||
19 | "AIN4",# "AIN5", | |||
20 | "AIN6",# "AIN7" | |||
21 | ] | |||
22 | ||||
23 | def model(self): | |||
24 | return 'T7Pro' | |||
25 | ||||
26 | def connect(self): | |||
27 | try: | |||
28 | print('Connecting to device @%s...' %(self.adress)) | |||
29 | self.handle = ljm.openS("T7", "ETHERNET", self.adress) | |||
30 | self.configureAINs() | |||
31 | print(' --> Ok') | |||
32 | ||||
33 | print(self.model()) | |||
34 | ||||
35 | if self.vtype == "TEMP": | |||
36 | 1 | |||
37 | elif self.vtype == "RES": | |||
38 | 1 | |||
39 | else: | |||
40 | print("Wrong -v argument") | |||
41 | raise | |||
42 | ||||
43 | except Exception as er: | |||
44 | print("Unexpected error during connection: " + str(er)) | |||
45 | raise | |||
46 | ||||
47 | def getValue(self): | |||
48 | results = self.read(self.names) | |||
49 | temp = results[0] | |||
50 | res1 = results[2]/results[1] | |||
51 | res2 = results[3]/results[1] | |||
52 | res3 = results[4]/results[1] | |||
53 | res4 = results[5]/results[1] | |||
54 | ||||
55 | if self.vtype == 'TEMP': | |||
56 | # Temperature calculation | |||
57 | temp1 = self.res2tempSensor(628, res1) | |||
58 | temp2 = self.res2tempSensor(16947, res2) | |||
59 | temp3 = self.res2tempSensor(625, res3) | |||
60 | temp4 = self.res2tempSensor(100, res4) | |||
61 | string = '%f\t%f\t%f\t%f\t%f\n'%(temp, temp1, temp2, temp3, temp4) | |||
62 | elif self.vtype == 'RES': | |||
63 | string = '%f\t%f\t%f\t%f\t%f\n'%(temp, res1, res2, res3, res4) | |||
64 | else: | |||
65 | string = '' | |||
66 | ||||
67 | return string | |||
68 | ||||
69 | def read(self, names): | |||
70 | return ljm.eReadNames(self.handle, len(names), names) | |||
71 | ||||
72 | def disconnect(self): | |||
73 | ljm.close(self.handle) | |||
74 | ||||
75 | def send(self, command): | |||
76 | pass | |||
77 | ||||
78 | def configureAINs(self): | |||
79 | # Setup and call eWriteNames to configure AINs on the LabJack. | |||
80 | names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", | |||
81 | #"AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", | |||
82 | "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", | |||
83 | #"AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", | |||
84 | "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", | |||
85 | #"AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", | |||
86 | "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", | |||
87 | #"AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX" | |||
88 | ] | |||
89 | l_names = len(names) | |||
90 | aValues = [1, 1, 12, | |||
91 | #199, 0.01, 0, | |||
92 | 3, 1, 12, | |||
93 | #199, 0.01, 0, | |||
94 | 5, 1, 12, | |||
95 | #199, 0.01, 0, | |||
96 | 7, 0.1, 12, | |||
97 | #199, 0.01, 0 | |||
98 | ] | |||
99 | ljm.eWriteNames(self.handle, l_names, names, aValues) | |||
100 | # print("\nSet configuration:") | |||
101 | # for i in range(len(names)): | |||
102 | # print(" %s : %f" % (names[i], aValues[i])) | |||
103 | ||||
104 | def res2tempSensor(self, sensor, res): | |||
105 | if sensor==627: | |||
106 | K = [0.399341181655472610, | |||
107 | 10.8420092277810909, | |||
108 | -26.4597939187660813, | |||
109 | 245.9828566655493379, | |||
110 | -668.069876596331596, | |||
111 | 1001.69882618263364, | |||
112 | -267.272089680656791] | |||
113 | if sensor==625: | |||
114 | K = [0.333548856582638109, | |||
115 | 11.7361551595386118, | |||
116 | -31.32988932320903987, | |||
117 | 262.878643524833024, | |||
118 | -704.163538021035492, | |||
119 | 1056.6040485650301, | |||
120 | -307.057196729816496] | |||
121 | if sensor==628: | |||
122 | K = [0.463200932294057566, | |||
123 | 13.5049710820894688, | |||
124 | -30.5191222755238414, | |||
125 | 231.098593852017075, | |||
126 | -550.122691885568202, | |||
127 | 806.038547554984689, | |||
128 | -198.510489917360246] | |||
129 | if sensor==16945: | |||
130 | K = [3.2497, 5.1777, 2.499] | |||
131 | if sensor==16943: | |||
132 | K = [3.4738, 5.1198, 2.3681] | |||
133 | if sensor==16944: | |||
134 | K = [3.3674, 5.2874, 2.5165] | |||
135 | if sensor==16941: | |||
136 | K = [2.9486, 4.5862, 2.266] | |||
137 | if sensor==16947: |
instruments/__init__.py
foo | 1 | 1 | from os import listdir | |
2 | from os.path import dirname | |||
3 | ||||
4 | for module in listdir(dirname(__file__)): | |||
5 | if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': | |||
6 | continue | |||
7 | __import__(module[:-3], locals(), globals()) | |||
8 | ||||
9 | del module, listdir, dirname | |||
2 |
instruments/abstract_instrument.py
File was created | 1 | import abc | ||
2 | ||||
3 | class abstract_instrument(object): | |||
4 | __metaclass__ = abc.ABCMeta | |||
5 | ||||
6 | @abc.abstractmethod | |||
7 | def __init__(self, adress, vtype): | |||
8 | """Build the class""" | |||
9 | return | |||
10 | ||||
11 | @abc.abstractmethod | |||
12 | def model(self): | |||
13 | """return the instrument model""" | |||
14 | return | |||
15 | ||||
16 | @abc.abstractmethod | |||
17 | def connect(self): | |||
18 | """Create a connection with the instrument""" | |||
19 | return | |||
20 | ||||
21 | @abc.abstractmethod | |||
22 | def disconnect(self): | |||
23 | """Disconnect the instrument""" | |||
24 | return | |||
25 | ||||
26 | @abc.abstractmethod | |||
27 | def read(self): | |||
28 | """read the buffer""" | |||
29 | return | |||
30 | ||||
31 | @abc.abstractmethod |
instruments/testDevice.py
File was created | 1 | from abstract_instrument import abstract_instrument | ||
2 | import numpy, time | |||
3 | ||||
4 | #============================================================================== | |||
5 | ||||
6 | ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | |||
7 | ||||
8 | #============================================================================== | |||
9 | ||||
10 | class testDevice(abstract_instrument): | |||
11 | def __init__(self, adress="123.456.789.123", vtype="DCV"): | |||
12 | self.adress = adress | |||
13 | self.port = 9999 | |||
14 | self.vtype = vtype | |||
15 | ||||
16 | def model(self): | |||
17 | return 'test device' | |||
18 | ||||
19 | def connect(self): | |||
20 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |||
21 | time.sleep(1) | |||
22 | print(' --> Ok') | |||
23 | ||||
24 | print(self.model()) | |||
25 | ||||
26 | if self.vtype == "DCV": | |||
27 | print("CONF:VOLT:DC") | |||
28 | elif self.vtype == "ACV": | |||
29 | print("CONF:VOLT:AC") | |||
30 | elif self.vtype == "DCI": | |||
31 | print("CONF:CURR:DC") | |||
32 | elif self.vtype == "ACI": | |||
33 | print("CONF:CURR:AC") | |||
34 | elif self.vtype == "RES2W": | |||
35 | print("CONF:RES") | |||
36 | elif self.vtype == "RES4W": | |||
37 | print("CONF:FRES") | |||
38 | elif self.vtype == "FREQ": | |||
39 | print("CONF:FREQ") | |||
40 | else: | |||
41 | print("Wrong -v argument") | |||
42 | raise | |||
43 |