Commit 792ebb9829207215345007e1979fa41ac5bddbcc

Authored by bmarechal
1 parent acf3be97df
Exists in master

-

Showing 1 changed file with 11 additions and 7 deletions Inline Diff

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