Examples

For more examples, visit our Rohde & Schwarz Github repository.

"""Getting started - how to work with RsFsw Python SCPI package.
This example performs basic RF settings and measurements on an FSW instrument.
It shows the RsFsw calls and their corresponding SCPI commands.
Notice that the python RsFsw interfaces track the SCPI commands syntax."""

from RsFsw import *

# A good practice is to check for the installed version
RsFsw.assert_minimum_version('5.0.0')

# Open the session
fsw = RsFsw('TCPIP::localhost::HISLIP', reset=True)
# Greetings, stranger...
print(f'Hello, I am: {fsw.utilities.idn_string}')

# Print commands to the console with the logger
fsw.utilities.logger.mode = LoggingMode.On
fsw.utilities.logger.log_to_console = True

# Driver's instrument status checking ( SYST:ERR? ) after each command (default value is true):
fsw.utilities.instrument_status_checking = True

#   SYSTem:DISPlay:UPDate ON
fsw.system.display.update.set(True)

#   INITiate:CONTinuous OFF
fsw.initiate.continuous.set(False)
print(f'Always work in single-sweep mode.')

#   SENSe.FREQuency:STARt 100000000
fsw.sense.frequency.start.set(100E6)

#   SENSe.FREQuency:STOP 200000000
fsw.sense.frequency.stop.set(200E6)

#   DISPlay:WINDow:TRACe:Y:SCALe:RLEVel -20.0
fsw.display.window.trace.y.scale.refLevel.set(-20.0)

#   DISPlay1:WINDow:SUBWindow:TRACe1:MODE:MAXHold
fsw.display.window.subwindow.trace.mode.set(enums.TraceModeC.MAXHold, repcap.Window.Nr1, repcap.SubWindow.Default, repcap.Trace.Tr1)

#   DISPlay1: WINDow:SUBWindow:TRACe2:MODE MINHold
fsw.display.window.subwindow.trace.mode.set(enums.TraceModeC.MINHold, repcap.Window.Nr1, repcap.SubWindow.Default, repcap.Trace.Tr2)

#   SENSe:SWEep:POINts 10001
fsw.sense.sweep.points.set(10001)

#    INITiate:IMMediate (with timeout 3000 ms)
fsw.initiate.immediate_with_opc(3000)

#            TRACe1:DATA?
trace1 = fsw.trace.data.get(enums.TraceNumber.TRACe1)

#            TRACe2:DATA?
trace2 = fsw.trace.data.get(enums.TraceNumber.TRACe2)

#   CALCulate1:MARKer1:TRACe 1
fsw.calculate.marker.trace.set(1, repcap.Window.Nr1, repcap.Marker.Nr1)

#   CALCulate1:MARKer1:MAXimum:PEAK
fsw.calculate.marker.maximum.peak.set(repcap.Window.Nr1, repcap.Marker.Nr1)
#         CALCulate1:MARKer1:X?
m1x = fsw.calculate.marker.x.get(repcap.Window.Nr1, repcap.Marker.Nr1)

#         CALCulate1:MARKer1:Y?
m1y = fsw.calculate.marker.y.get(repcap.Window.Nr1, repcap.Marker.Nr1)

print(f'Trace 1 points: {len(trace1)}')
print(f'Trace 1 Marker 1: {m1x} Hz, {m1y} dBm')

#   CALCulate1:MARKer2:TRACe 2
fsw.calculate.marker.trace.set(2, repcap.Window.Nr1, repcap.Marker.Nr2)

#   CALCulate1:MARKer2:MINimum:PEAK
fsw.calculate.marker.minimum.peak.set(repcap.Window.Nr1, repcap.Marker.Nr2)

#         CALCulate2:MARKer2:X?
m2x = fsw.calculate.marker.x.get(repcap.Window.Nr1, repcap.Marker.Nr2)

#         CALCulate2:MARKer2:Y?
m2y = fsw.calculate.marker.y.get(repcap.Window.Nr1, repcap.Marker.Nr2)

