# HG changeset patch # User Daniel O'Connor # Date 1611039777 -37800 # Node ID f95db5ea2fe1b096c298b87e618fc5a2f0cb5522 # Parent 98b9258c75b658f51b93a5e413ae8568cca5eff0 Add example code to configure a Rigol DSG815 for a frequency sweep diff -r 98b9258c75b6 -r f95db5ea2fe1 acqsweep.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/acqsweep.py Tue Jan 19 17:32:57 2021 +1030 @@ -0,0 +1,88 @@ +#!/usr/bin/env python + +# Copyright (c) 2021 +# Daniel O'Connor . All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +import usb +import usb488 + +# +# Tested with a Rigol DSG815 connected via USB +# + +def main(): + u = usb488.USB488Device() + print('Found device') + + setup(u) + +def freqsetup(u, swstart, swstop, swpoints, swoffset, swlevel): + '''Setup a frequency sweep''' + + res = u.ask('*IDN?') + print('Device ID: ' + res) + + # Output off + wrcheck(u, ':OUTP:STATE', 'OFF') + # XXX: Most of these work with :SOUR prefixed but :SWE:POIN:TRIG:TYPE does not + # Single sweep + wrcheck(u, ':SWE:MODE', 'SING') + # Frequency sweep + wrcheck(u, ':SWE:STATE', 'FREQ') + # Step (not list) + wrcheck(u, ':SWE:TYPE', 'STEP') + # In single sweep so it starts when SOU:SWE:EXE is sent + wrcheck(u, ':SWE:SWE:TRIG:TYPE', 'AUTO') + # Sweep a point every external trigger + wrcheck(u, ':SWE:POIN:TRIG:TYPE', 'EXT') + # Sweep up + wrcheck(u, ':SWE:DIR', 'FWD') + # Ramp (vs triangle) + wrcheck(u, ':SWE:STEP:SHAP', 'RAMP') + # Linear sweep + wrcheck(u, ':SWE:STEP:SPAC', 'LIN') + # Start/stop/points in sweep + wrcheck(u, ':SWE:STEP:STAR:FREQ', '%fHz' % (swstart + swoffset,)) + wrcheck(u, ':SWE:STEP:STOP:FREQ', '%fHz' % (swstop + swoffset,)) + wrcheck(u, ':SWE:STEP:POIN', '%d' % (swpoints,)) + # Output level + wrcheck(u, ':SWE:STEP:STAR:LEV', '%fdBm' % (swlevel,)) + wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swlevel,)) + wrcheck(u, ':LEV', '%fdBm' % (swlevel,)) + +def arm(u): + # Output on + wrcheck(u, ':OUTP:STATE', 'ON') + # Arm it + u.chkcmd(':SWE:EXEC') + +def wrcheck(u, name, value): + '''Helper function to set a value then read it back and print it out''' + u.chkcmd(name + ' ' + value) + readval = u.ask(name + '?') + print(name + ' -> ' + readval + ' (' + value + ')') + +if __name__ == '__main__': + main()