annotate example2.py @ 68:f95db5ea2fe1

Add example code to configure a Rigol DSG815 for a frequency sweep
author Daniel O'Connor <doconnor@gsoft.com.au>
date Tue, 19 Jan 2021 17:32:57 +1030
parents c90db15a497e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
1 #!/usr/bin/env python
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
2
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
3 # Copyright (c) 2009
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
5 #
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
6 # Redistribution and use in source and binary forms, with or without
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
7 # modification, are permitted provided that the following conditions
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
8 # are met:
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
14 #
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
25 # SUCH DAMAGE.
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
26 #
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
27
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
28 import rsib
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
29 import numpy
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
30 from matplotlib import pylab
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
31
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
32 def test(r):
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
33 r.write('*IDN?')
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
34 print("ID is " + r.read(5))
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
35 r.write("*RST")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
36 r.write("INIT:CONT OFF")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
37 r.write("SYST:DISP:UPD ON")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
38 r.write("FREQ:STAR 85MHz;STOP 125MHz")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
39 r.write("DISP:WIND:TRAC:T:RLEV -20dBm")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
40 r.write("INIT;*WAI")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
41 r.write("*OPC?")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
42 print("OPC - " + r.read(10))
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
43 r.write("CALC:MARK:PEXC 6DB")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
44 r.write("CALC:MARK:FUNC:TOI ON")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
45 r.write("CALC:MARK:FUNC:TOI:RES?")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
46 print("Result " + r.read(10))
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
47
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
48 r.write("FORM:DATA ASC")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
49 r.write("CALC:LIM5:NAME 'TEST1'")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
50 r.write("CALC:LIM5:COMM 'Upper limit line'")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
51 r.write("CALC1:LIM5:TRAC 2")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
52 r.write("TRAC1? TRACE1")
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
53 data = r.read(10)
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
54 #print "Data - " + dat
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
55 data = list(map(float, data.split(',')))
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
56 ary = numpy.array(data)
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
57 pylab.plot(ary)
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
58 pylab.show()
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
59
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
60 if __name__ == '__main__':
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
61 r = rsib.RSIBDevice('analyzer')
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
62 test(r)
c90db15a497e Add simple spectrum analyser example
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff changeset
63