Mercurial > ~darius > hgwebdir.cgi > pyinst
comparison 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 |
comparison
equal
deleted
inserted
replaced
68:f95db5ea2fe1 | 69:7386f2888508 |
---|---|
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 # SUCH DAMAGE. | 25 # SUCH DAMAGE. |
26 # | 26 # |
27 | 27 |
28 import sys | |
28 import usb | 29 import usb |
29 import usb488 | 30 import usb488 |
30 | 31 |
31 # | 32 # |
32 # Tested with a Rigol DSG815 connected via USB | 33 # Tested with a Rigol DSG815 connected via USB |
33 # | 34 # |
34 | 35 |
35 def main(): | 36 def main(): |
36 u = usb488.USB488Device() | 37 u = usb488.USB488Device() |
37 print('Found device') | 38 res = u.ask('*IDN?') |
39 print('Found device ID: ' + res) | |
38 | 40 |
39 setup(u) | 41 setup(u) |
40 | 42 |
41 def freqsetup(u, swstart, swstop, swpoints, swoffset, swlevel): | 43 def freqsetup(u, swstart, swstop, swpoints, swoffset, swlevel): |
42 '''Setup a frequency sweep''' | 44 '''Setup a frequency sweep''' |
43 | 45 |
44 res = u.ask('*IDN?') | |
45 print('Device ID: ' + res) | |
46 | |
47 # Output off | 46 # Output off |
48 wrcheck(u, ':OUTP:STATE', 'OFF') | 47 wrcheck(u, ':OUTP:STATE', 'OFF') |
49 # XXX: Most of these work with :SOUR prefixed but :SWE:POIN:TRIG:TYPE does not | |
50 # Single sweep | 48 # Single sweep |
51 wrcheck(u, ':SWE:MODE', 'SING') | 49 wrcheck(u, ':SWE:MODE', 'SING') |
52 # Frequency sweep | 50 # Frequency sweep |
53 wrcheck(u, ':SWE:STATE', 'FREQ') | 51 wrcheck(u, ':SWE:STATE', 'FREQ') |
54 # Step (not list) | 52 # Step (not list) |
70 # Output level | 68 # Output level |
71 wrcheck(u, ':SWE:STEP:STAR:LEV', '%fdBm' % (swlevel,)) | 69 wrcheck(u, ':SWE:STEP:STAR:LEV', '%fdBm' % (swlevel,)) |
72 wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swlevel,)) | 70 wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swlevel,)) |
73 wrcheck(u, ':LEV', '%fdBm' % (swlevel,)) | 71 wrcheck(u, ':LEV', '%fdBm' % (swlevel,)) |
74 | 72 |
73 def powersetup(u, swstart, swstop, swpoints, swfreq, swoffset): | |
74 '''Setup a power sweep''' | |
75 | |
76 # Output off | |
77 wrcheck(u, ':OUTP:STATE', 'OFF') | |
78 # Single sweep | |
79 wrcheck(u, ':SWE:MODE', 'SING') | |
80 # Level sweep | |
81 wrcheck(u, ':SWE:STATE', ' LEV') | |
82 # Step (not list) | |
83 wrcheck(u, ':SWE:TYPE', 'STEP') | |
84 # In single sweep so it starts when SOU:SWE:EXE is sent | |
85 wrcheck(u, ':SWE:SWE:TRIG:TYPE', 'AUTO') | |
86 # Sweep a point every external trigger | |
87 wrcheck(u, ':SWE:POIN:TRIG:TYPE', 'EXT') | |
88 # Sweep up | |
89 wrcheck(u, ':SWE:DIR', 'FWD') | |
90 # Ramp (vs triangle) | |
91 wrcheck(u, ':SWE:STEP:SHAP', 'RAMP') | |
92 # Linear sweep | |
93 wrcheck(u, ':SWE:STEP:SPAC', 'LIN') | |
94 # Start/stop/points in sweep | |
95 wrcheck(u, ':LEV', '%fdBm' % (swstart,)) | |
96 wrcheck(u, ':SWE:STEP:STAR:LEV', '%fdBm' % (swstart,)) | |
97 wrcheck(u, ':SWE:STEP:STOP:LEV', '%fdBm' % (swstop,)) | |
98 wrcheck(u, ':SWE:STEP:POIN', '%d' % (swpoints,)) | |
99 # Output frequency | |
100 wrcheck(u, ':SWE:STEP:STAR:FREQ', '%fHz' % (swfreq + swoffset,)) | |
101 wrcheck(u, ':SWE:STEP:STOP:FREQ', '%fHz' % (swfreq + swoffset,)) | |
102 wrcheck(u, ':FREQ', '%fHz' % (swfreq,)) | |
103 # Level sweep | |
104 | |
105 # XXX: need to send this twice for some reason | |
106 # isn't needed for frequency sweep | |
107 wrcheck(u, ':SWE:STATE', ' LEV') | |
108 | |
75 def arm(u): | 109 def arm(u): |
76 # Output on | 110 # Output on |
77 wrcheck(u, ':OUTP:STATE', 'ON') | 111 wrcheck(u, ':OUTP:STATE', 'ON') |
78 # Arm it | 112 # Arm it |
79 u.chkcmd(':SWE:EXEC') | 113 u.chkcmd(':SWE:EXEC') |
81 def wrcheck(u, name, value): | 115 def wrcheck(u, name, value): |
82 '''Helper function to set a value then read it back and print it out''' | 116 '''Helper function to set a value then read it back and print it out''' |
83 u.chkcmd(name + ' ' + value) | 117 u.chkcmd(name + ' ' + value) |
84 readval = u.ask(name + '?') | 118 readval = u.ask(name + '?') |
85 print(name + ' -> ' + readval + ' (' + value + ')') | 119 print(name + ' -> ' + readval + ' (' + value + ')') |
120 #sys.stdin.readline() | |
86 | 121 |
87 if __name__ == '__main__': | 122 if __name__ == '__main__': |
88 main() | 123 main() |