Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate acqsweep.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 | |
children | 7386f2888508 |
rev | line source |
---|---|
68
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
2 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
3 # Copyright (c) 2021 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
5 # |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
6 # Redistribution and use in source and binary forms, with or without |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
7 # modification, are permitted provided that the following conditions |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
8 # are met: |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
9 # 1. Redistributions of source code must retain the above copyright |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
10 # notice, this list of conditions and the following disclaimer. |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
11 # 2. Redistributions in binary form must reproduce the above copyright |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
12 # notice, this list of conditions and the following disclaimer in the |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
13 # documentation and/or other materials provided with the distribution. |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
14 # |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
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 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
25 # SUCH DAMAGE. |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
26 # |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
27 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
28 import usb |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
29 import usb488 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
30 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
31 # |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
32 # Tested with a Rigol DSG815 connected via USB |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
33 # |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
34 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
35 def main(): |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
36 u = usb488.USB488Device() |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
37 print('Found device') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
38 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
39 setup(u) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
40 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
41 def freqsetup(u, swstart, swstop, swpoints, swoffset, swlevel): |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
42 '''Setup a frequency sweep''' |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
43 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
44 res = u.ask('*IDN?') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
45 print('Device ID: ' + res) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
46 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
47 # Output off |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
48 wrcheck(u, ':OUTP:STATE', 'OFF') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
49 # XXX: Most of these work with :SOUR prefixed but :SWE:POIN:TRIG:TYPE does not |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
50 # Single sweep |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
51 wrcheck(u, ':SWE:MODE', 'SING') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
52 # Frequency sweep |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
53 wrcheck(u, ':SWE:STATE', 'FREQ') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
54 # Step (not list) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
55 wrcheck(u, ':SWE:TYPE', 'STEP') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
56 # In single sweep so it starts when SOU:SWE:EXE is sent |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
57 wrcheck(u, ':SWE:SWE:TRIG:TYPE', 'AUTO') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
58 # Sweep a point every external trigger |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
59 wrcheck(u, ':SWE:POIN:TRIG:TYPE', 'EXT') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
60 # Sweep up |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
61 wrcheck(u, ':SWE:DIR', 'FWD') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
62 # Ramp (vs triangle) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
63 wrcheck(u, ':SWE:STEP:SHAP', 'RAMP') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
64 # Linear sweep |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
65 wrcheck(u, ':SWE:STEP:SPAC', 'LIN') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
66 # Start/stop/points in sweep |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
67 wrcheck(u, ':SWE:STEP:STAR:FREQ', '%fHz' % (swstart + swoffset,)) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
68 wrcheck(u, ':SWE:STEP:STOP:FREQ', '%fHz' % (swstop + swoffset,)) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
69 wrcheck(u, ':SWE:STEP:POIN', '%d' % (swpoints,)) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
70 # Output level |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
71 wrcheck(u, ':SWE:STEP:STAR:LEV', '%fdBm' % (swlevel,)) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
72 wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swlevel,)) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
73 wrcheck(u, ':LEV', '%fdBm' % (swlevel,)) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
74 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
75 def arm(u): |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
76 # Output on |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
77 wrcheck(u, ':OUTP:STATE', 'ON') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
78 # Arm it |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
79 u.chkcmd(':SWE:EXEC') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
80 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
81 def wrcheck(u, name, value): |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
82 '''Helper function to set a value then read it back and print it out''' |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
83 u.chkcmd(name + ' ' + value) |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
84 readval = u.ask(name + '?') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
85 print(name + ' -> ' + readval + ' (' + value + ')') |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
86 |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
87 if __name__ == '__main__': |
f95db5ea2fe1
Add example code to configure a Rigol DSG815 for a frequency sweep
Daniel O'Connor <doconnor@gsoft.com.au>
parents:
diff
changeset
|
88 main() |