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