Blame view

instruments/FPC1000.py 1.89 KB
10d2e8222   bmarechal   new device: R&S F...
1
2
3
4
  from abstract_instrument import abstract_instrument
  import socket
  
  #==============================================================================
e5a64c512   bmarechal   FPC1000: measure ...
5
6
  ALL_VAL_TYPE = ['PWR_MKR']
  ALL_CHANNELS = ['1', '2', '3', '4']
10d2e8222   bmarechal   new device: R&S F...
7
8
  
  ADDRESS = "192.168.0.17"
71c75635e   bmarechal   FPC1000: une cohe...
9
  CONF_VAL_TYPE = ['CALC:MARKi:Y?']
10d2e8222   bmarechal   new device: R&S F...
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  
  #==============================================================================
  
  class FPC1000(abstract_instrument):
  	def __init__(self, channels, vtypes, address):
  		self.address = address
  		self.port = 5555
  		self.channels = channels
  		self.vtypes = vtypes
  
  	def model(self):
  		#self.send("*IDN?")
  		#return self.read()
  		return "FPC1000"
  
  	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()
  
  	def configure(self):
e5a64c512   bmarechal   FPC1000: measure ...
38
39
40
  		#for ch in self.channels:
  		#	self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])])
  		pass
10d2e8222   bmarechal   new device: R&S F...
41
42
43
44
  
  	def getValue(self):
  		mes = ''
  		for ch in self.channels:
71c75635e   bmarechal   FPC1000: une cohe...
45
  			self.send(CONF_VAL_TYPE[ALL_VAL_TYPE.index(self.vtypes[self.channels.index(ch)])].replace('i', str(ch)))
10d2e8222   bmarechal   new device: R&S F...
46
  			mesTemp = self.read()
e5a64c512   bmarechal   FPC1000: measure ...
47
48
  			mes = mes + '\t' + mesTemp.replace('
  ', '')
0cfef1bd2   bmarechal   FPC1000: fix CR a...
49
50
  		return mes + '
  '
10d2e8222   bmarechal   new device: R&S F...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  
  	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
  
  	def disconnect(self):
  		#self.send('*RST')
  		#self.send("SYST:BEEP")
  		self.sock.close()
  
  	def send(self, command):
  		self.sock.send("%s
  "%command)