Examples
For more examples, visit our Rohde & Schwarz Github repository.
"""
Getting started - how to work with rsrtx Python package.
This example performs the following actions on an RTO Oscilloscope:
- Basic configuration
- Triggers an acquisition and waits for it to finish.
- Fetches the waveforms for channel 1 and paints it into a plot.
The example also shows the corresponding SCPI commands next to the rsrtx calls.
Notice that the python rsrtx interfaces track the SCPI commands structure.
Additionally, the SCPI communication logger into the console shows you the SCPI communication with your RTO.
"""
from rsrtx import *
from rsrtx.enums import *
import matplotlib.pyplot as plt
RsRtx.assert_minimum_version('5.55.0')
# Open the session - adjust the resource name to fit your instrument
rto = RsRtx('TCPIP::10.103.34.49::hislip0')
# Greetings, stranger...
print(f'Hello, I am: {rto.utilities.idn_string}')
# Print commands to the console with the logger
rto.utilities.logger.mode = LoggingMode.On
rto.utilities.logger.log_to_console = True
# SYSTem:DISPlay:UPDate ON
rto.system.display.set_update(True)
# TRIGger:MODE AUTO
rto.trigger.mode.set(trigger_mode=TriggerMode.AUTO)
# TRIGger:EVENT:EVENT SINGle
rto.trigger.event.event.set(class_py=TriggerEventClass.SINGle)
# ACQuire:SRATe:MODE AUTO
rto.acquire.set_symbol_rate(sample_rate=20000000000)
# Create 'Channel' object 'ch1', that always addresses the Analog Channel 1
ch1 = rto.channel.clone()
ch1.repcap_channel_set(channel=repcap.Channel.Ch1)
# CHANnel1:STATe ON
ch1.state.set(True)
# Perform the acquisition, wait for it to finish.
# RUNSingle;*OPC
rto.run.single_and_wait()
# CHANnel1:WAVEFORM1:DATA:HEADer?
data_hdr_ch1 = ch1.waveform.data.header.get()
print(f'Channel 1 data: header:\n'
f'Time Start: {data_hdr_ch1.Start}\n'
f'Time Stop: {data_hdr_ch1.Stop}\n'
f'Record Length: {data_hdr_ch1.Record_Length}\n'
f'Values per Sample: {data_hdr_ch1.Vals_Per_Smp}')
# CHANnel1:WAVEFORM1:DATA:VALues?
wform1 = ch1.waveform.data.values.get()
plt.plot(wform1)
plt.legend(['CH1'])
plt.xlabel("Samples")
plt.ylabel("Amplitude in Volts")
plt.show()
rto.close()
"""
Getting started - how to work with rsrtx Python package.
This example performs the following actions on an RTO Oscilloscope:
- Basic configuration
- Triggers an acquisition and waits for it to finish.
- Fetches the waveforms for channel 1 and 2, and paints them into a plot.
The example also shows the corresponding SCPI commands next to the rsrtx calls.
Notice that the python rsrtx interfaces track the SCPI commands structure.
Additionally, the SCPI communication logger into the console shows you the SCPI communication with your RTO.
"""
from rsrtx import *
from rsrtx.enums import *
import matplotlib.pyplot as plt
RsRtx.assert_minimum_version('5.55.0')
# Open the session - adjust the resource name to fit your instrument
rto = RsRtx('TCPIP::10.103.34.49::hislip0')
# Greetings, stranger...
print(f'Hello, I am: {rto.utilities.idn_string}')
# Print commands to the console with the logger
rto.utilities.logger.mode = LoggingMode.On
rto.utilities.logger.log_to_console = True
# SYSTem:DISPlay:UPDate ON
rto.system.display.set_update(True)
# TRIGger:MODE AUTO
rto.trigger.mode.set(trigger_mode=TriggerMode.AUTO)
# TRIGger:EVENT:EVENT SINGle
rto.trigger.event.event.set(class_py=TriggerEventClass.SINGle)
# ACQuire:SRATe:MODE AUTO
rto.acquire.set_symbol_rate(sample_rate=20000000000)
# Create 'Channel' object 'ch1', that always addresses the Analog Channel 1
ch1 = rto.channel.clone()
ch1.repcap_channel_set(channel=repcap.Channel.Ch1)
# CHANnel1:RANGe 10
ch1.range.set(range_py=10)
# Create 'Channel' object 'ch2', that always addresses the Analog Channel 2
ch2 = rto.channel.clone()
ch2.repcap_channel_set(channel=repcap.Channel.Ch2)
# CHANnel1:RANGe 20
ch2.range.set(range_py=20)
# CHANnel1:STATe ON
ch1.state.set(True)
# CHANnel2:STATe ON
ch2.state.set(True)
# Perform the acquisition, wait for it to finish.
# RUNSingle;*OPC
rto.run.single_and_wait()
# CHANnel1:WAVEFORM1:DATA:HEADer?
data_hdr_ch1 = ch1.waveform.data.header.get()
print(f'Channel 1 data: header:\n'
f'Time Start: {data_hdr_ch1.Start}\n'
f'Time Stop: {data_hdr_ch1.Stop}\n'
f'Record Length: {data_hdr_ch1.Record_Length}\n'
f'Values per Sample: {data_hdr_ch1.Vals_Per_Smp}')
# CHANnel1:WAVEFORM1:DATA:VALues?
wform1 = ch1.waveform.data.values.get()
plt.plot(wform1)
# CHANnel2:WAVEFORM1:DATA:HEADer?
data_hdr_ch2 = ch2.waveform.data.header.get()
print(f'Channel 2 data: header:\n'
f'Time Start: {data_hdr_ch2.Start}\n'
f'Time Stop: {data_hdr_ch2.Stop}\n'
f'Record Length: {data_hdr_ch2.Record_Length}\n'
f'Values per Sample: {data_hdr_ch2.Vals_Per_Smp}')
# CHANnel2:WAVEFORM1:DATA:VALues?
wform2 = ch2.waveform.data.values.get()
plt.plot(wform2)
plt.legend(['CH1', 'CH2'])
plt.xlabel("Samples")
plt.ylabel("Amplitude in Volts")
plt.show()
rto.close()
"""
This example makes a screenshot of the current screen content of an RTO Oscilloscope display,
and transfers it into the host PC.
"""
import os
from pathlib import Path
from rsrtx import *
from rsrtx.enums import *
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
pc_file_name = 'screenshot_pc.png'
instr_file_name = 'screenshot_instr.png'
RsRtx.assert_minimum_version('5.55.0')
# Open the session - adjust the resource name to fit your instrument
rto = RsRtx('TCPIP::10.103.34.49::hislip0')
# Greetings, stranger...
print(f'Hello, I am: {rto.utilities.idn_string}')
rto.utilities.visa_timeout = 5000
rto.system.display.set_update(True)
rto.hardCopy.set_destination(medium='MMEM')
rto.hardCopy.device.set_language(PictureFileFormat.PNG)
current_dir = rto.massMemory.get_current_directory()
instr_file_path = current_dir + '\\' + instr_file_name
rto.massMemory.set_name(instr_file_path)
rto.hardCopy.immediate.perform()
file_content = rto.utilities.read_file_from_instrument_to_pc(instr_file_path, pc_file_name)
full_instr_file_path = Path(__file__).resolve().with_name(instr_file_name)
print(f'Screenshot file saved to "{pc_file_name}". Full Path: "{full_instr_file_path}"')
rto.close()
# Show the screenshot picture
img = mpimg.imread(pc_file_name)
plt.imshow(img)
plt.show()