Commit 10016888cd0b79903c0d05c74bbae4d74a5d49ad
1 parent
befe737ed5
Exists in
master
replace 4 spaces by tabs
Showing 9 changed files with 624 additions and 624 deletions Side-by-side Diff
datalogger.py
... | ... | @@ -22,190 +22,190 @@ |
22 | 22 | #============================================================================== |
23 | 23 | |
24 | 24 | def parse(): |
25 | - """ | |
26 | - Specific parsing procedure for transfering data from any abstract instrument. | |
27 | - :returns: populated namespace (parser) | |
28 | - """ | |
25 | + """ | |
26 | + Specific parsing procedure for transfering data from any abstract instrument. | |
27 | + :returns: populated namespace (parser) | |
28 | + """ | |
29 | 29 | |
30 | - parser = argparse.ArgumentParser(description = 'Acquire data from INSTRUMENT', | |
31 | - epilog = 'Example: \'./datalogger.py -i myInstrument -st 10\' logs myInstrument every 10 seconds to output file YYYYMMDD-HHMMSS-INSTRUMENT.dat') | |
30 | + parser = argparse.ArgumentParser(description = 'Acquire data from INSTRUMENT', | |
31 | + epilog = 'Example: \'./datalogger.py -i myInstrument -st 10\' logs myInstrument every 10 seconds to output file YYYYMMDD-HHMMSS-INSTRUMENT.dat') | |
32 | 32 | |
33 | - parser.add_argument('-l', | |
34 | - action='store_true', | |
35 | - dest='list', | |
36 | - default=False, | |
37 | - help='List all available instruments') | |
33 | + parser.add_argument('-l', | |
34 | + action='store_true', | |
35 | + dest='list', | |
36 | + default=False, | |
37 | + help='List all available instruments') | |
38 | 38 | |
39 | - parser.add_argument('-I', | |
40 | - action='store', | |
41 | - dest='instLog', | |
42 | - default=INSTRUMENT, | |
43 | - help='Instrument to log (default '+str(INSTRUMENT)+')') | |
39 | + parser.add_argument('-I', | |
40 | + action='store', | |
41 | + dest='instLog', | |
42 | + default=INSTRUMENT, | |
43 | + help='Instrument to log (default '+str(INSTRUMENT)+')') | |
44 | 44 | |
45 | - parser.add_argument('-ip', | |
46 | - action='store', | |
47 | - dest='adress', | |
48 | - default=ADRESS, | |
49 | - help='Adress of instrument (IP, USB...) (default '+str(ADRESS)+')') | |
45 | + parser.add_argument('-ip', | |
46 | + action='store', | |
47 | + dest='adress', | |
48 | + default=ADRESS, | |
49 | + help='Adress of instrument (IP, USB...) (default '+str(ADRESS)+')') | |
50 | 50 | |
51 | - parser.add_argument('-v', | |
52 | - action='store', | |
53 | - dest='vtype', | |
54 | - default=VAL_TYPE, | |
55 | - help='Value type to measure (default '+str(VAL_TYPE)+')') | |
51 | + parser.add_argument('-v', | |
52 | + action='store', | |
53 | + dest='vtype', | |
54 | + default=VAL_TYPE, | |
55 | + help='Value type to measure (default '+str(VAL_TYPE)+')') | |
56 | 56 | |
57 | - parser.add_argument('-st', | |
58 | - action='store', | |
59 | - dest='samplingtime', | |
60 | - default=SAMPLING_TIME, | |
61 | - help='Sampling time acquistion (default '+str(SAMPLING_TIME)+' second)') | |
57 | + parser.add_argument('-st', | |
58 | + action='store', | |
59 | + dest='samplingtime', | |
60 | + default=SAMPLING_TIME, | |
61 | + help='Sampling time acquistion (default '+str(SAMPLING_TIME)+' second)') | |
62 | 62 | |
63 | - parser.add_argument('-fd', | |
64 | - action='store', | |
65 | - dest='fileduration', | |
66 | - default=FILE_DURATION, | |
67 | - help='File duration (infinite : \'-fd -1\') (default '+str(FILE_DURATION)+' second)') | |
63 | + parser.add_argument('-fd', | |
64 | + action='store', | |
65 | + dest='fileduration', | |
66 | + default=FILE_DURATION, | |
67 | + help='File duration (infinite : \'-fd -1\') (default '+str(FILE_DURATION)+' second)') | |
68 | 68 | |
69 | - parser.add_argument('-p', | |
70 | - action='store', | |
71 | - dest='path', | |
72 | - default=PATH, | |
73 | - help='Absolute path (default '+PATH+')') | |
69 | + parser.add_argument('-p', | |
70 | + action='store', | |
71 | + dest='path', | |
72 | + default=PATH, | |
73 | + help='Absolute path (default '+PATH+')') | |
74 | 74 | |
75 | - args = parser.parse_args() | |
76 | - return args | |
75 | + args = parser.parse_args() | |
76 | + return args | |
77 | 77 | |
78 | 78 | #============================================================================== |
79 | 79 | |
80 | 80 | def acq_routine(instrument, path, samplingtime, fileduration): |
81 | - instrument.connect() | |
82 | - t0 = time.time() | |
83 | - filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | |
84 | - print('Opening %s' %filename) | |
85 | - try: | |
86 | - year = time.strftime("%Y", time.gmtime(t0)) | |
87 | - month = time.strftime("%Y-%m", time.gmtime(t0)) | |
88 | - os.chdir(path + '/' + year + '/' + month) | |
89 | - except: | |
90 | - try: | |
91 | - os.chdir(path + '/' + year) | |
92 | - os.mkdir(month) | |
93 | - os.chdir(path + '/' + year + '/' + month) | |
94 | - except: | |
95 | - os.chdir(path) | |
96 | - os.mkdir(year) | |
97 | - os.chdir(path + '/' + year) | |
98 | - os.mkdir(month) | |
99 | - os.chdir(path + '/' + year + '/' + month) | |
81 | + instrument.connect() | |
82 | + t0 = time.time() | |
83 | + filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | |
84 | + print('Opening %s' %filename) | |
85 | + try: | |
86 | + year = time.strftime("%Y", time.gmtime(t0)) | |
87 | + month = time.strftime("%Y-%m", time.gmtime(t0)) | |
88 | + os.chdir(path + '/' + year + '/' + month) | |
89 | + except: | |
90 | + try: | |
91 | + os.chdir(path + '/' + year) | |
92 | + os.mkdir(month) | |
93 | + os.chdir(path + '/' + year + '/' + month) | |
94 | + except: | |
95 | + os.chdir(path) | |
96 | + os.mkdir(year) | |
97 | + os.chdir(path + '/' + year) | |
98 | + os.mkdir(month) | |
99 | + os.chdir(path + '/' + year + '/' + month) | |
100 | 100 | |
101 | - data_file = open(filename, 'wr', 0) | |
101 | + data_file = open(filename, 'wr', 0) | |
102 | 102 | |
103 | - # Infinite loop | |
104 | - while True: | |
105 | - # tic | |
106 | - tic = time.time() | |
103 | + # Infinite loop | |
104 | + while True: | |
105 | + # tic | |
106 | + tic = time.time() | |
107 | 107 | |
108 | - if time.time() - t0 >= fileduration: | |
109 | - t0 = time.time() | |
110 | - print('Closing %s\n' %filename) | |
111 | - data_file.close() | |
108 | + if time.time() - t0 >= fileduration: | |
109 | + t0 = time.time() | |
110 | + print('Closing %s\n' %filename) | |
111 | + data_file.close() | |
112 | 112 | |
113 | - try: | |
114 | - year = time.strftime("%Y", time.gmtime(t0)) | |
115 | - month = time.strftime("%Y-%m", time.gmtime(t0)) | |
116 | - os.chdir(path + '/' + year + '/' + month) | |
117 | - except: | |
118 | - try: | |
119 | - os.chdir(path + '/' + year) | |
120 | - os.mkdir(month) | |
121 | - os.chdir(path + '/' + year + '/' + month) | |
122 | - except: | |
123 | - os.chdir(path) | |
124 | - os.mkdir(year) | |
125 | - os.chdir(path + '/' + year) | |
126 | - os.mkdir(month) | |
127 | - os.chdir(path + '/' + year + '/' + month) | |
113 | + try: | |
114 | + year = time.strftime("%Y", time.gmtime(t0)) | |
115 | + month = time.strftime("%Y-%m", time.gmtime(t0)) | |
116 | + os.chdir(path + '/' + year + '/' + month) | |
117 | + except: | |
118 | + try: | |
119 | + os.chdir(path + '/' + year) | |
120 | + os.mkdir(month) | |
121 | + os.chdir(path + '/' + year + '/' + month) | |
122 | + except: | |
123 | + os.chdir(path) | |
124 | + os.mkdir(year) | |
125 | + os.chdir(path + '/' + year) | |
126 | + os.mkdir(month) | |
127 | + os.chdir(path + '/' + year + '/' + month) | |
128 | 128 | |
129 | - filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | |
130 | - print('Opening %s\n' %filename) | |
131 | - data_file = open(filename, 'wr', 0) | |
129 | + filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | |
130 | + print('Opening %s\n' %filename) | |
131 | + data_file = open(filename, 'wr', 0) | |
132 | 132 | |
133 | - try: | |
134 | - try: | |
135 | - #epoch time | |
136 | - epoch = time.time() | |
137 | - #MJD time | |
138 | - mjd = epoch / 86400.0 + 40587 | |
139 | - # Meas values | |
140 | - meas = instrument.getValue() | |
141 | - meas = meas.replace(",", "\t") | |
142 | - meas = meas.replace(";", "\t") | |
143 | - meas = meas.replace("+", "") | |
133 | + try: | |
134 | + try: | |
135 | + #epoch time | |
136 | + epoch = time.time() | |
137 | + #MJD time | |
138 | + mjd = epoch / 86400.0 + 40587 | |
139 | + # Meas values | |
140 | + meas = instrument.getValue() | |
141 | + meas = meas.replace(",", "\t") | |
142 | + meas = meas.replace(";", "\t") | |
143 | + meas = meas.replace("+", "") | |
144 | 144 | |
145 | - string = "%f\t%f\t%s" % (epoch, mjd, meas) | |
146 | - data_file.write(string) # Write in a file | |
147 | - print(string) | |
145 | + string = "%f\t%f\t%s" % (epoch, mjd, meas) | |
146 | + data_file.write(string) # Write in a file | |
147 | + print(string) | |
148 | 148 | |
149 | - # Sleep until sampletime | |
150 | - time.sleep(samplingtime - (time.time() - tic)) | |
149 | + # Sleep until sampletime | |
150 | + time.sleep(samplingtime - (time.time() - tic)) | |
151 | 151 | |
152 | - except Exception as ex: | |
153 | - print 'Exception during controler data reading: ' + str(ex) | |
152 | + except Exception as ex: | |
153 | + print 'Exception during controler data reading: ' + str(ex) | |
154 | 154 | |
155 | - except KeyboardInterrupt: | |
156 | - print '\n --> Disconnected' | |
157 | - instrument.disconnect() | |
158 | - data_file.close() | |
155 | + except KeyboardInterrupt: | |
156 | + print '\n --> Disconnected' | |
157 | + instrument.disconnect() | |
158 | + data_file.close() | |
159 | 159 | |
160 | - # To stop the loop in a clean way | |
161 | - break | |
160 | + # To stop the loop in a clean way | |
161 | + break | |
162 | 162 | |
163 | 163 | #============================================================================== |
164 | 164 | |
165 | 165 | def main(): |
166 | - """ | |
167 | - Main script | |
168 | - """ | |
169 | - # Parse command line | |
170 | - args = parse() | |
171 | - # path | |
172 | - path = args.path | |
173 | - # Sampling time | |
174 | - samplingtime=float(args.samplingtime) | |
175 | - # File duration | |
176 | - fileduration=int(args.fileduration) | |
177 | - # Instrument to log | |
178 | - instLog = args.instLog | |
179 | - # instrument adress | |
180 | - adress = args.adress | |
181 | - # val type | |
182 | - vtype = args.vtype | |
166 | + """ | |
167 | + Main script | |
168 | + """ | |
169 | + # Parse command line | |
170 | + args = parse() | |
171 | + # path | |
172 | + path = args.path | |
173 | + # Sampling time | |
174 | + samplingtime=float(args.samplingtime) | |
175 | + # File duration | |
176 | + fileduration=int(args.fileduration) | |
177 | + # Instrument to log | |
178 | + instLog = args.instLog | |
179 | + # instrument adress | |
180 | + adress = args.adress | |
181 | + # val type | |
182 | + vtype = args.vtype | |
183 | 183 | |
184 | - try: | |
185 | - if args.list: | |
186 | - print('\nInstruments:') | |
187 | - for name, obj in inspect.getmembers(instruments): | |
188 | - if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | |
189 | - print('\n' + name) | |
190 | - exec('print("\t" + instruments.%s.ALL_VAL_TYPE)'%name) | |
184 | + try: | |
185 | + if args.list: | |
186 | + print('\nInstruments:') | |
187 | + for name, obj in inspect.getmembers(instruments): | |
188 | + if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | |
189 | + print('\n' + name) | |
190 | + exec('print("\t" + instruments.%s.ALL_VAL_TYPE)'%name) | |
191 | 191 | |
192 | - else: | |
193 | - if instLog == None: | |
194 | - raise Exception('No instrument selected !') | |
192 | + else: | |
193 | + if instLog == None: | |
194 | + raise Exception('No instrument selected !') | |
195 | 195 | |
196 | - if adress == None and vtype == None: | |
197 | - exec('myInstrument = instruments.%s.%s()'%(instLog, instLog)) | |
198 | - elif adress == None and vtype != None: | |
199 | - exec('myInstrument = instruments.%s.%s(vtype="%s")'%(instLog, instLog, vtype)) | |
200 | - elif adress != None and vtype != None: | |
201 | - exec('myInstrument = instruments.%s.%s(adress="%s", vtype="%s")'%(instLog, instLog, adress, vtype)) | |
202 | - acq_routine(myInstrument, path, samplingtime, fileduration) | |
196 | + if adress == None and vtype == None: | |
197 | + exec('myInstrument = instruments.%s.%s()'%(instLog, instLog)) | |
198 | + elif adress == None and vtype != None: | |
199 | + exec('myInstrument = instruments.%s.%s(vtype="%s")'%(instLog, instLog, vtype)) | |
200 | + elif adress != None and vtype != None: | |
201 | + exec('myInstrument = instruments.%s.%s(adress="%s", vtype="%s")'%(instLog, instLog, adress, vtype)) | |
202 | + acq_routine(myInstrument, path, samplingtime, fileduration) | |
203 | 203 | |
204 | - except Exception as ex: | |
205 | - print 'Oops: '+str(ex) | |
204 | + except Exception as ex: | |
205 | + print 'Oops: '+str(ex) | |
206 | 206 | |
207 | 207 | #============================================================================== |
208 | 208 | |
209 | 209 | if __name__ == "__main__": |
210 | - main() | |
210 | + main() |
instruments/AG34461A.py
... | ... | @@ -8,79 +8,79 @@ |
8 | 8 | #============================================================================== |
9 | 9 | |
10 | 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 | |
11 | + def __init__(self, adress="192.168.0.61", vtype="DCV"): | |
12 | + self.adress = adress | |
13 | + self.port = 5025 | |
14 | + self.vtype = vtype | |
15 | 15 | |
16 | - def model(self): | |
17 | - self.send("*IDN?") | |
18 | - return self.read() | |
16 | + def model(self): | |
17 | + self.send("*IDN?") | |
18 | + return self.read() | |
19 | 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') | |
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 | 29 | |
30 | - print(self.model()) | |
30 | + print(self.model()) | |
31 | 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 | |
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 | 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 | |
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 | 59 | |
60 | - def getValue(self): | |
61 | - self.send("READ?") | |
62 | - return self.read() | |
60 | + def getValue(self): | |
61 | + self.send("READ?") | |
62 | + return self.read() | |
63 | 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) | |
73 | - for j in range (0, list_size): | |
74 | - nb_data = nb_data+nb_data_list[j] | |
75 | - return nb_data | |
76 | - except socket.timeout: | |
77 | - print "Socket timeout error when reading." | |
78 | - raise | |
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) | |
73 | + for j in range (0, list_size): | |
74 | + nb_data = nb_data+nb_data_list[j] | |
75 | + return nb_data | |
76 | + except socket.timeout: | |
77 | + print "Socket timeout error when reading." | |
78 | + raise | |
79 | 79 | |
80 | - def disconnect(self): | |
81 | - self.send('*RST') | |
82 | - self.sock.close() | |
80 | + def disconnect(self): | |
81 | + self.send('*RST') | |
82 | + self.sock.close() | |
83 | 83 | |
84 | - def send(self, command): | |
85 | - self.sock.send("%s\n"%command) | |
84 | + def send(self, command): | |
85 | + self.sock.send("%s\n"%command) |
instruments/AG34972A.py
... | ... | @@ -8,79 +8,79 @@ |
8 | 8 | #============================================================================== |
9 | 9 | |
10 | 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 | |
11 | + def __init__(self, adress="192.168.0.72", vtype="DCV"): | |
12 | + self.adress = adress | |
13 | + self.port = 5025 | |
14 | + self.vtype = vtype | |
15 | 15 | |
16 | - def model(self): | |
17 | - self.send("*IDN?") | |
18 | - return self.read() | |
16 | + def model(self): | |
17 | + self.send("*IDN?") | |
18 | + return self.read() | |
19 | 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') | |
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 | 29 | |
30 | - print(self.model()) | |
30 | + print(self.model()) | |
31 | 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 | |
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 | 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 | |
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 | 59 | |
60 | - def getValue(self): | |
61 | - self.send("MEAS? AUTO,DEF,(@102:103)") | |
62 | - return self.read() | |
60 | + def getValue(self): | |
61 | + self.send("MEAS? AUTO,DEF,(@102:103)") | |
62 | + return self.read() | |
63 | 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) | |
73 | - for j in range (0, list_size): | |
74 | - nb_data = nb_data+nb_data_list[j] | |
75 | - return nb_data | |
76 | - except socket.timeout: | |
77 | - print "Socket timeout error when reading." | |
78 | - raise | |
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) | |
73 | + for j in range (0, list_size): | |
74 | + nb_data = nb_data+nb_data_list[j] | |
75 | + return nb_data | |
76 | + except socket.timeout: | |
77 | + print "Socket timeout error when reading." | |
78 | + raise | |
79 | 79 | |
80 | - def disconnect(self): | |
81 | - self.send('*RST') | |
82 | - self.sock.close() | |
80 | + def disconnect(self): | |
81 | + self.send('*RST') | |
82 | + self.sock.close() | |
83 | 83 | |
84 | - def send(self, command): | |
85 | - self.sock.send("%s\n"%command) | |
84 | + def send(self, command): | |
85 | + self.sock.send("%s\n"%command) |
instruments/LS350.py
... | ... | @@ -8,74 +8,74 @@ |
8 | 8 | #============================================================================== |
9 | 9 | |
10 | 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 | |
11 | + def __init__(self, adress="192.168.0.12", vtype="TEMP"): | |
12 | + self.adress = adress | |
13 | + self.port = 7777 | |
14 | + self.vtype = vtype | |
15 | 15 | |
16 | - def model(self): | |
17 | - self.send("*IDN?") | |
18 | - return self.read() | |
16 | + def model(self): | |
17 | + self.send("*IDN?") | |
18 | + return self.read() | |
19 | 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') | |
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 | 29 | |
30 | - print(self.model()) | |
30 | + print(self.model()) | |
31 | 31 | |
32 | - if self.vtype == "TEMP": | |
33 | - 1 | |
34 | - elif self.vtype == "RES": | |
35 | - 1 | |
36 | - else: | |
37 | - print("Wrong -v argument") | |
38 | - raise | |
32 | + if self.vtype == "TEMP": | |
33 | + 1 | |
34 | + elif self.vtype == "RES": | |
35 | + 1 | |
36 | + else: | |
37 | + print("Wrong -v argument") | |
38 | + raise | |
39 | 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 | |
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 | 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() | |
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 | 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) | |
68 | - for j in range (0, list_size): | |
69 | - nb_data = nb_data+nb_data_list[j] | |
70 | - return nb_data | |
71 | - except socket.timeout: | |
72 | - print "Socket timeout error when reading." | |
73 | - raise | |
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) | |
68 | + for j in range (0, list_size): | |
69 | + nb_data = nb_data+nb_data_list[j] | |
70 | + return nb_data | |
71 | + except socket.timeout: | |
72 | + print "Socket timeout error when reading." | |
73 | + raise | |
74 | 74 | |
75 | - def disconnect(self): | |
76 | - self.send('MODE0') | |
77 | - self.sock.close() | |
75 | + def disconnect(self): | |
76 | + self.send('MODE0') | |
77 | + self.sock.close() | |
78 | 78 | |
79 | - def send(self, command): | |
80 | - self.sock.send("%s\n"%command) | |
79 | + def send(self, command): | |
80 | + self.sock.send("%s\n"%command) |
instruments/PM100D.py
... | ... | @@ -8,42 +8,42 @@ |
8 | 8 | #============================================================================== |
9 | 9 | |
10 | 10 | class PM100D(abstract_instrument): |
11 | - def __init__(self, adress="/dev/usbtmc0", vtype="PWR"): | |
12 | - self.adress = adress | |
13 | - self.vtype = vtype | |
11 | + def __init__(self, adress="/dev/usbtmc0", vtype="PWR"): | |
12 | + self.adress = adress | |
13 | + self.vtype = vtype | |
14 | 14 | |
15 | - def model(self): | |
16 | - self.send("*IDN?") | |
17 | - return self.read() | |
15 | + def model(self): | |
16 | + self.send("*IDN?") | |
17 | + return self.read() | |
18 | 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') | |
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 | 24 | |
25 | - print(self.model()) | |
25 | + print(self.model()) | |
26 | 26 | |
27 | - if self.vtype == "PWR": | |
28 | - 1 | |
29 | - else: | |
30 | - print("Wrong -v argument") | |
31 | - raise | |
27 | + if self.vtype == "PWR": | |
28 | + 1 | |
29 | + else: | |
30 | + print("Wrong -v argument") | |
31 | + raise | |
32 | 32 | |
33 | - except Exception as er: | |
34 | - print("Unexpected error during connection: " + str(er)) | |
35 | - raise | |
33 | + except Exception as er: | |
34 | + print("Unexpected error during connection: " + str(er)) | |
35 | + raise | |
36 | 36 | |
37 | - def getValue(self): | |
38 | - self.send("READ?") | |
39 | - return self.read() | |
37 | + def getValue(self): | |
38 | + self.send("READ?") | |
39 | + return self.read() | |
40 | 40 | |
41 | - def read(self): | |
42 | - return os.read(self.FILE, 300) | |
41 | + def read(self): | |
42 | + return os.read(self.FILE, 300) | |
43 | 43 | |
44 | - def disconnect(self): | |
45 | - self.send('*RST') | |
44 | + def disconnect(self): | |
45 | + self.send('*RST') | |
46 | 46 | |
47 | - def send(self, command): | |
48 | - os.write(self.FILE, command) | |
47 | + def send(self, command): | |
48 | + os.write(self.FILE, command) |
instruments/T7Pro.py
... | ... | @@ -9,148 +9,148 @@ |
9 | 9 | #============================================================================== |
10 | 10 | |
11 | 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 | - ] | |
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 | 22 | |
23 | - def model(self): | |
24 | - return 'T7Pro' | |
23 | + def model(self): | |
24 | + return 'T7Pro' | |
25 | 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') | |
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 | 32 | |
33 | - print(self.model()) | |
33 | + print(self.model()) | |
34 | 34 | |
35 | - if self.vtype == "TEMP": | |
36 | - 1 | |
37 | - elif self.vtype == "RES": | |
38 | - 1 | |
39 | - else: | |
40 | - print("Wrong -v argument") | |
41 | - raise | |
35 | + if self.vtype == "TEMP": | |
36 | + 1 | |
37 | + elif self.vtype == "RES": | |
38 | + 1 | |
39 | + else: | |
40 | + print("Wrong -v argument") | |
41 | + raise | |
42 | 42 | |
43 | - except Exception as er: | |
44 | - print("Unexpected error during connection: " + str(er)) | |
45 | - raise | |
43 | + except Exception as er: | |
44 | + print("Unexpected error during connection: " + str(er)) | |
45 | + raise | |
46 | 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] | |
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 | 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 = '' | |
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 | 66 | |
67 | - return string | |
67 | + return string | |
68 | 68 | |
69 | - def read(self, names): | |
70 | - return ljm.eReadNames(self.handle, len(names), names) | |
69 | + def read(self, names): | |
70 | + return ljm.eReadNames(self.handle, len(names), names) | |
71 | 71 | |
72 | - def disconnect(self): | |
73 | - ljm.close(self.handle) | |
72 | + def disconnect(self): | |
73 | + ljm.close(self.handle) | |
74 | 74 | |
75 | - def send(self, command): | |
76 | - pass | |
75 | + def send(self, command): | |
76 | + pass | |
77 | 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])) | |
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 | 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: | |
138 | - K = [3.4597, 5.2422, 2.4169] | |
139 | - if sensor==100: | |
140 | - K = [0.003850] | |
141 | - return self.res2temp(K, res) | |
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: | |
138 | + K = [3.4597, 5.2422, 2.4169] | |
139 | + if sensor==100: | |
140 | + K = [0.003850] | |
141 | + return self.res2temp(K, res) | |
142 | 142 | |
143 | - def res2temp(K, res): | |
144 | - temp = 0 | |
145 | - tmp = 1000./res | |
146 | - if len(K)==7: | |
147 | - for i in range(len(K)): | |
148 | - temp += K[i]*tmp**i | |
149 | - if len(K)==3: | |
150 | - for i in range(len(K)): | |
151 | - temp += K[i]*numpy.log10(tmp)**(2-i) | |
152 | - temp = 10**temp | |
153 | - if len(K)==1: | |
154 | - temp = (res/100.-1)/K[0]+273.15 | |
155 | - return temp | |
143 | + def res2temp(K, res): | |
144 | + temp = 0 | |
145 | + tmp = 1000./res | |
146 | + if len(K)==7: | |
147 | + for i in range(len(K)): | |
148 | + temp += K[i]*tmp**i | |
149 | + if len(K)==3: | |
150 | + for i in range(len(K)): | |
151 | + temp += K[i]*numpy.log10(tmp)**(2-i) | |
152 | + temp = 10**temp | |
153 | + if len(K)==1: | |
154 | + temp = (res/100.-1)/K[0]+273.15 | |
155 | + return temp |
instruments/__init__.py
... | ... | @@ -2,9 +2,9 @@ |
2 | 2 | from os.path import dirname |
3 | 3 | |
4 | 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()) | |
5 | + if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': | |
6 | + continue | |
7 | + __import__(module[:-3], locals(), globals()) | |
8 | 8 | |
9 | 9 | del module, listdir, dirname |
instruments/abstract_instrument.py
1 | 1 | import abc |
2 | 2 | |
3 | 3 | class abstract_instrument(object): |
4 | - __metaclass__ = abc.ABCMeta | |
4 | + __metaclass__ = abc.ABCMeta | |
5 | 5 | |
6 | - @abc.abstractmethod | |
7 | - def __init__(self, adress, vtype): | |
8 | - """Build the class""" | |
9 | - return | |
6 | + @abc.abstractmethod | |
7 | + def __init__(self, adress, vtype): | |
8 | + """Build the class""" | |
9 | + return | |
10 | 10 | |
11 | - @abc.abstractmethod | |
12 | - def model(self): | |
13 | - """return the instrument model""" | |
14 | - return | |
11 | + @abc.abstractmethod | |
12 | + def model(self): | |
13 | + """return the instrument model""" | |
14 | + return | |
15 | 15 | |
16 | - @abc.abstractmethod | |
17 | - def connect(self): | |
18 | - """Create a connection with the instrument""" | |
19 | - return | |
16 | + @abc.abstractmethod | |
17 | + def connect(self): | |
18 | + """Create a connection with the instrument""" | |
19 | + return | |
20 | 20 | |
21 | - @abc.abstractmethod | |
22 | - def disconnect(self): | |
23 | - """Disconnect the instrument""" | |
24 | - return | |
21 | + @abc.abstractmethod | |
22 | + def disconnect(self): | |
23 | + """Disconnect the instrument""" | |
24 | + return | |
25 | 25 | |
26 | - @abc.abstractmethod | |
27 | - def read(self): | |
28 | - """read the buffer""" | |
29 | - return | |
26 | + @abc.abstractmethod | |
27 | + def read(self): | |
28 | + """read the buffer""" | |
29 | + return | |
30 | 30 | |
31 | - @abc.abstractmethod | |
32 | - def send(self): | |
33 | - """send a command""" | |
34 | - return | |
31 | + @abc.abstractmethod | |
32 | + def send(self): | |
33 | + """send a command""" | |
34 | + return | |
35 | 35 | |
36 | - @abc.abstractmethod | |
37 | - def getValue(self): | |
38 | - """return the value of measurment""" | |
39 | - return | |
36 | + @abc.abstractmethod | |
37 | + def getValue(self): | |
38 | + """return the value of measurment""" | |
39 | + return |
instruments/testDevice.py
... | ... | @@ -8,49 +8,49 @@ |
8 | 8 | #============================================================================== |
9 | 9 | |
10 | 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 | |
11 | + def __init__(self, adress="123.456.789.123", vtype="DCV"): | |
12 | + self.adress = adress | |
13 | + self.port = 9999 | |
14 | + self.vtype = vtype | |
15 | 15 | |
16 | - def model(self): | |
17 | - return 'test device' | |
16 | + def model(self): | |
17 | + return 'test device' | |
18 | 18 | |
19 | - def connect(self): | |
20 | - print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
21 | - time.sleep(1) | |
22 | - print(' --> Ok') | |
19 | + def connect(self): | |
20 | + print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
21 | + time.sleep(1) | |
22 | + print(' --> Ok') | |
23 | 23 | |
24 | - print(self.model()) | |
24 | + print(self.model()) | |
25 | 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 | |
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 | 43 | |
44 | - def getValue(self): | |
45 | - return str(numpy.random.rand()) | |
44 | + def getValue(self): | |
45 | + return str(numpy.random.rand()) | |
46 | 46 | |
47 | - def read(self): | |
48 | - print('reading') | |
49 | - return 1 | |
47 | + def read(self): | |
48 | + print('reading') | |
49 | + return 1 | |
50 | 50 | |
51 | - def disconnect(self): | |
52 | - print('reset') | |
51 | + def disconnect(self): | |
52 | + print('reset') | |
53 | 53 | |
54 | - def send(self, command): | |
55 | - print('send %s'%command) | |
54 | + def send(self, command): | |
55 | + print('send %s'%command) |