print(f'Trace 1 points: {len(trace2)}')
print(f'Trace 1 Marker 1: {m2x} Hz, {m2y} dBm')

# Close the session
fsw.close()
"""This RsFsw Python SCPI package example shows creating new FSW applications and arranging windows"""

from RsFsw import *

# A good practice is to check for the installed version
RsFsw.assert_minimum_version('5.0.0')

# Open the session
fsw = RsFsw('TCPIP::192.168.1.102::HISLIP', reset=True)
# Greetings, stranger...
print(f'Hello, I am: {fsw.utilities.idn_string}')

# Print commands to the console with the logger
fsw.utilities.logger.mode = LoggingMode.On
fsw.utilities.logger.log_to_console = True
# Do not log status checking messages if the status was OK
fsw.utilities.logger.log_status_check_ok = False

# Update display in remote
fsw.system.display.update.set(True)

# Create new instrument VSA
fsw.instrument.create.new.set(channel_type=enums.ChannelType.K70_VectorSignalAnalyzer, channel_name='MyVsa')
# Create new instrument Pulse
fsw.instrument.create.new.set(channel_type=enums.ChannelType.K6_PulseAnalysis, channel_name='MyPulse')

# Select the specan instrument by instrument name
fsw.instrument.select.set(enums.ChannelType.SpectrumAnalyzer)

# Select the MyVsa by name
fsw.instrument.selectName.set('MyVsa')

channels = fsw.instrument.listPy.get()
print(f'All active channels (type, name): {channels}')

# Get catalog of all the active windows in the VSA
windows = fsw.layout.catalog.window.get()
print(f'All active windows in the VSA (number, name): {windows}')

# Add new window with EVM results to the right of the ResultSummary window
new_name = fsw.applications.k70_Vsa.layout.add.window.get('2', enums.WindowDirection.RIGHt, enums.WindowTypeK70.ErrorVectorMagnitude)
print(f"Newly created window name: '{new_name}'")
# Now move the window 1 to the right from the newly created window:
fsw.applications.k70_Vsa.layout.move.window.set('1', new_name, enums.WindowDirReplace.RIGHt)

# Close the session
fsw.close()
"""RsFsw Python package example. Performs the following:
- Creates new FSW application.
- Takes a screenshot and transfers the file to the control PC.
- Saves the instrument status to a file 'RsFswState.dfl'.
- Copies the 'RsFswState.dfl' file under a different name to the Control PC: 'RsFswState_PC.dfl'
- Copies the file 'RsFswState_PC.dfl' back to the instrument under a new name 'RsFswState_back.dfl'.
    This simulates acquiring and distribution of a setup file from the Control PC
- Resets the instrument
- Recalls the status from the 'RsFswState_back.dfl'
"""

from RsFsw import *

# A good practice is to check for the installed version
RsFsw.assert_minimum_version('5.0.0')

# Open the session
fsw = RsFsw('TCPIP::192.168.1.102::HISLIP', reset=True)
# Greetings, stranger...
print(f'Hello, I am: {fsw.utilities.idn_string}')

# Update display in remote
fsw.system.display.update.set(True)

# Create new instrument PhaseNoise
fsw.instrument.create.new.set(channel_type=enums.ChannelType.K40_PhaseNoise, channel_name='NoiseOnly')

# Add new window with SpotNoiseTable results at the bottom
new_name = fsw.applications.k40_PhaseNoise.layout.add.window.get('2', enums.WindowDirection.BELow, enums.WindowTypeK40.SpotNoiseTable)

