Commit a52533e359503d678a60505b77fc8f55c6d30160

Authored by bmarechal
1 parent 792ebb9829
Exists in master

-

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

instruments/AG34461A.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 = ['DCV', 'ACV', 'DCI', 'ACI', 'RES2W', 'RES4W', 'FREQ'] 6 6 ALL_VAL_TYPE = ['DCV', 'ACV', 'DCI', 'ACI', 'RES2W', 'RES4W', 'FREQ']
ALL_CHANNELS = ['1'] 7 7 ALL_CHANNELS = ['1']
8 8
ADRESS = "192.168.0.61" 9 9 ADRESS = "192.168.0.61"
CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', 'CONF:RES', 'CONF:FRES', 'CONF:FREQ'] 10 10 CONF_VAL_TYPE = ['CONF:VOLT:DC', 'CONF:VOLT:AC', 'CONF:CURR:DC', 'CONF:CURR:AC', 'CONF:RES', 'CONF:FRES', 'CONF:FREQ']
11 11
#============================================================================== 12 12 #==============================================================================
13 13
class AG34461A(abstract_instrument): 14 14 class AG34461A(abstract_instrument):
def __init__(self, channels, vtypes, adress=ADRESS): 15 15 def __init__(self, channels, vtypes, adress=ADRESS):
self.adress = adress 16 16 self.adress = adress
self.port = 5025 17 17 self.port = 5025
self.channels = channels 18 18 self.channels = channels
self.vtypes = vtypes 19 19 self.vtypes = vtypes
20 20
def model(self): 21 21 def model(self):
#self.send("*IDN?") 22 22 #self.send("*IDN?")
#return self.read() 23 23 #return self.read()
return "AG34461A" 24 24 return "AG34461A"
25 25
def connect(self): 26 26 def connect(self):
print('Connecting to device @%s:%s...' %(self.adress, self.port)) 27 27 print('Connecting to device @%s:%s...' %(self.adress, self.port))
self.sock = socket.socket(socket.AF_INET, 28 28 self.sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM, 29 29 socket.SOCK_STREAM,
socket.IPPROTO_TCP) 30 30 socket.IPPROTO_TCP)
self.sock.settimeout(10.0) # Don't hang around forever 31 31 self.sock.settimeout(10.0) # Don't hang around forever
self.sock.connect((self.adress, self.port)) 32 32 self.sock.connect((self.adress, self.port))
self.send("SYST:BEEP") 33 33 self.send("SYST:BEEP")
print(' --> Ok') 34 34 print(' --> Ok')
print(self.model()) 35 35 print(self.model())
self.configure() 36 36 self.configure()
37 37
def configure(self): 38 38 def configure(self):
for ch in self.channels: 39 39 for ch in self.channels:
self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])]) 40 40 self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
41 41
def getValue(self): 42 42 def getValue(self):
mes = '' 43 43 mes = ''
for ch in self.channels: 44 44 for ch in self.channels:
self.send("READ?") 45 45 self.send("READ?")
mesTemp = self.read() 46 46 mesTemp = self.read()
mes = mes + '\t' + mesTemp 47 47 mes = mes + '\t' + mesTemp
return mes 48 48 return mes
49 49
def read(self): 50 50 def read(self):
ans = '' 51 51 ans = ''
nb_data_list = [] 52 52 nb_data_list = []
nb_data = '' 53 53 nb_data = ''
try: 54 54 try:
while ans != '\n': 55 55 while ans != '\n':
ans = self.sock.recv(1) 56 56 ans = self.sock.recv(1)
nb_data_list.append(ans) # Return the number of data 57 57 nb_data_list.append(ans) # Return the number of data
list_size = len(nb_data_list) 58 58 list_size = len(nb_data_list)
for j in range (0, list_size): 59 59 for j in range (0, list_size):
nb_data = nb_data+nb_data_list[j] 60 60 nb_data = nb_data+nb_data_list[j]
return nb_data 61 61 return nb_data