comparison rs_fsp7_example.py @ 16:c2c13d804fce

Rename examples, rework them to be clearer and use helper functions.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 10 Aug 2011 12:51:07 +0930
parents example2.py@85dfc0babc36
children 9bb8a9f3df6b
comparison
equal deleted inserted replaced
15:37d6ceb4850f 16:c2c13d804fce
1 #!/usr/bin/env python
2
3 # Copyright (c) 2011
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27
28 import numpy
29 from matplotlib import pylab
30 import rsib
31 import scpi
32
33 def test(r):
34 # ID instrument
35 r.write('*IDN?')
36 print "ID is " + r.read(5)
37
38 # Reset to defaults
39 r.write("*RST")
40
41 # Set to single sweep mode
42 r.write("INIT:CONT OFF")
43
44 # Enable display updates
45 r.write("SYST:DISP:UPD ON")
46
47 # Set frequency range
48 r.write("FREQ:STAR 85MHz;STOP 125MHz")
49
50 # Set reference level
51 r.write("DISP:WIND:TRAC:Y:RLEV -20dBm")
52
53 # Trigger the sweep
54 r.write("INIT;*WAI")
55
56 # Wait up to 10 seconds for it to be done
57 r.write("*OPC?")
58 print "OPC - " + r.read(10)
59
60 # Set peak excursion
61 r.write("CALC:MARK:PEXC 6DB")
62 # Find 3rd order intercept & get result
63 r.write("CALC:MARK:FUNC:TOI ON")
64 r.write("CALC:MARK:FUNC:TOI:RES?")
65 print "Result " + r.read(10)
66
67 # Set data format
68 r.write("FORM REAL,32")
69 #r.write("FORM:DATA ASC")
70
71 # Set limit line
72 r.write("CALC:LIM5:NAME 'TEST1'")
73 r.write("CALC:LIM5:COMM 'Upper limit line'")
74 r.write("CALC1:LIM5:TRAC 2")
75
76 # Grab trace data
77 r.write("TRAC1? TRACE1")
78 data = r.read(10)
79 #print "Data - " + dat
80 #ary = ascdecode(data)
81 ary = bindecode(data)
82
83 # Plot data
84 pylab.plot(ary)
85 pylab.show()
86
87 if __name__ == '__main__':
88 r = rsib.RSIBDevice('analyzer')
89 test(r)
90