Blame view

instruments/AG34461A_avg.py 2.25 KB
b8f64a3eb   bmarechal   instruments/AG344...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  from abstract_instrument import abstract_instrument
  import socket
  import time
  
  #==============================================================================
  
  ALL_VAL_TYPE = ['DCV', 'ACV', 'DCI', 'ACI', 'RES2W', 'RES4W', 'FREQ']
  ALL_CHANNELS = ['1']
  
  ADDRESS = "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']
  
  #==============================================================================
  
  class AG34461A_avg(abstract_instrument):
348049517   bmarechal   replace 4 spaces ...
16
17
18
19
20
  	def __init__(self, channels, vtypes, address):
  		self.address = address
  		self.port = 5025
  		self.channels = channels
  		self.vtypes = vtypes
b8f64a3eb   bmarechal   instruments/AG344...
21

348049517   bmarechal   replace 4 spaces ...
22
23
24
25
  	def model(self):
  		#self.send("*IDN?")
  		#return self.read()
  		return "AG34461A_avg"
b8f64a3eb   bmarechal   instruments/AG344...
26

348049517   bmarechal   replace 4 spaces ...
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)
  		self.sock.settimeout(10.0)	# Don't hang around forever
  		self.sock.connect((self.address, self.port))
  		self.send("SYST:BEEP")
  		print('  --> Ok')
  		print(self.model())
  		self.configure()
b8f64a3eb   bmarechal   instruments/AG344...
36

348049517   bmarechal   replace 4 spaces ...
37
38
39
40
41
42
43
44
45
46
47
48
49
  	def configure(self):
  		self.send("*RST")
  		for ch in self.channels:
  			self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
  		#self.send("CONF:VOLT:DC 1")
  		self.send("VOLT:DC:NPLC 10")
  		self.send("SAMP:COUN 5")
  		self.send("TRIG:COUN 1")
  		self.send("TRIG:DEL 0")
  		self.send("SENS:ZERO:AUTO OFF")
  		self.send("TRIG:SOUR TIM")
  		self.send("TRIG:TIM 0.2")
  		self.send("INIT")
b8f64a3eb   bmarechal   instruments/AG344...
50

348049517   bmarechal   replace 4 spaces ...
51
52
53
54
55
56
57
58
59
60
61
62
  	def getValue(self):
  		mes = ''
  		for ch in self.channels:
  			self.send("FETC?")
  			mesTemp = self.read()
  			#print(mesTemp)
  			mesTemp = map(float, mesTemp.split(','))
  			mes = mes + '\t' + str(sum(mesTemp)/len(mesTemp))
  			self.send("INIT")
  		mes = mes + '
  '
  		return mes
b8f64a3eb   bmarechal   instruments/AG344...
63

348049517   bmarechal   replace 4 spaces ...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  	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
b8f64a3eb   bmarechal   instruments/AG344...
80

348049517   bmarechal   replace 4 spaces ...
81
82
83
84
  	def disconnect(self):
  		self.send('*RST')
  		self.send("SYST:BEEP")
  		self.sock.close()
b8f64a3eb   bmarechal   instruments/AG344...
85

348049517   bmarechal   replace 4 spaces ...
86
87
88
  	def send(self, command):
  		self.sock.send("%s
  "%command)