# Let's make a screenshot
fsw.hardCopy.mode.set(enums.HardcopyMode.SCReen)
fsw.hardCopy.device.color.set(True)
# Set the color map. Colors.Ix4 means: Screen colors without changes
fsw.hardCopy.cmap.default.set(colors=repcap.Colors.Ix4)
fsw.massMemory.name.set(r'c:\Temp\Device_Screenshot2.png')
fsw.hardCopy.immediate.set_with_opc()
# Copy the screenshot to the PC
fsw.utilities.read_file_from_instrument_to_pc(r'c:\Temp\Device_Screenshot2.png', r'c:\Temp\PC_Screenshot2.png')
print(r'Screenshot saved here: c:\Temp\PC_Screenshot2.png')

# Save the current instrument status to a recall file
fsw.massMemory.store.state.set(r'RsFswState.dfl')
# Copy the setup file to the PC under a different name
fsw.utilities.read_file_from_instrument_to_pc(r'RsFswState.dfl', r'c:\Temp\RsFswState_PC.dfl')
print(r'Setup file saved here: c:\Temp\RsFswState_PC.dfl')
# Copy the setup file back to the instrument as 'RsFswState_back.dfl'
fsw.utilities.send_file_from_pc_to_instrument(r'c:\Temp\RsFswState_PC.dfl', r'RsFswState_back.dfl')

# Make a reset and restore the saved state.
fsw.utilities.reset()

# Restore the instrument status with the file copied back from the PC
fsw.massMemory.load.state.set(r'RsFswState_back.dfl')

# Close the session
fsw.close()
# Python SCPI package RsFsw example.
# The example shows the default repcap setting done in group objects and / or cloning it.
# Each group can be cloned with clone() method, and then its repcaps can be set independently to other default values.
# These values are then taken as a default for all the methods belonging to that group.
# That means, as long as you do not want to use another repcap value, you can use the method overloads without the repcaps.
# Example (see more in the actual code):
# var tr3 = fsw.display.window.subwindow.trace.clone()
# tr3.repcap_trace_set(repcap.Trace.Tr2)
# Now the following two calls send the same SCPI command: DISPlay1:WINDow:SUBWindow1:TRACe3:MODE MAXHold
# fsw.display.window.subwindow.trace.mode.set(enums.TraceModeCenum.MAXHold, repcap.WindowRepCap.Nr1, repcap.SubWindowRepCap.Nr1, repcap.TraceRepCap.Tr3)
# tr3.mode.set(enums.TraceModeCenum.MAXHold)

# Preconditions:
# - Install the RsFsw driver package over Packet Manager from NuGet.org
# - Adjust the IP address the match your instrument

from RsFsw import *

# A good practice is to check for the installed version
RsFsw.assert_minimum_version('5.0.0')

# Open the session
fsw = RsFsw('TCPIP::192.168.1.102::HISLIP', reset=True)
# Greetings, stranger...
print(f'Hello, I am: {fsw.utilities.idn_string}')

fsw = RsFsw("TCPIP::localhost::HISLIP", True, True)
# fsw = RsFsw("TCPIP::localhost::HISLIP", True, True, options='SelectVisa=RsVisa')  # Forcing R&S VISA
# fsw = RsFsw("TCPIP::localhost::5025::SOCKET", True, True, options='SelectVisa=SocketIo')  # No VISA installation needed

# Driver's instrument status checking ( SYST:ERR? ) after each command (default value is true):
fsw.utilities.instrument_status_checking = True

#   SYSTem:DISPlay:UPDate ON
fsw.system.display.update.set(True)

#   INITiate:CONTinuous OFF
fsw.initiate.continuous.set(True)
print('Always work in single-sweep mode.')

#   SENSe.FREQuency:STARt 100000000
fsw.sense.frequency.start.set(100E6)

#   SENSe.FREQuency:STOP 200000000
fsw.sense.frequency.stop.set(200E6)

#   DISPlay:WINDow:TRACe:Y:SCALe:RLEVel -20.0
fsw.display.window.trace.y.scale.refLevel.set(-20.0)

#   DISPlay:WINDow:SUBWindow:TRACe:Y:SCALe 60.0
fsw.display.window.subwindow.trace.y.scale.set(60.0)

