Commit cb568e88d79b3bf31cf92eef8aea1e9f6b2817c7
1 parent
9af9f93f99
Exists in
master
Add Lakeshore LS350 support over ethernet
Showing 1 changed file with 70 additions and 0 deletions Side-by-side Diff
instruments/LS350.py
1 | +from abstract_instrument import abstract_instrument | |
2 | +import socket | |
3 | + | |
4 | +#============================================================================== | |
5 | + | |
6 | +ALL_VAL_TYPE = ['TEMP', 'RES'] | |
7 | +ALL_CHANNELS = ['a', 'b', 'c', 'd'] | |
8 | + | |
9 | +ADRESS = "192.168.0.12" | |
10 | +CONF_VAL_TYPE = ['krdg?', 'srdg?'] | |
11 | + | |
12 | +#============================================================================== | |
13 | + | |
14 | +class LS350(abstract_instrument): | |
15 | + def __init__(self, channels, vtypes, adress): | |
16 | + self.adress = adress | |
17 | + self.port = 7777 | |
18 | + self.channels = channels | |
19 | + self.vtypes = vtypes | |
20 | + | |
21 | + def model(self): | |
22 | + #self.send("*IDN?") | |
23 | + #return self.read() | |
24 | + return "LS350" | |
25 | + | |
26 | + def connect(self): | |
27 | + print('Connecting to device @%s:%s...' %(self.adress, self.port)) | |
28 | + self.sock = socket.socket(socket.AF_INET, | |
29 | + socket.SOCK_STREAM, | |
30 | + socket.IPPROTO_TCP) | |
31 | + self.sock.settimeout(10.0) # Don't hang around forever | |
32 | + self.sock.connect((self.adress, self.port)) | |
33 | + print(' --> Ok') | |
34 | + print(self.model()) | |
35 | + self.configure() | |
36 | + | |
37 | + def configure(self): | |
38 | + self.strCh = '' | |
39 | + for ch in self.channels: | |
40 | + self.strCh = self.strCh + '%s %s;'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch) | |
41 | + self.strCh = self.strCh[0:-1] | |
42 | + print(self.strCh) | |
43 | + | |
44 | + def getValue(self): | |
45 | + self.send(self.strCh) | |
46 | + return self.read() | |
47 | + | |
48 | + def read(self): | |
49 | + self.send("++read eoi") | |
50 | + ans = '' | |
51 | + nb_data_list = [] | |
52 | + nb_data = '' | |
53 | + try: | |
54 | + while ans != '\n': | |
55 | + ans = self.sock.recv(1) | |
56 | + nb_data_list.append(ans) # Return the number of data | |
57 | + list_size = len(nb_data_list) | |
58 | + for j in range (0, list_size): | |
59 | + nb_data = nb_data+nb_data_list[j] | |
60 | + return nb_data | |
61 | + except socket.timeout: | |
62 | + print "Socket timeout error when reading." | |
63 | + raise | |
64 | + | |
65 | + def disconnect(self): | |
66 | + self.send('MODE0') | |
67 | + self.sock.close() | |
68 | + | |
69 | + def send(self, command): | |
70 | + self.sock.send("%s\n"%command) |