I'm trying to play around with some automation using PyVISA to control my Rigol DSA815 over the LAN. I'm pretty new to VISA/SCPI/etc, but am making progress. However, I'm getting very inconsistent results when trying to set values like center frequency and span. I'm using Python 2.7 on Windows if that makes any difference.
Reading values always works. Commands like turning the tracking generator on (:OUTPut ON) and the reset to defaults (:SYSTem:PRESet) always work. But most of the time when I try to set a value, nothing happens.
Here's what I'm doing. Basically resetting, setting a center freq and a span, then reading the center freq and span to see if it took effect. Run through that ten times and print the results:
import visa
import time
def test_commands(sa, delay):
"""Run a sequence of commands. sa is the spectrum analyzer to control,
delay is the number of seconds to wait between commands."""
sa.write(":SYSTem:PRESet")
time.sleep(delay)
sa.write(":FREQuency:SPAN 0")
time.sleep(delay)
sa.write(":FREQuency:CENTer 1000000")
time.sleep(delay)
current_freq = sa.ask(":FREQ:CENT?")
current_span = sa.ask(":FREQ:SPAN?")
if(current_freq != "1000000"):
print ("Freq FAIL (%s)" % current_freq),
else:
print ("Freq PASS"),
if(current_span != "0"):
print "Span FAIL (%s)" % current_span
else:
print "Span PASS"
sa = visa.instrument("TCPIP0::192.168.43.123::INSTR", term_chars='\n')
print sa.ask("*IDN?")
for i in range(10):
test_commands(sa, 1)
And here's the output when I run the script:
Rigol Technologies,DSA815,DSA8A15xxxxxxx,00.01.07.00.01
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span PASS
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span PASS
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
So the frequency never got set, and the span only got set twice.
I turned the delay between commands down to zero and ran it again:
Rigol Technologies,DSA815,DSA8A15xxxxxxx,00.01.07.00.01
Freq FAIL (750000000) Span PASS
Freq FAIL (750000000) Span PASS
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq PASS Span FAIL (2000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
Freq FAIL (750000000) Span FAIL (1500000000)
This time the frequency got set successfully once! And the span got set a couple times. But still... usually not working. I did have one test run earlier (with 1 second delay) where both frequency and span got set correctly.
Anyway... what am I doing wrong?
Can anyone successfully and consistently set the center frequency and span using PyVISA on a Rigol DSA 815 over the LAN?