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