Commit acf3be97dfac7a29b2f396fa9fec6208e5d41edb

Authored by bmarechal
1 parent 4e424a66ab
Exists in master

add HP53132A support

Showing 1 changed file with 96 additions and 0 deletions Inline Diff

instruments/HP53132A.py
File was created 1 from abstract_instrument import abstract_instrument
2 import socket
3
4 #==============================================================================
5
6 ALL_VAL_TYPE = ['FREQ']
7 ALL_CHANNELS = ['1', '2']
8
9 ADRESS = "192.168.0.52"
10 CONF_VAL_TYPE = [':FETCH:FREQ?']
11
12 #==============================================================================
13
14 class HP53132A(abstract_instrument):
15 def __init__(self, channels, vtypes, adress):
16 self.adress = adress
17 self.port = 1234
18 self.gpib_addr = 12
19 self.channels = channels
20 self.vtypes = vtypes
21
22 def model(self):
23 #self.send("*IDN?")
24 #return self.read()
25 return "HP53132A"
26
27 def connect(self):
28 print('Connecting to device @%s:%s...' %(self.adress, self.port))
29 self.sock = socket.socket(socket.AF_INET,
30 socket.SOCK_STREAM,
31 socket.IPPROTO_TCP)
32 self.sock.settimeout(10.0) # Don't hang around forever
33 self.sock.connect((self.adress, self.port))
34 self.init_prologix()
35 print(' --> Ok')
36 print(self.model())
37 self.configure()
38
39 def configure(self):
40 self.strCh = ''
41 for ch in self.channels:
42 self.strCh = self.strCh + '%s;'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
43 self.strCh = self.strCh[0:-1]
44 self.send(':FORMAT ASCII')
45 self.send(":FUNC 'FREQ 1'")
46 self.send(":ROSC:SOUR INT")
47 self.send(":INIT:CONT ON")
48 print(self.strCh)
49
50 def getValue(self):
51 self.send(self.strCh)
52 return self.read()
53
54 def read(self):
55 self.send("++read eoi")
56 ans = ''
57 nb_data_list = []
58 nb_data = ''
59 try:
60 while ans != '\n':
61 ans = self.sock.recv(1)
62 nb_data_list.append(ans) # Return the number of data
63 list_size = len(nb_data_list)
64 for j in range (0, list_size):
65 nb_data = nb_data+nb_data_list[j]
66 return nb_data
67 except socket.timeout:
68 print "Socket timeout error when reading."
69 raise
70
71 def disconnect(self):
72 self.send('*RST')
73 self.sock.close()
74
75 def send(self, command):
76 self.sock.send("%s\n"%command)
77
78 def init_prologix(self):
79 try:
80 self.sock.send("++mode 1\n") # Set mode as CONTROLLER
81 self.sock.send('++addr ' + str(self.gpib_addr) + '\n') # Set the GPIB address
82 self.sock.send('++eos 3\n') # Set end-of-send character to nothing