Commit c3e162c114ff1fef46c9a7eb1893db207bda263c

Authored by bmarechal
1 parent 55f9a61364
Exists in master

add AG53230A frequency counter

Showing 1 changed file with 72 additions and 0 deletions Side-by-side Diff

instruments/AG53230A.py
  1 +from abstract_instrument import abstract_instrument
  2 +import socket
  3 +
  4 +#==============================================================================
  5 +
  6 +ALL_VAL_TYPE = ['FREQ']
  7 +ALL_CHANNELS = ['1']
  8 +
  9 +ADDRESS = "192.168.0.74"
  10 +CONF_VAL_TYPE = ['CONF:FREQ']
  11 +
  12 +#==============================================================================
  13 +
  14 +class AG53230A(abstract_instrument):
  15 + def __init__(self, channels, vtypes, address):
  16 + self.address = address
  17 + self.port = 5025
  18 + self.channels = channels
  19 + self.vtypes = vtypes
  20 +
  21 + def model(self):
  22 + #self.send("*IDN?")
  23 + #return self.read()
  24 + return "AG53230A"
  25 +
  26 + def connect(self):
  27 + print('Connecting to device @%s:%s...' %(self.address, 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.address, self.port))
  33 + self.send("SYST:BEEP")
  34 + print(' --> Ok')
  35 + print(self.model())
  36 + self.configure()
  37 +
  38 + def configure(self):
  39 + for ch in self.channels:
  40 + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
  41 +
  42 + def getValue(self):
  43 + mes = ''
  44 + for ch in self.channels:
  45 + self.send("READ?")
  46 + mesTemp = self.read()
  47 + mes = mes + '\t' + mesTemp
  48 + return mes
  49 +
  50 + def read(self):
  51 + ans = ''
  52 + nb_data_list = []
  53 + nb_data = ''
  54 + try:
  55 + while ans != '\n':
  56 + ans = self.sock.recv(1)
  57 + nb_data_list.append(ans) # Return the number of data
  58 + list_size = len(nb_data_list)
  59 + for j in range (0, list_size):
  60 + nb_data = nb_data+nb_data_list[j]
  61 + return nb_data
  62 + except socket.timeout:
  63 + print "Socket timeout error when reading."
  64 + raise
  65 +
  66 + def disconnect(self):
  67 + self.send('*RST')
  68 + self.send("SYST:BEEP")
  69 + self.sock.close()
  70 +
  71 + def send(self, command):
  72 + self.sock.send("%s\n"%command)