annotate specan.py @ 31:c6c86dcb54ba

Add code to automate a sitesurvey (to some degree).
author Daniel O'Connor <darius@dons.net.au>
date Wed, 21 Sep 2011 15:00:24 +0930
parents
children 182c42e7bf03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 import exceptions
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 import numpy
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 import scpi
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 class Traceinst(object):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 '''Generic class for a trace based instrument'''
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 attrs = {}
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 tracetypename = None
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 tracedtype = None
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 tracequery = None
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 def __init__(self, con):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 self.con = con
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 # Set trace format
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 self.con.write("FORM " + self.tracetypename)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 def setconf(self, name, value):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 if name not in self.attrs:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 raise exceptions.KeyError(name + " not supported")
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 # Check value is correct type
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 tmp = self.attrs[name][1](value)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 # Run validation function (if necessary)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 if self.attrs[name][2] != None:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 self.attrs[name][2](value)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 #print "Setting %s to %s" % (self.attrs[name][0], str(value))
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 self.con.write("%s %s" % (self.attrs[name][0], str(value)))
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 def getconf(self, name):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 if name not in self.attrs:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 raise exceptions.KeyError(name + " not supported")
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 self.con.write("%s?" % (self.attrs[name][0]))
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 r = self.con.read()
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 return self.attrs[name][1](r)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 def write(self, *args):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 return self.con.write(*args)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 def read(self, *args):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 return self.con.read(*args)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 def gettrace(self, timeout = 10):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 # Trigger the sweep
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 self.con.write("INIT;*WAI")
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 # Wait for it to be done
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 if False:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 self.con.write("*OPC?")
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 opc = scpi.getdata(self.con.read(timeout), int)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 if opc != 1:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 return None
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 else:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 while True:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 self.con.write(':STATus:OPERation?')
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 i = scpi.getdata(self.con.read(timeout), int)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 if i & 256:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 break
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 # Grab trace data
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 self.con.write(self.tracequery)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 dat = self.con.read(10)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 # Parse into array
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 ary = scpi.bindecode(dat, dtype = self.tracedtype)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 return ary
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 def dumpconf(self):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 rtn = {}
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 for k in self.attrs:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 self.con.write(self.attrs[k][0] + '?')
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 res = self.con.read()
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 #print "Getting " + k + " / " + self.attrs[k][0] + " = " + res
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 rtn[k] = self.attrs[k][1](res)
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 return rtn
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 class RSSPA(Traceinst):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 '''Rhode & Schwartz Spectrum Analyzer'''
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 attrs = { 'fstart' : ['FREQ:START', float, None], # Page 561
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 'fstop' : ['FREQ:STOP', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 'atten' : ['INP:ATT', float, None], # Page 518
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 'resbw' : ['SENSE:BANDWIDTH:RESOLUTION', float, None], # Page 539
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 'vidbw' : ['SENSE:BANDWIDTH:VIDEO', float, None], # Page 541
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 'sweept' : ['SENSE:SWEEP:TIME', float, None], # Page 599
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 #'sweeppts' : ['SWEEP:POINTS', int, RSSPA.sweepptscheck],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 'sweeppts' : ['SWEEP:POINTS', int, None], # Page 599
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 'sweepcnt' : ['SENSE1:AVERAGE:COUNT', int, None], # Page 595
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 'reflev' : ['DISPLAY:WINDOW1:TRACE1:Y:SCALE:RLEVEL', float, None], # Page 506
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 'detector' : ['SENSE1:DETECTOR1:FUNCTION', str, None] , # Page 552
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 }
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 tracetypename = 'REAL,32'
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 tracedtype = numpy.float32
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 tracequery = 'TRAC1? TRACE1'
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 swptslist = [125, 251, 501, 1001, 2001, 4001, 8001]
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 # def sweepptscheck(npts):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 # if x not in RSSPA.swptslist:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 # raise exceptions.ValueError("Sweep value not supported, must be one of " + str(RSSPA.swptslist))
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 class AnSPA(Traceinst):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 '''Anritsu Spectrum Analyzer'''
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 attrs = { 'fstart' : ['FREQ:START', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 'fstop' : ['FREQ:STOP', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 'atten' : ['SENSE:POWER:ATTENUATION', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 'sweept' : ['SENSE:SWEEP:TIME', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 'sweepcnt' : [':SENSe:AVERage:COUNt', int, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 'tracemode' : [':SENSe:AVERage:TYPE', str, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 'resbw' : ['SENSE:BANDWIDTH:RESOLUTION', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 'vidbw' : ['SENSE:BANDWIDTH:VIDEO', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 'reflev' : [':DISPLAY:WIND:TRACE:Y:SCALE:RLEVEL', float, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 'detector' : [':SENSe:DETector:FUNCtion', str, None],
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 }
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 tracetypename = 'REAL,32'
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 tracedtype = numpy.float32
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 tracequery = 'TRACE:DATA?'
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 def getInst(inst):
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 if inst == "RSSPA":
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 return RSSPA
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 elif inst == "AnSPA":
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 return AnSPA
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 else:
c6c86dcb54ba Add code to automate a sitesurvey (to some degree).
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 raise exceptions.NotImplementedError("unknown instrument type " + inst)