Blame view
instruments/AG34972A.py
1.99 KB
91efd0ebc Add files via upload |
1 2 3 4 5 6 7 |
from abstract_instrument import abstract_instrument import socket #============================================================================== ALL_VAL_TYPE = ['DCV', 'ACV', 'DCI', 'ACI', 'RES2W', 'RES4W', 'FREQ'] ALL_CHANNELS = ['101', '102', '103', '104', '105'] |
9058343c5 some minor fixes |
8 |
ADDRESS = "192.168.0.72" |
91efd0ebc Add files via upload |
9 10 11 12 13 |
CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', 'CONF:RES', 'CONF:FRES', 'CONF:FREQ'] #============================================================================== class AG34972A(abstract_instrument): |
348049517 replace 4 spaces ... |
14 15 16 17 18 |
def __init__(self, channels, vtypes, address): self.address = address self.port = 5025 self.channels = channels self.vtypes = vtypes |
91efd0ebc Add files via upload |
19 |
|
348049517 replace 4 spaces ... |
20 21 22 23 |
def model(self): #self.send("*IDN?") #return self.read() return "AG34972A" |
91efd0ebc Add files via upload |
24 |
|
348049517 replace 4 spaces ... |
25 26 27 28 29 30 31 32 33 34 35 |
def connect(self): print('Connecting to device @%s:%s...' %(self.address, self.port)) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) self.sock.settimeout(2.0) # Don't hang around forever self.sock.connect((self.address, self.port)) self.send("SYST:BEEP") print(' --> Ok') print(self.model()) self.configure() |
91efd0ebc Add files via upload |
36 |
|
348049517 replace 4 spaces ... |
37 38 39 40 41 42 43 44 |
def configure(self): self.strCh = '' for ch in self.channels: self.send('%s (@%s)'%(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])], ch)) self.strCh = self.strCh + ch + ',' self.strCh = self.strCh[0:-1] self.send("ROUT:SCAN (@%s)"%self.strCh) self.send("TRIG:COUN 1") |
91efd0ebc Add files via upload |
45 |
|
348049517 replace 4 spaces ... |
46 47 48 49 |
def getValue(self): self.send("INIT") self.send("FETC?") return self.read() |
91efd0ebc Add files via upload |
50 |
|
348049517 replace 4 spaces ... |
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
def read(self): 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 |
91efd0ebc Add files via upload |
67 |
|
348049517 replace 4 spaces ... |
68 69 70 |
def disconnect(self): self.send('*RST') self.sock.close() |
91efd0ebc Add files via upload |
71 |
|
348049517 replace 4 spaces ... |
72 73 74 |
def send(self, command): self.sock.send("%s "%command) |