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