annotate anritsu_ms2034a_example.py @ 85:60ad91b4c67c default tip

Add 'quick' option to use a faster sweep time with no averaging. Useful for testing the hardware is setup correctly without having to wait 3 minutes.
author Daniel O'Connor <doconnor@gsoft.com.au>
date Mon, 21 Oct 2024 14:12:50 +1030
parents 91b476ebc0f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 # Copyright (c) 2011
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 #
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 # Redistribution and use in source and binary forms, with or without
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 # modification, are permitted provided that the following conditions
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 # are met:
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 #
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
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
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 # SUCH DAMAGE.
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 #
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 import numpy
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 from matplotlib import pylab
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 import vxi
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 import scpi
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 def test(r):
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 # ID instrument
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 r.write('*IDN?')
56
91b476ebc0f2 Run through 2to3
Daniel O'Connor <doconnor@gsoft.com.au>
parents: 30
diff changeset
36 print("ID is " + r.read(5))
30
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 # XXX: Don't do this, on this device it resets the ethernet settings (duuuh)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 # Reset to defaults
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 #r.write("*RST")
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 # Grab trace data
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 r.write("TRAC1? TRACE1")
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 data = r.read(10)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 #print "Data - " + dat
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 #ary = ascdecode(data)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 ary = bindecode(data)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 # Plot data
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 pylab.plot(ary)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 pylab.show()
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 if __name__ == '__main__':
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 r = vxi.VXIDevice('192.168.42.51', device='inst0')
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 test(r)
9ce709b7da4b Add Q&D example code for Anritsu MS2034A and Agilent R5071.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56