Blame view

instruments/AG53230A.py 2.11 KB
c3e162c11   bmarechal   add AG53230A freq...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  from abstract_instrument import abstract_instrument
  import socket
  
  #==============================================================================
  
  ALL_VAL_TYPE = ['FREQ']
  ALL_CHANNELS = ['1']
  
  ADDRESS = "192.168.0.74"
  CONF_VAL_TYPE = ['CONF:FREQ']
  
  #==============================================================================
  
  class AG53230A(abstract_instrument):
348049517   bmarechal   replace 4 spaces ...
15
16
17
18
19
  	def __init__(self, channels, vtypes, address):
  		self.address = address
  		self.port = 5025
  		self.channels = channels
  		self.vtypes = vtypes
c3e162c11   bmarechal   add AG53230A freq...
20

348049517   bmarechal   replace 4 spaces ...
21
22
23
24
  	def model(self):
  		#self.send("*IDN?")
  		#return self.read()
  		return "AG53230A"
c3e162c11   bmarechal   add AG53230A freq...
25

348049517   bmarechal   replace 4 spaces ...
26
27
28
29
30
31
32
33
34
35
36
  	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(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()
c3e162c11   bmarechal   add AG53230A freq...
37

348049517   bmarechal   replace 4 spaces ...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  	def configure(self):
  		self.send('*RST')
  		self.send('DISP:DIG:MASK:AUTO OFF')
  		self.send('INP1:IMP 50')
  		self.send('INP1:COUP AC')
  		self.send('SYST:TIM INF')
  		self.send('SENS:ROSC:SOUR EXT')
  		self.send('SENS:ROSC:EXT:FREQ 10E6')
  		for ch in self.channels:
  			self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
  		self.send('SAMP:COUN 1E6')
  		self.send('SENS:FREQ:MODE CONT')
  		self.send('SENS:FREQ:GATE:SOUR TIME')
  		self.send('1')
  		self.send('TRIG:SOUR IMM')
c3e162c11   bmarechal   add AG53230A freq...
53

348049517   bmarechal   replace 4 spaces ...
54
55
56
57
58
59
60
  	def getValue(self):
  		mes = ''
  		for ch in self.channels:
  			self.send("DATA:REM?")
  			mesTemp = self.read()
  			mes = mes + '\t' + mesTemp
  		return mes
c3e162c11   bmarechal   add AG53230A freq...
61

348049517   bmarechal   replace 4 spaces ...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  	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
c3e162c11   bmarechal   add AG53230A freq...
78

348049517   bmarechal   replace 4 spaces ...
79
80
81
82
  	def disconnect(self):
  		self.send('*RST')
  		self.send("SYST:BEEP")
  		self.sock.close()
c3e162c11   bmarechal   add AG53230A freq...
83

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