Commit ff6ac074765154ae401b771db9af7e379be8ebcb
1 parent
67c0abcaa5
Exists in
master
Remove some files from master
Showing 3 changed files with 0 additions and 288 deletions Side-by-side Diff
instruments/LS350.py
1 | -from abstract_instrument import abstract_instrument | |
2 | -import socket | |
3 | - | |
4 | -#============================================================================== | |
5 | - | |
6 | -ALL_VAL_TYPE = ['TEMP', 'RES'] | |
7 | -ALL_CHANNELS = ['a', 'b', 'c', 'd'] | |
8 | - | |
9 | -ADRESS = "192.168.0.12" | |
10 | -CONF_VAL_TYPE = ['krdg?', 'srdg?'] | |
11 | - | |
12 | -#============================================================================== | |
13 | - | |
14 | -class LS350(abstract_instrument): | |
15 | - def __init__(self, channels, vtypes, adress): | |
16 | - self.adress = adress | |
17 | - self.port = 7777 | |
18 | - self.channels = channels | |
19 | - self.vtypes = vtypes | |
20 | - | |
21 | - def model(self): | |
22 | - #self.send("*IDN?") | |
23 | - #return self.read() | |
24 | - return "LS350" | |
25 | - | |
26 | - def connect(self): | |
27 | - print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
28 | - self.sock = socket.socket(socket.AF_INET, | |
29 | - socket.SOCK_STREAM, | |
30 | - socket.IPPROTO_TCP) | |
31 | - self.sock.settimeout(10.0) # Don't hang around forever | |
32 | - self.sock.connect((self.adress, self.port)) | |
33 | - print(' --> Ok') | |
34 | - print(self.model()) | |
35 | - self.configure() | |
36 | - | |
37 | - def configure(self): | |
38 | - self.strCh = '' | |
39 | - for ch in self.channels: | |
40 | - self.strCh = self.strCh + '%s %s;'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch) | |
41 | - self.strCh = self.strCh[0:-1] | |
42 | - print(self.strCh) | |
43 | - | |
44 | - def getValue(self): | |
45 | - self.send(self.strCh) | |
46 | - return self.read() | |
47 | - | |
48 | - def read(self): | |
49 | - self.send("++read eoi") | |
50 | - ans = '' | |
51 | - nb_data_list = [] | |
52 | - nb_data = '' | |
53 | - try: | |
54 | - while ans != '\n': | |
55 | - ans = self.sock.recv(1) | |
56 | - nb_data_list.append(ans) # Return the number of data | |
57 | - list_size = len(nb_data_list) | |
58 | - for j in range (0, list_size): | |
59 | - nb_data = nb_data+nb_data_list[j] | |
60 | - return nb_data | |
61 | - except socket.timeout: | |
62 | - print "Socket timeout error when reading." | |
63 | - raise | |
64 | - | |
65 | - def disconnect(self): | |
66 | - self.send('MODE0') | |
67 | - self.sock.close() | |
68 | - | |
69 | - def send(self, command): | |
70 | - self.sock.send("%s\n"%command) |
instruments/T7Pro.py
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 | -ALL_CHANNELS = ['TEMP', '1', '2', '3', '4'] | |
9 | -ADRESS = "192.168.0.25" | |
10 | - | |
11 | -#============================================================================== | |
12 | - | |
13 | -class T7Pro(abstract_instrument): | |
14 | - def __init__(self, adress=ADRESS, vtype=[ALL_VAL_TYPE[0]], channels = [ALL_CHANNELS[0]]): | |
15 | - self.adress = adress | |
16 | - self.vtype = vtype | |
17 | - self.tempName = ["TEMPERATURE_AIR_K"] | |
18 | - self.res1Name = ["AIN0", "AIN10"] | |
19 | - self.res2Name = ["AIN2", "AIN11"] | |
20 | - self.res3Name = ["AIN4", "AIN12"] | |
21 | - self.res4Name = ["AIN6", "AIN13"] | |
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 | - mesTemp = self.read(self.tempName) | |
49 | - mesRes1 = self.read(self.res1Name) | |
50 | - mesRes2 = self.read(self.res2Name) | |
51 | - mesRes3 = self.read(self.res3Name) | |
52 | - mesRes4 = self.read(self.res4Name) | |
53 | -# mesRes4 = [1, 1] | |
54 | -# print("~~~~~~~~~~~~~~~~~~~~~~\n" + str(results) + "~~~~~~~~~~~~~~~~~~~~~~\n") | |
55 | - temp = mesTemp[0] | |
56 | - res1 = 100.*mesRes1[0]/mesRes1[1] | |
57 | - res2 = 100.*mesRes2[0]/mesRes2[1] | |
58 | - res3 = 100.*mesRes3[0]/mesRes3[1] | |
59 | - res4 = 100.*mesRes4[0]/mesRes4[1] | |
60 | - | |
61 | - if self.vtype == 'TEMP': | |
62 | - # Temperature calculation | |
63 | - temp1 = self.res2tempSensor(628, res1) | |
64 | - temp2 = self.res2tempSensor(16947, res2) | |
65 | - temp3 = self.res2tempSensor(625, res3) | |
66 | - temp4 = self.res2tempSensor(100, res4) | |
67 | - string = '%f\t%f\t%f\t%f\t%f\n'%(temp, temp1, temp2, temp3, temp4) | |
68 | -# string = '%f\t%f\n'%(temp, temp1) | |
69 | - elif self.vtype == 'RES': | |
70 | - string = '%f\t%f\t%f\t%f\t%f\n'%(temp, res1, res2, res3, res4) | |
71 | -# string = '%f\t%f\n'%(temp, res1) | |
72 | - else: | |
73 | - string = '' | |
74 | - | |
75 | - return string | |
76 | - | |
77 | - def read(self, names): | |
78 | - return ljm.eReadNames(self.handle, len(names), names) | |
79 | - | |
80 | - def disconnect(self): | |
81 | - ljm.close(self.handle) | |
82 | - | |
83 | - def send(self, command): | |
84 | - pass | |
85 | - | |
86 | - def configureAINs(self): | |
87 | - # Setup and call eWriteNames to configure AINs on the LabJack. | |
88 | - names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", | |
89 | - "AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", | |
90 | - "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", | |
91 | - "AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", | |
92 | - "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", | |
93 | - "AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", | |
94 | - "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", | |
95 | - "AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX", | |
96 | - "AIN8_NEGATIVE_CH", "AIN8_RANGE", "AIN8_RESOLUTION_INDEX", | |
97 | - "AIN9_NEGATIVE_CH", "AIN9_RANGE", "AIN9_RESOLUTION_INDEX", | |
98 | - "AIN10_NEGATIVE_CH", "AIN10_RANGE", "AIN10_RESOLUTION_INDEX", | |
99 | - "AIN11_NEGATIVE_CH", "AIN11_RANGE", "AIN11_RESOLUTION_INDEX", | |
100 | - "AIN12_NEGATIVE_CH", "AIN12_RANGE", "AIN12_RESOLUTION_INDEX", | |
101 | - "AIN13_NEGATIVE_CH", "AIN13_RANGE", "AIN13_RESOLUTION_INDEX" | |
102 | - ] | |
103 | - l_names = len(names) | |
104 | - aValues = [1, 0.1, 12,#0 | |
105 | - 199, 0.1, 12,#1 | |
106 | - 3, 0.1, 12,#2 | |
107 | - 199, 0.1, 12,#3 | |
108 | - 5, 0.1, 12,#4 | |
109 | - 199, 0.1, 12,#5 | |
110 | - 7, 0.1, 12,#6 | |
111 | - 199, 0.1, 12,#7 | |
112 | - 199, 0.1, 12,#8 | |
113 | - 199, 0.1, 12,#9 | |
114 | - 199, 0.1, 12,#10 | |
115 | - 199, 0.1, 12,#11 | |
116 | - 199, 0.1, 12,#12 | |
117 | - 199, 0.1, 12#13 | |
118 | - ] | |
119 | - ljm.eWriteNames(self.handle, l_names, names, aValues) | |
120 | - | |
121 | - | |
122 | - def res2tempSensor(self, sensor, res): | |
123 | - if sensor==627: | |
124 | - K = [0.399341181655472610, | |
125 | - 10.8420092277810909, | |
126 | - -26.4597939187660813, | |
127 | - 245.9828566655493379, | |
128 | - -668.069876596331596, | |
129 | - 1001.69882618263364, | |
130 | - -267.272089680656791] | |
131 | - if sensor==625: | |
132 | - K = [0.333548856582638109, | |
133 | - 11.7361551595386118, | |
134 | - -31.32988932320903987, | |
135 | - 262.878643524833024, | |
136 | - -704.163538021035492, | |
137 | - 1056.6040485650301, | |
138 | - -307.057196729816496] | |
139 | - if sensor==628: | |
140 | - K = [0.463200932294057566, | |
141 | - 13.5049710820894688, | |
142 | - -30.5191222755238414, | |
143 | - 231.098593852017075, | |
144 | - -550.122691885568202, | |
145 | - 806.038547554984689, | |
146 | - -198.510489917360246] | |
147 | - if sensor==16945: | |
148 | - K = [3.2497, 5.1777, 2.499] | |
149 | - if sensor==16943: | |
150 | - K = [3.4738, 5.1198, 2.3681] | |
151 | - if sensor==16944: | |
152 | - K = [3.3674, 5.2874, 2.5165] | |
153 | - if sensor==16941: | |
154 | - K = [2.9486, 4.5862, 2.266] | |
155 | - if sensor==16947: | |
156 | - K = [3.4597, 5.2422, 2.4169] | |
157 | - if sensor==100: | |
158 | - K = [0.003850] | |
159 | - return self.res2temp(K, res) | |
160 | - | |
161 | - def res2temp(K, res): | |
162 | - temp = 0 | |
163 | - tmp = 1000./res | |
164 | - if len(K)==7: | |
165 | - for i in range(len(K)): | |
166 | - temp += K[i]*tmp**i | |
167 | - if len(K)==3: | |
168 | - for i in range(len(K)): | |
169 | - temp += K[i]*numpy.log10(tmp)**(2-i) | |
170 | - temp = 10**temp | |
171 | - if len(K)==1: | |
172 | - temp = (res/100.-1)/K[0]+273.15 | |
173 | - return temp |
instruments/testDevice.py
1 | -from abstract_instrument import abstract_instrument | |
2 | -import numpy, time | |
3 | - | |
4 | -#============================================================================== | |
5 | - | |
6 | -ALL_VAL_TYPE = ['vtype', 'DCV', 'ACV', 'DCI', 'ACI', 'RES2W', 'RES4W', 'FREQ'] | |
7 | -ALL_CHANNELS = ['0', '1'] | |
8 | -ADRESS = "123.456.789.123" | |
9 | - | |
10 | -#============================================================================== | |
11 | - | |
12 | -class testDevice(abstract_instrument): | |
13 | - def __init__(self, channels, vtype, adress = ADRESS): | |
14 | - self.adress = adress | |
15 | - self.port = 9999 | |
16 | - self.channels = channels | |
17 | - print(self.channels) | |
18 | - self.vtype = vtype | |
19 | - print(self.vtype) | |
20 | - | |
21 | - def model(self): | |
22 | - return 'test_device' | |
23 | - | |
24 | - def connect(self): | |
25 | - print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
26 | - time.sleep(1) | |
27 | - print(' --> Ok') | |
28 | - | |
29 | - print(self.model()) | |
30 | - | |
31 | - def getValue(self): | |
32 | - mes = "" | |
33 | - for ch in self.channels: | |
34 | - mes = mes + str(numpy.random.rand()) + '\t' | |
35 | - return mes + '\n' | |
36 | - | |
37 | - def read(self): | |
38 | - print('reading') | |
39 | - return 1 | |
40 | - | |
41 | - def disconnect(self): | |
42 | - print('disconnect') | |
43 | - | |
44 | - def send(self, command): | |
45 | - print('send %s'%command) |