Commit 10016888cd0b79903c0d05c74bbae4d74a5d49ad
1 parent
befe737ed5
Exists in
master
replace 4 spaces by tabs
Showing 9 changed files with 624 additions and 624 deletions Inline Diff
datalogger.py
#!/usr/bin/env python | 1 | 1 | #!/usr/bin/env python | |
2 | 2 | |||
# -*- coding: utf-8 -*- | 3 | 3 | # -*- coding: utf-8 -*- | |
4 | 4 | |||
import argparse, time, os, instruments, inspect | 5 | 5 | import argparse, time, os, instruments, inspect | |
6 | 6 | |||
#============================================================================== | 7 | 7 | #============================================================================== | |
8 | 8 | |||
# Path | 9 | 9 | # Path | |
PATH = os.getcwd() | 10 | 10 | PATH = os.getcwd() | |
# Sampling time acquisition | 11 | 11 | # Sampling time acquisition | |
SAMPLING_TIME = 1 | 12 | 12 | SAMPLING_TIME = 1 | |
# File duration | 13 | 13 | # File duration | |
FILE_DURATION = 3600*24 | 14 | 14 | FILE_DURATION = 3600*24 | |
# Default instrument | 15 | 15 | # Default instrument | |
INSTRUMENT = None | 16 | 16 | INSTRUMENT = None | |
# Default instrument adress | 17 | 17 | # Default instrument adress | |
ADRESS = None | 18 | 18 | ADRESS = None | |
#Default val type | 19 | 19 | #Default val type | |
VAL_TYPE = None | 20 | 20 | VAL_TYPE = None | |
21 | 21 | |||
#============================================================================== | 22 | 22 | #============================================================================== | |
23 | 23 | |||
def parse(): | 24 | 24 | def parse(): | |
""" | 25 | 25 | """ | |
Specific parsing procedure for transfering data from any abstract instrument. | 26 | 26 | Specific parsing procedure for transfering data from any abstract instrument. | |
:returns: populated namespace (parser) | 27 | 27 | :returns: populated namespace (parser) | |
""" | 28 | 28 | """ | |
29 | 29 | |||
parser = argparse.ArgumentParser(description = 'Acquire data from INSTRUMENT', | 30 | 30 | parser = argparse.ArgumentParser(description = 'Acquire data from INSTRUMENT', | |
epilog = 'Example: \'./datalogger.py -i myInstrument -st 10\' logs myInstrument every 10 seconds to output file YYYYMMDD-HHMMSS-INSTRUMENT.dat') | 31 | 31 | epilog = 'Example: \'./datalogger.py -i myInstrument -st 10\' logs myInstrument every 10 seconds to output file YYYYMMDD-HHMMSS-INSTRUMENT.dat') | |
32 | 32 | |||
parser.add_argument('-l', | 33 | 33 | parser.add_argument('-l', | |
action='store_true', | 34 | 34 | action='store_true', | |
dest='list', | 35 | 35 | dest='list', | |
default=False, | 36 | 36 | default=False, | |
help='List all available instruments') | 37 | 37 | help='List all available instruments') | |
38 | 38 | |||
parser.add_argument('-I', | 39 | 39 | parser.add_argument('-I', | |
action='store', | 40 | 40 | action='store', | |
dest='instLog', | 41 | 41 | dest='instLog', | |
default=INSTRUMENT, | 42 | 42 | default=INSTRUMENT, | |
help='Instrument to log (default '+str(INSTRUMENT)+')') | 43 | 43 | help='Instrument to log (default '+str(INSTRUMENT)+')') | |
44 | 44 | |||
parser.add_argument('-ip', | 45 | 45 | parser.add_argument('-ip', | |
action='store', | 46 | 46 | action='store', | |
dest='adress', | 47 | 47 | dest='adress', | |
default=ADRESS, | 48 | 48 | default=ADRESS, | |
help='Adress of instrument (IP, USB...) (default '+str(ADRESS)+')') | 49 | 49 | help='Adress of instrument (IP, USB...) (default '+str(ADRESS)+')') | |
50 | 50 | |||
parser.add_argument('-v', | 51 | 51 | parser.add_argument('-v', | |
action='store', | 52 | 52 | action='store', | |
dest='vtype', | 53 | 53 | dest='vtype', | |
default=VAL_TYPE, | 54 | 54 | default=VAL_TYPE, | |
help='Value type to measure (default '+str(VAL_TYPE)+')') | 55 | 55 | help='Value type to measure (default '+str(VAL_TYPE)+')') | |
56 | 56 | |||
parser.add_argument('-st', | 57 | 57 | parser.add_argument('-st', | |
action='store', | 58 | 58 | action='store', | |
dest='samplingtime', | 59 | 59 | dest='samplingtime', | |
default=SAMPLING_TIME, | 60 | 60 | default=SAMPLING_TIME, | |
help='Sampling time acquistion (default '+str(SAMPLING_TIME)+' second)') | 61 | 61 | help='Sampling time acquistion (default '+str(SAMPLING_TIME)+' second)') | |
62 | 62 | |||
parser.add_argument('-fd', | 63 | 63 | parser.add_argument('-fd', | |
action='store', | 64 | 64 | action='store', | |
dest='fileduration', | 65 | 65 | dest='fileduration', | |
default=FILE_DURATION, | 66 | 66 | default=FILE_DURATION, | |
help='File duration (infinite : \'-fd -1\') (default '+str(FILE_DURATION)+' second)') | 67 | 67 | help='File duration (infinite : \'-fd -1\') (default '+str(FILE_DURATION)+' second)') | |
68 | 68 | |||
parser.add_argument('-p', | 69 | 69 | parser.add_argument('-p', | |
action='store', | 70 | 70 | action='store', | |
dest='path', | 71 | 71 | dest='path', | |
default=PATH, | 72 | 72 | default=PATH, | |
help='Absolute path (default '+PATH+')') | 73 | 73 | help='Absolute path (default '+PATH+')') | |
74 | 74 | |||
args = parser.parse_args() | 75 | 75 | args = parser.parse_args() | |
return args | 76 | 76 | return args | |
77 | 77 | |||
#============================================================================== | 78 | 78 | #============================================================================== | |
79 | 79 | |||
def acq_routine(instrument, path, samplingtime, fileduration): | 80 | 80 | def acq_routine(instrument, path, samplingtime, fileduration): | |
instrument.connect() | 81 | 81 | instrument.connect() | |
t0 = time.time() | 82 | 82 | t0 = time.time() | |
filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | 83 | 83 | filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | |
print('Opening %s' %filename) | 84 | 84 | print('Opening %s' %filename) | |
try: | 85 | 85 | try: | |
year = time.strftime("%Y", time.gmtime(t0)) | 86 | 86 | year = time.strftime("%Y", time.gmtime(t0)) | |
month = time.strftime("%Y-%m", time.gmtime(t0)) | 87 | 87 | month = time.strftime("%Y-%m", time.gmtime(t0)) | |
os.chdir(path + '/' + year + '/' + month) | 88 | 88 | os.chdir(path + '/' + year + '/' + month) | |
except: | 89 | 89 | except: | |
try: | 90 | 90 | try: | |
os.chdir(path + '/' + year) | 91 | 91 | os.chdir(path + '/' + year) | |
os.mkdir(month) | 92 | 92 | os.mkdir(month) | |
os.chdir(path + '/' + year + '/' + month) | 93 | 93 | os.chdir(path + '/' + year + '/' + month) | |
except: | 94 | 94 | except: | |
os.chdir(path) | 95 | 95 | os.chdir(path) | |
os.mkdir(year) | 96 | 96 | os.mkdir(year) | |
os.chdir(path + '/' + year) | 97 | 97 | os.chdir(path + '/' + year) | |
os.mkdir(month) | 98 | 98 | os.mkdir(month) | |
os.chdir(path + '/' + year + '/' + month) | 99 | 99 | os.chdir(path + '/' + year + '/' + month) | |
100 | 100 | |||
data_file = open(filename, 'wr', 0) | 101 | 101 | data_file = open(filename, 'wr', 0) | |
102 | 102 | |||
# Infinite loop | 103 | 103 | # Infinite loop | |
while True: | 104 | 104 | while True: | |
# tic | 105 | 105 | # tic | |
tic = time.time() | 106 | 106 | tic = time.time() | |
107 | 107 | |||
if time.time() - t0 >= fileduration: | 108 | 108 | if time.time() - t0 >= fileduration: | |
t0 = time.time() | 109 | 109 | t0 = time.time() | |
print('Closing %s\n' %filename) | 110 | 110 | print('Closing %s\n' %filename) | |
data_file.close() | 111 | 111 | data_file.close() | |
112 | 112 | |||
try: | 113 | 113 | try: | |
year = time.strftime("%Y", time.gmtime(t0)) | 114 | 114 | year = time.strftime("%Y", time.gmtime(t0)) | |
month = time.strftime("%Y-%m", time.gmtime(t0)) | 115 | 115 | month = time.strftime("%Y-%m", time.gmtime(t0)) | |
os.chdir(path + '/' + year + '/' + month) | 116 | 116 | os.chdir(path + '/' + year + '/' + month) | |
except: | 117 | 117 | except: | |
try: | 118 | 118 | try: | |
os.chdir(path + '/' + year) | 119 | 119 | os.chdir(path + '/' + year) | |
os.mkdir(month) | 120 | 120 | os.mkdir(month) | |
os.chdir(path + '/' + year + '/' + month) | 121 | 121 | os.chdir(path + '/' + year + '/' + month) | |
except: | 122 | 122 | except: | |
os.chdir(path) | 123 | 123 | os.chdir(path) | |
os.mkdir(year) | 124 | 124 | os.mkdir(year) | |
os.chdir(path + '/' + year) | 125 | 125 | os.chdir(path + '/' + year) | |
os.mkdir(month) | 126 | 126 | os.mkdir(month) | |
os.chdir(path + '/' + year + '/' + month) | 127 | 127 | os.chdir(path + '/' + year + '/' + month) | |
128 | 128 | |||
filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | 129 | 129 | filename = time.strftime("%Y%m%d-%H%M%S", time.gmtime(t0)) + '-' + instrument.model() + '.dat' | |
print('Opening %s\n' %filename) | 130 | 130 | print('Opening %s\n' %filename) | |
data_file = open(filename, 'wr', 0) | 131 | 131 | data_file = open(filename, 'wr', 0) | |
132 | 132 | |||
try: | 133 | 133 | try: | |
try: | 134 | 134 | try: | |
#epoch time | 135 | 135 | #epoch time | |
epoch = time.time() | 136 | 136 | epoch = time.time() | |
#MJD time | 137 | 137 | #MJD time | |
mjd = epoch / 86400.0 + 40587 | 138 | 138 | mjd = epoch / 86400.0 + 40587 | |
# Meas values | 139 | 139 | # Meas values | |
meas = instrument.getValue() | 140 | 140 | meas = instrument.getValue() | |
meas = meas.replace(",", "\t") | 141 | 141 | meas = meas.replace(",", "\t") | |
meas = meas.replace(";", "\t") | 142 | 142 | meas = meas.replace(";", "\t") | |
meas = meas.replace("+", "") | 143 | 143 | meas = meas.replace("+", "") | |
144 | 144 | |||
string = "%f\t%f\t%s" % (epoch, mjd, meas) | 145 | 145 | string = "%f\t%f\t%s" % (epoch, mjd, meas) | |
data_file.write(string) # Write in a file | 146 | 146 | data_file.write(string) # Write in a file | |
print(string) | 147 | 147 | print(string) | |
148 | 148 | |||
# Sleep until sampletime | 149 | 149 | # Sleep until sampletime | |
time.sleep(samplingtime - (time.time() - tic)) | 150 | 150 | time.sleep(samplingtime - (time.time() - tic)) | |
151 | 151 | |||
except Exception as ex: | 152 | 152 | except Exception as ex: | |
print 'Exception during controler data reading: ' + str(ex) | 153 | 153 | print 'Exception during controler data reading: ' + str(ex) | |
154 | 154 | |||
except KeyboardInterrupt: | 155 | 155 | except KeyboardInterrupt: | |
print '\n --> Disconnected' | 156 | 156 | print '\n --> Disconnected' | |
instrument.disconnect() | 157 | 157 | instrument.disconnect() | |
data_file.close() | 158 | 158 | data_file.close() | |
159 | 159 | |||
# To stop the loop in a clean way | 160 | 160 | # To stop the loop in a clean way | |
break | 161 | 161 | break | |
162 | 162 | |||
#============================================================================== | 163 | 163 | #============================================================================== | |
164 | 164 | |||
def main(): | 165 | 165 | def main(): | |
""" | 166 | 166 | """ | |
Main script | 167 | 167 | Main script | |
""" | 168 | 168 | """ | |
# Parse command line | 169 | 169 | # Parse command line | |
args = parse() | 170 | 170 | args = parse() | |
# path | 171 | 171 | # path | |
path = args.path | 172 | 172 | path = args.path | |
# Sampling time | 173 | 173 | # Sampling time | |
samplingtime=float(args.samplingtime) | 174 | 174 | samplingtime=float(args.samplingtime) | |
# File duration | 175 | 175 | # File duration | |
fileduration=int(args.fileduration) | 176 | 176 | fileduration=int(args.fileduration) | |
# Instrument to log | 177 | 177 | # Instrument to log | |
instLog = args.instLog | 178 | 178 | instLog = args.instLog | |
# instrument adress | 179 | 179 | # instrument adress | |
adress = args.adress | 180 | 180 | adress = args.adress | |
# val type | 181 | 181 | # val type | |
vtype = args.vtype | 182 | 182 | vtype = args.vtype | |
183 | 183 | |||
try: | 184 | 184 | try: | |
if args.list: | 185 | 185 | if args.list: | |
print('\nInstruments:') | 186 | 186 | print('\nInstruments:') | |
for name, obj in inspect.getmembers(instruments): | 187 | 187 | for name, obj in inspect.getmembers(instruments): | |
if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | 188 | 188 | if inspect.ismodule(obj) and name.startswith('__') == False and name.startswith('abstract') == False: | |
print('\n' + name) | 189 | 189 | print('\n' + name) | |
exec('print("\t" + instruments.%s.ALL_VAL_TYPE)'%name) | 190 | 190 | exec('print("\t" + instruments.%s.ALL_VAL_TYPE)'%name) | |
191 | 191 | |||
else: | 192 | 192 | else: | |
if instLog == None: | 193 | 193 | if instLog == None: | |
raise Exception('No instrument selected !') | 194 | 194 | raise Exception('No instrument selected !') | |
195 | 195 | |||
if adress == None and vtype == None: | 196 | 196 | if adress == None and vtype == None: | |
exec('myInstrument = instruments.%s.%s()'%(instLog, instLog)) | 197 | 197 | exec('myInstrument = instruments.%s.%s()'%(instLog, instLog)) | |
elif adress == None and vtype != None: | 198 | 198 | elif adress == None and vtype != None: | |
exec('myInstrument = instruments.%s.%s(vtype="%s")'%(instLog, instLog, vtype)) | 199 | 199 | exec('myInstrument = instruments.%s.%s(vtype="%s")'%(instLog, instLog, vtype)) | |
elif adress != None and vtype != None: | 200 | 200 | elif adress != None and vtype != None: | |
exec('myInstrument = instruments.%s.%s(adress="%s", vtype="%s")'%(instLog, instLog, adress, vtype)) | 201 | 201 | exec('myInstrument = instruments.%s.%s(adress="%s", vtype="%s")'%(instLog, instLog, adress, vtype)) | |
acq_routine(myInstrument, path, samplingtime, fileduration) | 202 | 202 | acq_routine(myInstrument, path, samplingtime, fileduration) | |
203 | 203 | |||
except Exception as ex: | 204 | 204 | except Exception as ex: | |
print 'Oops: '+str(ex) | 205 | 205 | print 'Oops: '+str(ex) | |
206 | 206 | |||
#============================================================================== | 207 | 207 | #============================================================================== | |
208 | 208 | |||
if __name__ == "__main__": | 209 | 209 | if __name__ == "__main__": | |
main() | 210 | 210 | main() | |
211 | 211 | |||
instruments/AG34461A.py
from abstract_instrument import abstract_instrument | 1 | 1 | from abstract_instrument import abstract_instrument | |
import socket | 2 | 2 | import socket | |
3 | 3 | |||
#============================================================================== | 4 | 4 | #============================================================================== | |
5 | 5 | |||
ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | 6 | 6 | ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | |
7 | 7 | |||
#============================================================================== | 8 | 8 | #============================================================================== | |
9 | 9 | |||
class AG34461A(abstract_instrument): | 10 | 10 | class AG34461A(abstract_instrument): | |
def __init__(self, adress="192.168.0.61", vtype="DCV"): | 11 | 11 | def __init__(self, adress="192.168.0.61", vtype="DCV"): | |
self.adress = adress | 12 | 12 | self.adress = adress | |
self.port = 5025 | 13 | 13 | self.port = 5025 | |
self.vtype = vtype | 14 | 14 | self.vtype = vtype | |
15 | 15 | |||
def model(self): | 16 | 16 | def model(self): | |
self.send("*IDN?") | 17 | 17 | self.send("*IDN?") | |
return self.read() | 18 | 18 | return self.read() | |
19 | 19 | |||
def connect(self): | 20 | 20 | def connect(self): | |
try: | 21 | 21 | try: | |
print('Connecting to device @%s:%s...' %(self.adress, self.port)) | 22 | 22 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
self.sock = socket.socket(socket.AF_INET, | 23 | 23 | self.sock = socket.socket(socket.AF_INET, | |
socket.SOCK_STREAM, | 24 | 24 | socket.SOCK_STREAM, | |
socket.IPPROTO_TCP) | 25 | 25 | socket.IPPROTO_TCP) | |
self.sock.settimeout(10.0) # Don't hang around forever | 26 | 26 | self.sock.settimeout(10.0) # Don't hang around forever | |
self.sock.connect((self.adress, self.port)) | 27 | 27 | self.sock.connect((self.adress, self.port)) | |
print(' --> Ok') | 28 | 28 | print(' --> Ok') | |
29 | 29 | |||
print(self.model()) | 30 | 30 | print(self.model()) | |
31 | 31 | |||
if self.vtype == "DCV": | 32 | 32 | if self.vtype == "DCV": | |
self.send("CONF:VOLT:DC") | 33 | 33 | self.send("CONF:VOLT:DC") | |
elif self.vtype == "ACV": | 34 | 34 | elif self.vtype == "ACV": | |
self.send("CONF:VOLT:AC") | 35 | 35 | self.send("CONF:VOLT:AC") | |
elif self.vtype == "DCI": | 36 | 36 | elif self.vtype == "DCI": | |
self.send("CONF:CURR:DC") | 37 | 37 | self.send("CONF:CURR:DC") | |
elif self.vtype == "ACI": | 38 | 38 | elif self.vtype == "ACI": | |
self.send("CONF:CURR:AC") | 39 | 39 | self.send("CONF:CURR:AC") | |
elif self.vtype == "RES2W": | 40 | 40 | elif self.vtype == "RES2W": | |
self.send("CONF:RES") | 41 | 41 | self.send("CONF:RES") | |
elif self.vtype == "RES4W": | 42 | 42 | elif self.vtype == "RES4W": | |
self.send("CONF:FRES") | 43 | 43 | self.send("CONF:FRES") | |
elif self.vtype == "FREQ": | 44 | 44 | elif self.vtype == "FREQ": | |
self.send("CONF:FREQ") | 45 | 45 | self.send("CONF:FREQ") | |
else: | 46 | 46 | else: | |
print("Wrong -v argument") | 47 | 47 | print("Wrong -v argument") | |
raise | 48 | 48 | raise | |
49 | 49 | |||
except socket.timeout: | 50 | 50 | except socket.timeout: | |
print("Socket timeout error during connection.") | 51 | 51 | print("Socket timeout error during connection.") | |
raise | 52 | 52 | raise | |
except socket.error as er: | 53 | 53 | except socket.error as er: | |
print("Socket error during connection: " + str(er)) | 54 | 54 | print("Socket error during connection: " + str(er)) | |
raise | 55 | 55 | raise | |
except Exception as er: | 56 | 56 | except Exception as er: | |
print("Unexpected error during connection: " + str(er)) | 57 | 57 | print("Unexpected error during connection: " + str(er)) | |
raise | 58 | 58 | raise | |
59 | 59 | |||
def getValue(self): | 60 | 60 | def getValue(self): | |
self.send("READ?") | 61 | 61 | self.send("READ?") | |
return self.read() | 62 | 62 | return self.read() | |
63 | 63 | |||
def read(self): | 64 | 64 | def read(self): | |
ans = '' | 65 | 65 | ans = '' | |
nb_data_list = [] | 66 | 66 | nb_data_list = [] | |
nb_data = '' | 67 | 67 | nb_data = '' | |
try: | 68 | 68 | try: | |
while ans != '\n': | 69 | 69 | while ans != '\n': | |
ans = self.sock.recv(1) | 70 | 70 | ans = self.sock.recv(1) | |
nb_data_list.append(ans) # Return the number of data | 71 | 71 | nb_data_list.append(ans) # Return the number of data | |
list_size = len(nb_data_list) | 72 | 72 | list_size = len(nb_data_list) | |
for j in range (0, list_size): | 73 | 73 | for j in range (0, list_size): | |
nb_data = nb_data+nb_data_list[j] | 74 | 74 | nb_data = nb_data+nb_data_list[j] | |
return nb_data | 75 | 75 | return nb_data | |
except socket.timeout: | 76 | 76 | except socket.timeout: | |
print "Socket timeout error when reading." | 77 | 77 | print "Socket timeout error when reading." | |
raise | 78 | 78 | raise | |
79 | 79 | |||
def disconnect(self): | 80 | 80 | def disconnect(self): | |
self.send('*RST') | 81 | 81 | self.send('*RST') | |
self.sock.close() | 82 | 82 | self.sock.close() | |
83 | 83 | |||
def send(self, command): | 84 | 84 | def send(self, command): | |
self.sock.send("%s\n"%command) | 85 | 85 | self.sock.send("%s\n"%command) | |
86 | 86 | |||
instruments/AG34972A.py
from abstract_instrument import abstract_instrument | 1 | 1 | from abstract_instrument import abstract_instrument | |
import socket | 2 | 2 | import socket | |
3 | 3 | |||
#============================================================================== | 4 | 4 | #============================================================================== | |
5 | 5 | |||
ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | 6 | 6 | ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | |
7 | 7 | |||
#============================================================================== | 8 | 8 | #============================================================================== | |
9 | 9 | |||
class AG34972A(abstract_instrument): | 10 | 10 | class AG34972A(abstract_instrument): | |
def __init__(self, adress="192.168.0.72", vtype="DCV"): | 11 | 11 | def __init__(self, adress="192.168.0.72", vtype="DCV"): | |
self.adress = adress | 12 | 12 | self.adress = adress | |
self.port = 5025 | 13 | 13 | self.port = 5025 | |
self.vtype = vtype | 14 | 14 | self.vtype = vtype | |
15 | 15 | |||
def model(self): | 16 | 16 | def model(self): | |
self.send("*IDN?") | 17 | 17 | self.send("*IDN?") | |
return self.read() | 18 | 18 | return self.read() | |
19 | 19 | |||
def connect(self): | 20 | 20 | def connect(self): | |
try: | 21 | 21 | try: | |
print('Connecting to device @%s:%s...' %(self.adress, self.port)) | 22 | 22 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
self.sock = socket.socket(socket.AF_INET, | 23 | 23 | self.sock = socket.socket(socket.AF_INET, | |
socket.SOCK_STREAM, | 24 | 24 | socket.SOCK_STREAM, | |
socket.IPPROTO_TCP) | 25 | 25 | socket.IPPROTO_TCP) | |
self.sock.settimeout(2.0) # Don't hang around forever | 26 | 26 | self.sock.settimeout(2.0) # Don't hang around forever | |
self.sock.connect((self.adress, self.port)) | 27 | 27 | self.sock.connect((self.adress, self.port)) | |
print(' --> Ok') | 28 | 28 | print(' --> Ok') | |
29 | 29 | |||
print(self.model()) | 30 | 30 | print(self.model()) | |
31 | 31 | |||
if self.vtype == "DCV": | 32 | 32 | if self.vtype == "DCV": | |
self.send("CONF:VOLT:DC (@102:103)") | 33 | 33 | self.send("CONF:VOLT:DC (@102:103)") | |
elif self.vtype == "ACV": | 34 | 34 | elif self.vtype == "ACV": | |
self.send("CONF:VOLT:AC (@102:103)") | 35 | 35 | self.send("CONF:VOLT:AC (@102:103)") | |
elif self.vtype == "DCI": | 36 | 36 | elif self.vtype == "DCI": | |
self.send("CONF:CURR:DC (@102:103)") | 37 | 37 | self.send("CONF:CURR:DC (@102:103)") | |
elif self.vtype == "ACI": | 38 | 38 | elif self.vtype == "ACI": | |
self.send("CONF:CURR:AC (@102:103)") | 39 | 39 | self.send("CONF:CURR:AC (@102:103)") | |
elif self.vtype == "RES2W": | 40 | 40 | elif self.vtype == "RES2W": | |
self.send("CONF:RES (@102:103)") | 41 | 41 | self.send("CONF:RES (@102:103)") | |
elif self.vtype == "RES4W": | 42 | 42 | elif self.vtype == "RES4W": | |
self.send("CONF:FRES (@102:103)") | 43 | 43 | self.send("CONF:FRES (@102:103)") | |
elif self.vtype == "FREQ": | 44 | 44 | elif self.vtype == "FREQ": | |
self.send("CONF:FREQ (@102:103)") | 45 | 45 | self.send("CONF:FREQ (@102:103)") | |
else: | 46 | 46 | else: | |
print("Wrong -v argument") | 47 | 47 | print("Wrong -v argument") | |
raise | 48 | 48 | raise | |
49 | 49 | |||
except socket.timeout: | 50 | 50 | except socket.timeout: | |
print("Socket timeout error during connection.") | 51 | 51 | print("Socket timeout error during connection.") | |
raise | 52 | 52 | raise | |
except socket.error as er: | 53 | 53 | except socket.error as er: | |
print("Socket error during connection: " + str(er)) | 54 | 54 | print("Socket error during connection: " + str(er)) | |
raise | 55 | 55 | raise | |
except Exception as er: | 56 | 56 | except Exception as er: | |
print("Unexpected error during connection: " + str(er)) | 57 | 57 | print("Unexpected error during connection: " + str(er)) | |
raise | 58 | 58 | raise | |
59 | 59 | |||
def getValue(self): | 60 | 60 | def getValue(self): | |
self.send("MEAS? AUTO,DEF,(@102:103)") | 61 | 61 | self.send("MEAS? AUTO,DEF,(@102:103)") | |
return self.read() | 62 | 62 | return self.read() | |
63 | 63 | |||
def read(self): | 64 | 64 | def read(self): | |
ans = '' | 65 | 65 | ans = '' | |
nb_data_list = [] | 66 | 66 | nb_data_list = [] | |
nb_data = '' | 67 | 67 | nb_data = '' | |
try: | 68 | 68 | try: | |
while ans != '\n': | 69 | 69 | while ans != '\n': | |
ans = self.sock.recv(1) | 70 | 70 | ans = self.sock.recv(1) | |
nb_data_list.append(ans) # Return the number of data | 71 | 71 | nb_data_list.append(ans) # Return the number of data | |
list_size = len(nb_data_list) | 72 | 72 | list_size = len(nb_data_list) | |
for j in range (0, list_size): | 73 | 73 | for j in range (0, list_size): | |
nb_data = nb_data+nb_data_list[j] | 74 | 74 | nb_data = nb_data+nb_data_list[j] | |
return nb_data | 75 | 75 | return nb_data | |
except socket.timeout: | 76 | 76 | except socket.timeout: | |
print "Socket timeout error when reading." | 77 | 77 | print "Socket timeout error when reading." | |
raise | 78 | 78 | raise | |
79 | 79 | |||
def disconnect(self): | 80 | 80 | def disconnect(self): | |
self.send('*RST') | 81 | 81 | self.send('*RST') | |
self.sock.close() | 82 | 82 | self.sock.close() | |
83 | 83 | |||
def send(self, command): | 84 | 84 | def send(self, command): | |
self.sock.send("%s\n"%command) | 85 | 85 | self.sock.send("%s\n"%command) | |
86 | 86 | |||
instruments/LS350.py
from abstract_instrument import abstract_instrument | 1 | 1 | from abstract_instrument import abstract_instrument | |
import socket | 2 | 2 | import socket | |
3 | 3 | |||
#============================================================================== | 4 | 4 | #============================================================================== | |
5 | 5 | |||
ALL_VAL_TYPE = "TEMP, RES" | 6 | 6 | ALL_VAL_TYPE = "TEMP, RES" | |
7 | 7 | |||
#============================================================================== | 8 | 8 | #============================================================================== | |
9 | 9 | |||
class LS350(abstract_instrument): | 10 | 10 | class LS350(abstract_instrument): | |
def __init__(self, adress="192.168.0.12", vtype="TEMP"): | 11 | 11 | def __init__(self, adress="192.168.0.12", vtype="TEMP"): | |
self.adress = adress | 12 | 12 | self.adress = adress | |
self.port = 7777 | 13 | 13 | self.port = 7777 | |
self.vtype = vtype | 14 | 14 | self.vtype = vtype | |
15 | 15 | |||
def model(self): | 16 | 16 | def model(self): | |
self.send("*IDN?") | 17 | 17 | self.send("*IDN?") | |
return self.read() | 18 | 18 | return self.read() | |
19 | 19 | |||
def connect(self): | 20 | 20 | def connect(self): | |
try: | 21 | 21 | try: | |
print('Connecting to device @%s:%s...' %(self.adress, self.port)) | 22 | 22 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
self.sock = socket.socket(socket.AF_INET, | 23 | 23 | self.sock = socket.socket(socket.AF_INET, | |
socket.SOCK_STREAM, | 24 | 24 | socket.SOCK_STREAM, | |
socket.IPPROTO_TCP) | 25 | 25 | socket.IPPROTO_TCP) | |
self.sock.settimeout(10.0) # Don't hang around forever | 26 | 26 | self.sock.settimeout(10.0) # Don't hang around forever | |
self.sock.connect((self.adress, self.port)) | 27 | 27 | self.sock.connect((self.adress, self.port)) | |
print(' --> Ok') | 28 | 28 | print(' --> Ok') | |
29 | 29 | |||
print(self.model()) | 30 | 30 | print(self.model()) | |
31 | 31 | |||
if self.vtype == "TEMP": | 32 | 32 | if self.vtype == "TEMP": | |
1 | 33 | 33 | 1 | |
elif self.vtype == "RES": | 34 | 34 | elif self.vtype == "RES": | |
1 | 35 | 35 | 1 | |
else: | 36 | 36 | else: | |
print("Wrong -v argument") | 37 | 37 | print("Wrong -v argument") | |
raise | 38 | 38 | raise | |
39 | 39 | |||
except socket.timeout: | 40 | 40 | except socket.timeout: | |
print("Socket timeout error during connection.") | 41 | 41 | print("Socket timeout error during connection.") | |
raise | 42 | 42 | raise | |
except socket.error as er: | 43 | 43 | except socket.error as er: | |
print("Socket error during connection: " + str(er)) | 44 | 44 | print("Socket error during connection: " + str(er)) | |
raise | 45 | 45 | raise | |
except Exception as er: | 46 | 46 | except Exception as er: | |
print("Unexpected error during connection: " + str(er)) | 47 | 47 | print("Unexpected error during connection: " + str(er)) | |
raise | 48 | 48 | raise | |
49 | 49 | |||
def getValue(self): | 50 | 50 | def getValue(self): | |
if self.vtype == 'TEMP': | 51 | 51 | if self.vtype == 'TEMP': | |
self.send('krdg? a;krdg? b;krdg? c;krdg? d') | 52 | 52 | self.send('krdg? a;krdg? b;krdg? c;krdg? d') | |
return self.read() | 53 | 53 | return self.read() | |
elif self.vtype == 'RES': | 54 | 54 | elif self.vtype == 'RES': | |
self.send('srdg? a;srdg? b;srdg? c;srdg? d') | 55 | 55 | self.send('srdg? a;srdg? b;srdg? c;srdg? d') | |
return self.read() | 56 | 56 | return self.read() | |
57 | 57 | |||
def read(self): | 58 | 58 | def read(self): | |
self.send("++read eoi") | 59 | 59 | self.send("++read eoi") | |
ans = '' | 60 | 60 | ans = '' | |
nb_data_list = [] | 61 | 61 | nb_data_list = [] | |
nb_data = '' | 62 | 62 | nb_data = '' | |
try: | 63 | 63 | try: | |
while ans != '\n': | 64 | 64 | while ans != '\n': | |
ans = self.sock.recv(1) | 65 | 65 | ans = self.sock.recv(1) | |
nb_data_list.append(ans) # Return the number of data | 66 | 66 | nb_data_list.append(ans) # Return the number of data | |
list_size = len(nb_data_list) | 67 | 67 | list_size = len(nb_data_list) | |
for j in range (0, list_size): | 68 | 68 | for j in range (0, list_size): | |
nb_data = nb_data+nb_data_list[j] | 69 | 69 | nb_data = nb_data+nb_data_list[j] | |
return nb_data | 70 | 70 | return nb_data | |
except socket.timeout: | 71 | 71 | except socket.timeout: | |
print "Socket timeout error when reading." | 72 | 72 | print "Socket timeout error when reading." | |
raise | 73 | 73 | raise | |
74 | 74 | |||
def disconnect(self): | 75 | 75 | def disconnect(self): | |
self.send('MODE0') | 76 | 76 | self.send('MODE0') | |
self.sock.close() | 77 | 77 | self.sock.close() | |
78 | 78 | |||
def send(self, command): | 79 | 79 | def send(self, command): | |
self.sock.send("%s\n"%command) | 80 | 80 | self.sock.send("%s\n"%command) | |
81 | 81 | |||
instruments/PM100D.py
from abstract_instrument import abstract_instrument | 1 | 1 | from abstract_instrument import abstract_instrument | |
import os | 2 | 2 | import os | |
3 | 3 | |||
#============================================================================== | 4 | 4 | #============================================================================== | |
5 | 5 | |||
ALL_VAL_TYPE = "PWR" | 6 | 6 | ALL_VAL_TYPE = "PWR" | |
7 | 7 | |||
#============================================================================== | 8 | 8 | #============================================================================== | |
9 | 9 | |||
class PM100D(abstract_instrument): | 10 | 10 | class PM100D(abstract_instrument): | |
def __init__(self, adress="/dev/usbtmc0", vtype="PWR"): | 11 | 11 | def __init__(self, adress="/dev/usbtmc0", vtype="PWR"): | |
self.adress = adress | 12 | 12 | self.adress = adress | |
self.vtype = vtype | 13 | 13 | self.vtype = vtype | |
14 | 14 | |||
def model(self): | 15 | 15 | def model(self): | |
self.send("*IDN?") | 16 | 16 | self.send("*IDN?") | |
return self.read() | 17 | 17 | return self.read() | |
18 | 18 | |||
def connect(self): | 19 | 19 | def connect(self): | |
try: | 20 | 20 | try: | |
print('Connecting to device @%s...' %(self.adress)) | 21 | 21 | print('Connecting to device @%s...' %(self.adress)) | |
self.FILE = os.open(self.adress, os.O_RDWR) | 22 | 22 | self.FILE = os.open(self.adress, os.O_RDWR) | |
print(' --> Ok') | 23 | 23 | print(' --> Ok') | |
24 | 24 | |||
print(self.model()) | 25 | 25 | print(self.model()) | |
26 | 26 | |||
if self.vtype == "PWR": | 27 | 27 | if self.vtype == "PWR": | |
1 | 28 | 28 | 1 | |
else: | 29 | 29 | else: | |
print("Wrong -v argument") | 30 | 30 | print("Wrong -v argument") | |
raise | 31 | 31 | raise | |
32 | 32 | |||
except Exception as er: | 33 | 33 | except Exception as er: | |
print("Unexpected error during connection: " + str(er)) | 34 | 34 | print("Unexpected error during connection: " + str(er)) | |
raise | 35 | 35 | raise | |
36 | 36 | |||
def getValue(self): | 37 | 37 | def getValue(self): | |
self.send("READ?") | 38 | 38 | self.send("READ?") | |
return self.read() | 39 | 39 | return self.read() | |
40 | 40 | |||
def read(self): | 41 | 41 | def read(self): | |
return os.read(self.FILE, 300) | 42 | 42 | return os.read(self.FILE, 300) | |
43 | 43 | |||
def disconnect(self): | 44 | 44 | def disconnect(self): | |
self.send('*RST') | 45 | 45 | self.send('*RST') | |
46 | 46 | |||
def send(self, command): | 47 | 47 | def send(self, command): | |
os.write(self.FILE, command) | 48 | 48 | os.write(self.FILE, command) | |
49 | 49 | |||
instruments/T7Pro.py
from abstract_instrument import abstract_instrument | 1 | 1 | from abstract_instrument import abstract_instrument | |
from labjack import ljm | 2 | 2 | from labjack import ljm | |
import numpy | 3 | 3 | import numpy | |
4 | 4 | |||
#============================================================================== | 5 | 5 | #============================================================================== | |
6 | 6 | |||
ALL_VAL_TYPE = "TEMP, RES" | 7 | 7 | ALL_VAL_TYPE = "TEMP, RES" | |
8 | 8 | |||
#============================================================================== | 9 | 9 | #============================================================================== | |
10 | 10 | |||
class T7Pro(abstract_instrument): | 11 | 11 | class T7Pro(abstract_instrument): | |
def __init__(self, adress="192.168.0.26", vtype="TEMP"): | 12 | 12 | def __init__(self, adress="192.168.0.26", vtype="TEMP"): | |
self.adress = adress | 13 | 13 | self.adress = adress | |
self.vtype = vtype | 14 | 14 | self.vtype = vtype | |
self.names = ["TEMPERATURE_AIR_K", | 15 | 15 | self.names = ["TEMPERATURE_AIR_K", | |
"CURRENT_SOURCE_200UA_CAL_VALUE", | 16 | 16 | "CURRENT_SOURCE_200UA_CAL_VALUE", | |
"AIN0",# "AIN1", | 17 | 17 | "AIN0",# "AIN1", | |
"AIN2",# "AIN3", | 18 | 18 | "AIN2",# "AIN3", | |
"AIN4",# "AIN5", | 19 | 19 | "AIN4",# "AIN5", | |
"AIN6",# "AIN7" | 20 | 20 | "AIN6",# "AIN7" | |
] | 21 | 21 | ] | |
22 | 22 | |||
def model(self): | 23 | 23 | def model(self): | |
return 'T7Pro' | 24 | 24 | return 'T7Pro' | |
25 | 25 | |||
def connect(self): | 26 | 26 | def connect(self): | |
try: | 27 | 27 | try: | |
print('Connecting to device @%s...' %(self.adress)) | 28 | 28 | print('Connecting to device @%s...' %(self.adress)) | |
self.handle = ljm.openS("T7", "ETHERNET", self.adress) | 29 | 29 | self.handle = ljm.openS("T7", "ETHERNET", self.adress) | |
self.configureAINs() | 30 | 30 | self.configureAINs() | |
print(' --> Ok') | 31 | 31 | print(' --> Ok') | |
32 | 32 | |||
print(self.model()) | 33 | 33 | print(self.model()) | |
34 | 34 | |||
if self.vtype == "TEMP": | 35 | 35 | if self.vtype == "TEMP": | |
1 | 36 | 36 | 1 | |
elif self.vtype == "RES": | 37 | 37 | elif self.vtype == "RES": | |
1 | 38 | 38 | 1 | |
else: | 39 | 39 | else: | |
print("Wrong -v argument") | 40 | 40 | print("Wrong -v argument") | |
raise | 41 | 41 | raise | |
42 | 42 | |||
except Exception as er: | 43 | 43 | except Exception as er: | |
print("Unexpected error during connection: " + str(er)) | 44 | 44 | print("Unexpected error during connection: " + str(er)) | |
raise | 45 | 45 | raise | |
46 | 46 | |||
def getValue(self): | 47 | 47 | def getValue(self): | |
results = self.read(self.names) | 48 | 48 | results = self.read(self.names) | |
temp = results[0] | 49 | 49 | temp = results[0] | |
res1 = results[2]/results[1] | 50 | 50 | res1 = results[2]/results[1] | |
res2 = results[3]/results[1] | 51 | 51 | res2 = results[3]/results[1] | |
res3 = results[4]/results[1] | 52 | 52 | res3 = results[4]/results[1] | |
res4 = results[5]/results[1] | 53 | 53 | res4 = results[5]/results[1] | |
54 | 54 | |||
if self.vtype == 'TEMP': | 55 | 55 | if self.vtype == 'TEMP': | |
# Temperature calculation | 56 | 56 | # Temperature calculation | |
temp1 = self.res2tempSensor(628, res1) | 57 | 57 | temp1 = self.res2tempSensor(628, res1) | |
temp2 = self.res2tempSensor(16947, res2) | 58 | 58 | temp2 = self.res2tempSensor(16947, res2) | |
temp3 = self.res2tempSensor(625, res3) | 59 | 59 | temp3 = self.res2tempSensor(625, res3) | |
temp4 = self.res2tempSensor(100, res4) | 60 | 60 | temp4 = self.res2tempSensor(100, res4) | |
string = '%f\t%f\t%f\t%f\t%f\n'%(temp, temp1, temp2, temp3, temp4) | 61 | 61 | string = '%f\t%f\t%f\t%f\t%f\n'%(temp, temp1, temp2, temp3, temp4) | |
elif self.vtype == 'RES': | 62 | 62 | elif self.vtype == 'RES': | |
string = '%f\t%f\t%f\t%f\t%f\n'%(temp, res1, res2, res3, res4) | 63 | 63 | string = '%f\t%f\t%f\t%f\t%f\n'%(temp, res1, res2, res3, res4) | |
else: | 64 | 64 | else: | |
string = '' | 65 | 65 | string = '' | |
66 | 66 | |||
return string | 67 | 67 | return string | |
68 | 68 | |||
def read(self, names): | 69 | 69 | def read(self, names): | |
return ljm.eReadNames(self.handle, len(names), names) | 70 | 70 | return ljm.eReadNames(self.handle, len(names), names) | |
71 | 71 | |||
def disconnect(self): | 72 | 72 | def disconnect(self): | |
ljm.close(self.handle) | 73 | 73 | ljm.close(self.handle) | |
74 | 74 | |||
def send(self, command): | 75 | 75 | def send(self, command): | |
pass | 76 | 76 | pass | |
77 | 77 | |||
def configureAINs(self): | 78 | 78 | def configureAINs(self): | |
# Setup and call eWriteNames to configure AINs on the LabJack. | 79 | 79 | # Setup and call eWriteNames to configure AINs on the LabJack. | |
names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", | 80 | 80 | names = ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", | |
#"AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", | 81 | 81 | #"AIN1_NEGATIVE_CH", "AIN1_RANGE", "AIN1_RESOLUTION_INDEX", | |
"AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", | 82 | 82 | "AIN2_NEGATIVE_CH", "AIN2_RANGE", "AIN2_RESOLUTION_INDEX", | |
#"AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", | 83 | 83 | #"AIN3_NEGATIVE_CH", "AIN3_RANGE", "AIN3_RESOLUTION_INDEX", | |
"AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", | 84 | 84 | "AIN4_NEGATIVE_CH", "AIN4_RANGE", "AIN4_RESOLUTION_INDEX", | |
#"AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", | 85 | 85 | #"AIN5_NEGATIVE_CH", "AIN5_RANGE", "AIN5_RESOLUTION_INDEX", | |
"AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", | 86 | 86 | "AIN6_NEGATIVE_CH", "AIN6_RANGE", "AIN6_RESOLUTION_INDEX", | |
#"AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX" | 87 | 87 | #"AIN7_NEGATIVE_CH", "AIN7_RANGE", "AIN7_RESOLUTION_INDEX" | |
] | 88 | 88 | ] | |
l_names = len(names) | 89 | 89 | l_names = len(names) | |
aValues = [1, 1, 12, | 90 | 90 | aValues = [1, 1, 12, | |
#199, 0.01, 0, | 91 | 91 | #199, 0.01, 0, | |
3, 1, 12, | 92 | 92 | 3, 1, 12, | |
#199, 0.01, 0, | 93 | 93 | #199, 0.01, 0, | |
5, 1, 12, | 94 | 94 | 5, 1, 12, | |
#199, 0.01, 0, | 95 | 95 | #199, 0.01, 0, | |
7, 0.1, 12, | 96 | 96 | 7, 0.1, 12, | |
#199, 0.01, 0 | 97 | 97 | #199, 0.01, 0 | |
] | 98 | 98 | ] | |
ljm.eWriteNames(self.handle, l_names, names, aValues) | 99 | 99 | ljm.eWriteNames(self.handle, l_names, names, aValues) | |
# print("\nSet configuration:") | 100 | 100 | # print("\nSet configuration:") | |
# for i in range(len(names)): | 101 | 101 | # for i in range(len(names)): | |
# print(" %s : %f" % (names[i], aValues[i])) | 102 | 102 | # print(" %s : %f" % (names[i], aValues[i])) | |
103 | 103 | |||
def res2tempSensor(self, sensor, res): | 104 | 104 | def res2tempSensor(self, sensor, res): | |
if sensor==627: | 105 | 105 | if sensor==627: | |
K = [0.399341181655472610, | 106 | 106 | K = [0.399341181655472610, | |
10.8420092277810909, | 107 | 107 | 10.8420092277810909, | |
-26.4597939187660813, | 108 | 108 | -26.4597939187660813, | |
245.9828566655493379, | 109 | 109 | 245.9828566655493379, | |
-668.069876596331596, | 110 | 110 | -668.069876596331596, | |
1001.69882618263364, | 111 | 111 | 1001.69882618263364, | |
-267.272089680656791] | 112 | 112 | -267.272089680656791] | |
if sensor==625: | 113 | 113 | if sensor==625: | |
K = [0.333548856582638109, | 114 | 114 | K = [0.333548856582638109, | |
11.7361551595386118, | 115 | 115 | 11.7361551595386118, | |
-31.32988932320903987, | 116 | 116 | -31.32988932320903987, | |
262.878643524833024, | 117 | 117 | 262.878643524833024, | |
-704.163538021035492, | 118 | 118 | -704.163538021035492, | |
1056.6040485650301, | 119 | 119 | 1056.6040485650301, | |
-307.057196729816496] | 120 | 120 | -307.057196729816496] | |
if sensor==628: | 121 | 121 | if sensor==628: | |
K = [0.463200932294057566, | 122 | 122 | K = [0.463200932294057566, | |
13.5049710820894688, | 123 | 123 | 13.5049710820894688, | |
-30.5191222755238414, | 124 | 124 | -30.5191222755238414, | |
231.098593852017075, | 125 | 125 | 231.098593852017075, | |
-550.122691885568202, | 126 | 126 | -550.122691885568202, | |
806.038547554984689, | 127 | 127 | 806.038547554984689, | |
-198.510489917360246] | 128 | 128 | -198.510489917360246] | |
if sensor==16945: | 129 | 129 | if sensor==16945: | |
K = [3.2497, 5.1777, 2.499] | 130 | 130 | K = [3.2497, 5.1777, 2.499] | |
if sensor==16943: | 131 | 131 | if sensor==16943: | |
K = [3.4738, 5.1198, 2.3681] | 132 | 132 | K = [3.4738, 5.1198, 2.3681] | |
if sensor==16944: | 133 | 133 | if sensor==16944: | |
K = [3.3674, 5.2874, 2.5165] | 134 | 134 | K = [3.3674, 5.2874, 2.5165] | |
if sensor==16941: | 135 | 135 | if sensor==16941: | |
K = [2.9486, 4.5862, 2.266] | 136 | 136 | K = [2.9486, 4.5862, 2.266] | |
if sensor==16947: | 137 | 137 | if sensor==16947: | |
K = [3.4597, 5.2422, 2.4169] | 138 | 138 | K = [3.4597, 5.2422, 2.4169] | |
if sensor==100: | 139 | 139 | if sensor==100: | |
K = [0.003850] | 140 | 140 | K = [0.003850] | |
return self.res2temp(K, res) | 141 | 141 | return self.res2temp(K, res) | |
142 | 142 | |||
def res2temp(K, res): | 143 | 143 | def res2temp(K, res): | |
temp = 0 | 144 | 144 | temp = 0 | |
tmp = 1000./res | 145 | 145 | tmp = 1000./res | |
if len(K)==7: | 146 | 146 | if len(K)==7: | |
for i in range(len(K)): | 147 | 147 | for i in range(len(K)): | |
temp += K[i]*tmp**i | 148 | 148 | temp += K[i]*tmp**i | |
if len(K)==3: | 149 | 149 | if len(K)==3: | |
for i in range(len(K)): | 150 | 150 | for i in range(len(K)): | |
temp += K[i]*numpy.log10(tmp)**(2-i) | 151 | 151 | temp += K[i]*numpy.log10(tmp)**(2-i) | |
temp = 10**temp | 152 | 152 | temp = 10**temp | |
if len(K)==1: | 153 | 153 | if len(K)==1: | |
temp = (res/100.-1)/K[0]+273.15 | 154 | 154 | temp = (res/100.-1)/K[0]+273.15 | |
return temp | 155 | 155 | return temp | |
156 | 156 | |||
instruments/__init__.py
from os import listdir | 1 | 1 | from os import listdir | |
from os.path import dirname | 2 | 2 | from os.path import dirname | |
3 | 3 | |||
for module in listdir(dirname(__file__)): | 4 | 4 | for module in listdir(dirname(__file__)): | |
if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': | 5 | 5 | if module == '__init__.py' or module == 'abstract_instrument.py' or module[-3:] != '.py': | |
continue | 6 | 6 | continue | |
__import__(module[:-3], locals(), globals()) | 7 | 7 | __import__(module[:-3], locals(), globals()) | |
8 | 8 | |||
del module, listdir, dirname | 9 | 9 | del module, listdir, dirname | |
instruments/abstract_instrument.py
import abc | 1 | 1 | import abc | |
2 | 2 | |||
class abstract_instrument(object): | 3 | 3 | class abstract_instrument(object): | |
__metaclass__ = abc.ABCMeta | 4 | 4 | __metaclass__ = abc.ABCMeta | |
5 | 5 | |||
@abc.abstractmethod | 6 | 6 | @abc.abstractmethod | |
def __init__(self, adress, vtype): | 7 | 7 | def __init__(self, adress, vtype): | |
"""Build the class""" | 8 | 8 | """Build the class""" | |
return | 9 | 9 | return | |
10 | 10 | |||
@abc.abstractmethod | 11 | 11 | @abc.abstractmethod | |
def model(self): | 12 | 12 | def model(self): | |
"""return the instrument model""" | 13 | 13 | """return the instrument model""" | |
return | 14 | 14 | return | |
15 | 15 | |||
@abc.abstractmethod | 16 | 16 | @abc.abstractmethod | |
def connect(self): | 17 | 17 | def connect(self): | |
"""Create a connection with the instrument""" | 18 | 18 | """Create a connection with the instrument""" | |
return | 19 | 19 | return | |
20 | 20 | |||
@abc.abstractmethod | 21 | 21 | @abc.abstractmethod | |
def disconnect(self): | 22 | 22 | def disconnect(self): | |
"""Disconnect the instrument""" | 23 | 23 | """Disconnect the instrument""" | |
return | 24 | 24 | return | |
25 | 25 | |||
@abc.abstractmethod | 26 | 26 | @abc.abstractmethod | |
def read(self): | 27 | 27 | def read(self): | |
"""read the buffer""" | 28 | 28 | """read the buffer""" | |
return | 29 | 29 | return | |
30 | 30 | |||
@abc.abstractmethod | 31 | 31 | @abc.abstractmethod | |
def send(self): | 32 | 32 | def send(self): | |
"""send a command""" | 33 | 33 | """send a command""" | |
return | 34 | 34 | return | |
35 | 35 | |||
@abc.abstractmethod | 36 | 36 | @abc.abstractmethod | |
def getValue(self): | 37 | 37 | def getValue(self): | |
"""return the value of measurment""" | 38 | 38 | """return the value of measurment""" | |
return | 39 | 39 | return | |
40 | 40 | |||
instruments/testDevice.py
from abstract_instrument import abstract_instrument | 1 | 1 | from abstract_instrument import abstract_instrument | |
import numpy, time | 2 | 2 | import numpy, time | |
3 | 3 | |||
#============================================================================== | 4 | 4 | #============================================================================== | |
5 | 5 | |||
ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | 6 | 6 | ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" | |
7 | 7 | |||
#============================================================================== | 8 | 8 | #============================================================================== | |
9 | 9 | |||
class testDevice(abstract_instrument): | 10 | 10 | class testDevice(abstract_instrument): | |
def __init__(self, adress="123.456.789.123", vtype="DCV"): | 11 | 11 | def __init__(self, adress="123.456.789.123", vtype="DCV"): | |
self.adress = adress | 12 | 12 | self.adress = adress | |
self.port = 9999 | 13 | 13 | self.port = 9999 | |
self.vtype = vtype | 14 | 14 | self.vtype = vtype | |
15 | 15 | |||
def model(self): | 16 | 16 | def model(self): | |
return 'test device' | 17 | 17 | return 'test device' | |
18 | 18 | |||
def connect(self): | 19 | 19 | def connect(self): | |
print('Connecting to device @%s:%s...' %(self.adress, self.port)) | 20 | 20 | print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
time.sleep(1) | 21 | 21 | time.sleep(1) | |
print(' --> Ok') | 22 | 22 | print(' --> Ok') | |
23 | 23 | |||
print(self.model()) | 24 | 24 | print(self.model()) | |
25 | 25 | |||
if self.vtype == "DCV": | 26 | 26 | if self.vtype == "DCV": | |
print("CONF:VOLT:DC") | 27 | 27 | print("CONF:VOLT:DC") | |
elif self.vtype == "ACV": | 28 | 28 | elif self.vtype == "ACV": | |
print("CONF:VOLT:AC") | 29 | 29 | print("CONF:VOLT:AC") | |
elif self.vtype == "DCI": | 30 | 30 | elif self.vtype == "DCI": | |
print("CONF:CURR:DC") | 31 | 31 | print("CONF:CURR:DC") | |
elif self.vtype == "ACI": | 32 | 32 | elif self.vtype == "ACI": | |
print("CONF:CURR:AC") | 33 | 33 | print("CONF:CURR:AC") | |
elif self.vtype == "RES2W": | 34 | 34 | elif self.vtype == "RES2W": | |
print("CONF:RES") | 35 | 35 | print("CONF:RES") | |
elif self.vtype == "RES4W": | 36 | 36 | elif self.vtype == "RES4W": | |
print("CONF:FRES") | 37 | 37 | print("CONF:FRES") | |
elif self.vtype == "FREQ": | 38 | 38 | elif self.vtype == "FREQ": | |
print("CONF:FREQ") | 39 | 39 | print("CONF:FREQ") | |
else: | 40 | 40 | else: | |
print("Wrong -v argument") | 41 | 41 | print("Wrong -v argument") | |
raise | 42 | 42 | raise | |
43 | 43 | |||
def getValue(self): | 44 | 44 | def getValue(self): | |
return str(numpy.random.rand()) | 45 | 45 | return str(numpy.random.rand()) | |
46 | 46 | |||
def read(self): | 47 | 47 | def read(self): | |
print('reading') | 48 | 48 | print('reading') | |
return 1 | 49 | 49 | return 1 | |
50 | 50 | |||
def disconnect(self): | 51 | 51 | def disconnect(self): | |
print('reset') | 52 | 52 | print('reset') | |
53 | 53 | |||
def send(self, command): | 54 | 54 | def send(self, command): | |
print('send %s'%command) | 55 | 55 | print('send %s'%command) | |
56 | 56 | |||