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