# Prepare tr1 and tr2 to work with the trace 1 and trace 2 interfaces:
tr1 = fsw.display.window.subwindow.trace.clone()
tr1.repcap_trace_set(repcap.Trace.Tr1)
tr2 = fsw.display.window.subwindow.trace.clone()
tr2.repcap_trace_set(repcap.Trace.Tr2)

# Standard usage with all the repcaps defined in the method call:
#   DISPlay1:WINDow:SUBWindow:TRACe1:MODE MAXHold
fsw.display.window.subwindow.trace.mode.set(enums.TraceModeC.MAXHold, repcap.Window.Nr1, repcap.SubWindow.Nr1, repcap.Trace.Tr1)
# Now the following call sends the same command:
tr1.mode.set(enums.TraceModeC.MAXHold)

#   DISPlay1:WINDow:SUBWindow:TRACe2:MODE MINHold
fsw.display.window.subwindow.trace.mode.set(enums.TraceModeC.MINHold, repcap.Window.Nr1, repcap.SubWindow.Nr1, repcap.Trace.Tr2)
# Now the following call sends the same command:
tr2.mode.set(enums.TraceModeC.MINHold)

#   SENSe:SWEep:POINts 10001
fsw.sense.sweep.points.set(10001)

#   INITiate:IMMediate (set timeout 3000 ms)
fsw.initiate.immediate_with_opc(3000)

#            TRACe1:DATA?
trace1 = fsw.trace.data.get(enums.TraceNumber.TRACe1)

#            TRACe2:DATA?
trace2 = fsw.trace.data.get(enums.TraceNumber.TRACe2)

#   CALCulate1:MARKer1:TRACe 1
fsw.calculate.marker.trace.set(1, repcap.Window.Nr1, repcap.Marker.Nr1)
mark1 = fsw.calculate.marker.clone()
mark1.RepCapMarker = repcap.Marker.Nr1

#   CALCulate1:MARKer1:MAXimum:PEAK
fsw.calculate.marker.maximum.peak.set(repcap.Window.Nr1, repcap.Marker.Nr1)
# Same command with the mark1 interface:
mark1.maximum.peak.set()

#         CALCulate1:MARKer1:X?
m1x = fsw.calculate.marker.x.get(repcap.Window.Nr1, repcap.Marker.Nr1)
# Same command with the mark1 interface:
m1x = mark1.x.get()

#         CALCulate1:MARKer1:Y?
m1y = fsw.calculate.marker.y.get(repcap.Window.Nr1, repcap.Marker.Nr1)
# Same command with the mark1 interface:
m1y = mark1.y.get()

print(f'Trace 1 points: {len(trace1)}')
print(f'Trace 1 Marker 1: {m1x} Hz, {m1y} dBm')

#   CALCulate1:MARKer2:TRACe 2
fsw.calculate.marker.trace.set(2, repcap.Window.Nr1, repcap.Marker.Nr2)
mark2 = fsw.calculate.marker.clone()
mark2.RepCapMarker = repcap.Marker.Nr2

#   CALCulate1:MARKer2:MINimum:PEAK
fsw.calculate.marker.minimum.peak.set(repcap.Window.Nr1, repcap.Marker.Nr2)
# Same effect with the mark2 interface:
mark2.minimum.peak.set()

#         CALCulate2:MARKer2:X?
m2x = fsw.calculate.marker.x.get(repcap.Window.Nr1, repcap.Marker.Nr2)
# Same effect with the mark1 interface:
m2x = mark2.x.get()

#         CALCulate2:MARKer2:Y?
m2y = fsw.calculate.marker.y.get(repcap.Window.Nr1, repcap.Marker.Nr2)
# Same command with the mark1 interface:
m2y = mark2.y.get()

print(f'Trace 2 points: {len(trace2)}')
print(f'Trace 2 Marker 2: {m2x} Hz, {m2y} dBm')

# Close the session
fsw.close()