diff acqsweep.py @ 69:7386f2888508

Make function more configurable
author Daniel O'Connor <doconnor@gsoft.com.au>
date Wed, 04 Aug 2021 16:07:44 +0930
parents f95db5ea2fe1
children
line wrap: on
line diff
--- a/acqsweep.py	Tue Jan 19 17:32:57 2021 +1030
+++ b/acqsweep.py	Wed Aug 04 16:07:44 2021 +0930
@@ -25,6 +25,7 @@
 # SUCH DAMAGE.
 #
 
+import sys
 import usb
 import usb488
 
@@ -34,19 +35,16 @@
 
 def main():
     u = usb488.USB488Device()
-    print('Found device')
+    res = u.ask('*IDN?')
+    print('Found device ID: ' + res)
 
     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
@@ -72,6 +70,42 @@
     wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swlevel,))
     wrcheck(u, ':LEV', '%fdBm' % (swlevel,))
 
+def powersetup(u, swstart, swstop, swpoints, swfreq, swoffset):
+    '''Setup a power sweep'''
+
+    # Output off
+    wrcheck(u, ':OUTP:STATE', 'OFF')
+    # Single sweep
+    wrcheck(u, ':SWE:MODE', 'SING')
+    # Level sweep
+    wrcheck(u, ':SWE:STATE', ' LEV')
+    # 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, ':LEV', '%fdBm' % (swstart,))
+    wrcheck(u, ':SWE:STEP:STAR:LEV', '%fdBm' % (swstart,))
+    wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swstop,))
+    wrcheck(u, ':SWE:STEP:POIN', '%d' % (swpoints,))
+    # Output frequency
+    wrcheck(u, ':SWE:STEP:STAR:FREQ', '%fHz' % (swfreq + swoffset,))
+    wrcheck(u, ':SWE:STEP:STOP:FREQ', '%fHz' % (swfreq + swoffset,))
+    wrcheck(u, ':FREQ', '%fHz' % (swfreq,))
+    # Level sweep
+
+    # XXX: need to send this twice for some reason
+    # isn't needed for frequency sweep
+    wrcheck(u, ':SWE:STATE', ' LEV')
+
 def arm(u):
     # Output on
     wrcheck(u, ':OUTP:STATE', 'ON')
@@ -83,6 +117,7 @@
     u.chkcmd(name + ' ' + value)
     readval = u.ask(name + '?')
     print(name + ' -> ' + readval + ' (' + value + ')')
+    #sys.stdin.readline()
 
 if __name__ == '__main__':
     main()