Rohde & Schwarz Instruments
How to control R&S spectrum analyzers, signal generators, and oscilloscopes with PyVISA. Connection snippets, examples, and vendor quirks.
Control Rohde & Schwarz spectrum analyzers, signal generators, and oscilloscopes with PyVISA. One connect snippet, one example per instrument type.
Supported Models
| Family | Models | Interface |
|---|---|---|
| Spectrum analyzers | FSW (8/26/43/67/85), FSV3000/4000, FPS, FSVA | LAN, USB, GPIB |
| Signal generators | SMW200A, SMB100A/B, SMBV100A/B, SGT100A | LAN, USB, GPIB |
| Oscilloscopes | RTO2000/6000, RTB2000, RTM3000 | LAN, USB |
| Network analyzers | ZNA, ZNB, ZNC series | LAN, USB, GPIB |
Connect to an R&S Instrument
R&S instruments use USB vendor ID 0x0AAD. Most R&S instruments support HiSLIP over LAN (port 4880), which is faster than VXI-11.
import pyvisa
rm = pyvisa.ResourceManager()
# USB
inst = rm.open_resource("USB0::0x0AAD::0x0054::123456::INSTR")
# HiSLIP over LAN (preferred for R&S)
inst = rm.open_resource("TCPIP::192.168.1.100::hislip0::INSTR")
# VXI-11 (fallback)
inst = rm.open_resource("TCPIP::192.168.1.100::inst0::INSTR")
inst.timeout = 30000 # R&S instruments can be slow on first command
print(inst.query("*IDN?").strip())Log measurements automatically
TofuPilot records spectrum and signal measurements from your R&S instruments, tracks pass/fail rates, and generates compliance reports. Free to start.
Spectrum Analyzer (FSW / FSV)
Configure a span, run a single sweep, and find the peak.
import pyvisa
import numpy as np
rm = pyvisa.ResourceManager()
fsa = rm.open_resource("TCPIP::192.168.1.100::hislip0::INSTR")
fsa.timeout = 30000
fsa.write("*RST")
fsa.write("*CLS")
fsa.write("INIT:CONT OFF") # Single sweep mode
# Configure span
fsa.write("FREQ:CENT 1E9") # 1 GHz center
fsa.write("FREQ:SPAN 100E6") # 100 MHz span
fsa.write("BAND:RES 1E6") # 1 MHz RBW
fsa.write("BAND:VID:AUTO ON")
fsa.write("DISP:WIND:TRAC:Y:RLEV 0") # 0 dBm reference level
fsa.write("INP:ATT 10") # 10 dB attenuation
# Single sweep
fsa.write("INIT:IMM")
fsa.query("*OPC?")
# Read trace
trace = fsa.query_ascii_values("TRAC1? TRACE1")
freqs = np.linspace(0.95e9, 1.05e9, len(trace))
# Peak search
fsa.write("CALC:MARK:MAX")
peak_freq = float(fsa.query("CALC:MARK:X?"))
peak_level = float(fsa.query("CALC:MARK:Y?"))
print(f"Peak: {peak_freq/1e6:.2f} MHz at {peak_level:.1f} dBm")
fsa.close()
rm.close()Signal Generator (SMW / SMB)
Set a CW tone with AM modulation.
import pyvisa
rm = pyvisa.ResourceManager()
smb = rm.open_resource("TCPIP::192.168.1.101::hislip0::INSTR")
smb.timeout = 10000
smb.write("*RST")
smb.write("*CLS")
# CW signal: 2.4 GHz, -10 dBm
smb.write("SOUR:FREQ 2.4E9")
smb.write("SOUR:POW -10")
smb.write("OUTP:STAT ON")
# Add AM modulation
smb.write("SOUR:AM:STAT ON")
smb.write("SOUR:AM:SOUR INT")
smb.write("SOUR:AM:INT:FREQ 1000") # 1 kHz modulation
smb.write("SOUR:AM:DEPT 50") # 50% depth
print("Output: 2.4 GHz, -10 dBm, AM 1 kHz 50%")
# smb.write("OUTP:STAT OFF")
# smb.close()
# rm.close()Oscilloscope (RTO / RTB)
Capture a waveform and read automated measurements.
import pyvisa
import numpy as np
rm = pyvisa.ResourceManager()
rto = rm.open_resource("TCPIP::192.168.1.102::hislip0::INSTR")
rto.timeout = 30000
rto.write("*RST")
rto.write("FORM:DATA REAL,32")
rto.write("FORM:BORD NORM")
# Channel setup
rto.write("CHAN1:STAT ON")
rto.write("CHAN1:COUP DC")
rto.write("CHAN1:SCAL 0.5") # 500 mV/div
rto.write("TIM:SCAL 1E-6") # 1 us/div
# Trigger
rto.write("TRIG:SOUR CHAN1")
rto.write("TRIG:LEV 0.1")
rto.write("TRIG:SLOP POS")
rto.write("TRIG:MODE NORM")
# Acquire
rto.write("SING")
rto.query("*OPC?")
# Read waveform
waveform = rto.query_binary_values("CHAN1:DATA?", datatype='f')
print(f"Acquired {len(waveform)} points")
# Automated measurements
freq = float(rto.query("MEAS:FREQ? CHAN1"))
ampl = float(rto.query("MEAS:AMPL? CHAN1"))
print(f"Frequency: {freq:.1f} Hz, Amplitude: {ampl:.3f} V")
rto.close()
rm.close()R&S Quirks
| Quirk | Details | Workaround |
|---|---|---|
| HiSLIP preferred | VXI-11 works but HiSLIP is faster and more reliable | Use hislip0 in the resource string |
| Slow first command | First SCPI command after connect can take several seconds | Set timeout = 30000 at connection time |
| Verbose errors available | SYST:ERR:VERB ON gives human-readable error messages | Enable after *RST for easier debugging |
| Status byte format | R&S error strings use 0,"No error" (not +0) | Match both 0, and +0, when draining error queue |
| Spectrum analyzer sweep time | Complex measurements (EMI, phase noise) can run for minutes | Set timeout per measurement, not globally |
| Oscilloscope data format | Must set FORM:DATA and FORM:BORD before reading waveforms | Always configure after *RST |
| Probe auto-detection | CHAN:PROB:AUTO ONCE exists on RTO but not RTB | Wrap in try/except |
| Long calibration | Internal calibration (*CAL?) can take 60+ seconds | inst.timeout = 120000 before calling |