Commit b8f64a3ebf31b54dd7357727a2da6463167906dc

Authored by bmarechal
1 parent bd700e0048
Exists in master

instruments/AG34461A_avg.py: NPLC trick to give a 1s meas

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

instruments/AG34461A_avg.py
  1 +from abstract_instrument import abstract_instrument
  2 +import socket
  3 +import time
  4 +
  5 +#==============================================================================
  6 +
  7 +ALL_VAL_TYPE = ['DCV', 'ACV', 'DCI', 'ACI', 'RES2W', 'RES4W', 'FREQ']
  8 +ALL_CHANNELS = ['1']
  9 +
  10 +ADDRESS = "192.168.0.61"
  11 +CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', 'CONF:RES', 'CONF:FRES', 'CONF:FREQ']
  12 +
  13 +#==============================================================================
  14 +
  15 +class AG34461A_avg(abstract_instrument):
  16 + def __init__(self, channels, vtypes, address):
  17 + self.address = address
  18 + self.port = 5025
  19 + self.channels = channels
  20 + self.vtypes = vtypes
  21 +
  22 + def model(self):
  23 + #self.send("*IDN?")
  24 + #return self.read()
  25 + return "AG34461A"
  26 +
  27 + def connect(self):
  28 + print('Connecting to device @%s:%s...' %(self.address, self.port))
  29 + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  30 + self.sock.settimeout(10.0) # Don't hang around forever
  31 + self.sock.connect((self.address, self.port))
  32 + self.send("SYST:BEEP")
  33 + print(' --> Ok')
  34 + print(self.model())
  35 + self.configure()
  36 +
  37 + def configure(self):
  38 + self.send("*RST")
  39 + for ch in self.channels:
  40 + self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
  41 + self.send("CONF:VOLT:DC 10")
  42 + #self.send("VOLT:DC:NPLC 10")
  43 + self.send("SAMP:COUN 1")
  44 + self.send("TRIG:COUN 5")
  45 + self.send("TRIG:DEL 0")
  46 + self.send("SENS:ZERO:AUTO OFF")
  47 + self.send("TRIG:SOUR IMM")
  48 + self.send("INIT")
  49 +
  50 + def getValue(self):
  51 + mes = ''
  52 + for ch in self.channels:
  53 + self.send("FETC?")
  54 + mesTemp = self.read()
  55 + mesTemp = map(float, mesTemp.split(','))
  56 + mes = mes + '\t' + str(sum(mesTemp)/len(mesTemp))
  57 + self.send("INIT")
  58 + return mes
  59 +
  60 + def read(self):
  61 + ans = ''
  62 + nb_data_list = []
  63 + nb_data = ''
  64 + try:
  65 + while ans != '\n':
  66 + ans = self.sock.recv(1)
  67 + nb_data_list.append(ans) # Return the number of data
  68 + list_size = len(nb_data_list)
  69 + for j in range (0, list_size):
  70 + nb_data = nb_data+nb_data_list[j]
  71 + return nb_data
  72 + except socket.timeout:
  73 + print "Socket timeout error when reading."
  74 + raise
  75 +
  76 + def disconnect(self):
  77 + self.send('*RST')
  78 + self.send("SYST:BEEP")
  79 + self.sock.close()
  80 +
  81 + def send(self, command):
  82 + self.sock.send("%s\n"%command)