annotate rs_fsp7_example.py @ 30:9ce709b7da4b

Add Q&D example code for Anritsu MS2034A and Agilent R5071.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 21 Sep 2011 14:58:55 +0930
parents 438a5f1ddcd7
children 91b476ebc0f2
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?")
18
9bb8a9f3df6b Update examples to match new code.
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
58 opc = scpi.getdata(r.read(10), int)
9bb8a9f3df6b Update examples to match new code.
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
59 print "OPC - %d" % (opc)
16
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
60
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
61 # Set peak excursion
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 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
63 # 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
64 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
65 r.write("CALC:MARK:FUNC:TOI:RES?")
18
9bb8a9f3df6b Update examples to match new code.
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
66 toi = scpi.getdata(r.read(1))
9bb8a9f3df6b Update examples to match new code.
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
67 print "Result = %.2f" % (toi)
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68
16
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
69 # 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
70 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
71 #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
72
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
73 # Set limit line
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 r.write("CALC:LIM5:NAME 'TEST1'")
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 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
76 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
77
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
78 # Grab trace data
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 r.write("TRAC1? TRACE1")
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 data = r.read(10)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 #print "Data - " + dat
25
438a5f1ddcd7 Fix example usage of scpi decoder.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
82 #ary = scpi.ascdecode(data)
438a5f1ddcd7 Fix example usage of scpi decoder.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
83 ary = scpi.bindecode(data)
16
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
84
c2c13d804fce Rename examples, rework them to be clearer and use helper functions.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
85 # Plot data
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 pylab.plot(ary)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 pylab.show()
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 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
90 r = rsib.RSIBDevice('analyzer')
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 test(r)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92