Skip to content

Rhode&Schwarz Source

Bases: VisaDriver

A driver for controlling Rohde & Schwarz signal generators via the VISA interface.

This class provides methods to control and query the Rohde & Schwarz signal generators, including setting and querying the output power, frequency, and output state.

Parameters:

Name Type Description Default
resource_location str

The VISA resource name used to connect to the device.

required

Initialize the RhodeSchwarzSource object with the specified resource location.

The constructor configures the communication termination character as a newline character.

Parameters:

Name Type Description Default
resource_location str

The VISA resource name used to connect to the device.

required
Source code in driverlib/rhode_schwarz/rs_source.py
18
19
20
21
22
23
24
25
26
def __init__(self, resource_location: str):
    """Initialize the RhodeSchwarzSource object with the specified resource location.

    The constructor configures the communication termination character as a newline character.

    Args:
        resource_location (str): The VISA resource name used to connect to the device.
    """
    super().__init__(resource_location, "\n")

idn property

idn

Retrieve the identification string.

Returns:

Name Type Description
str str

The identification string of the device.

close

close()

Close the connection to the device.

Source code in driverlib/visa_driver.py
114
115
116
def close(self):
    """Close the connection to the device."""
    self.rm.close()

get_error

get_error()

Retrieve the error message from the device.

Returns:

Name Type Description
str

The error message.

Source code in driverlib/visa_driver.py
127
128
129
130
131
132
133
def get_error(self):
    """Retrieve the error message from the device.

    Returns:
        str: The error message.
    """
    return self.ask("SYST:ERR?")

print_error

print_error()

Print eventual errors occurred.

Source code in driverlib/visa_driver.py
135
136
137
def print_error(self):
    """Print eventual errors occurred."""
    print(f"Errors: {self.get_error()}", end="")

reset

reset()

Reset instrument to factory default state. Does not clear volatile memory.

Source code in driverlib/visa_driver.py
139
140
141
142
def reset(self):
    """Reset instrument to factory default state. Does not clear volatile memory."""
    self.write("*RST")
    self.write("*WAI")

clear

clear()

Clear event register, error queue -when power is cycled-.

Source code in driverlib/visa_driver.py
144
145
146
147
def clear(self):
    """Clear event register, error queue -when power is cycled-."""
    self.write("*CLS")
    self.write("*WAI")

lookup_resources

lookup_resources()

Look for all the available resources.

Source code in driverlib/visa_driver.py
149
150
151
152
153
154
155
156
157
158
159
160
def lookup_resources(self):
    """Look for all the available resources."""
    instruments = self.rm.list_resources()
    print(f"Found {len(instruments)} instruments:")
    for location in instruments:
        try:
            with OpenResource(self.rm, location, self.endline) as instr:
                idn = instr.query("*IDN?")
        except VisaIOError:
            idn = None

        print(f"Resource named: {idn if idn else 'Unable to determine'} @ '{location}'")

get_power

get_power()

Query the output power of the signal generator.

Returns:

Name Type Description
float

The output power in dBm.

Source code in driverlib/rhode_schwarz/rs_source.py
28
29
30
31
32
33
34
def get_power(self):
    """Query the output power of the signal generator.

    Returns:
        float: The output power in dBm.
    """
    return float(self.ask(":POW?"))

set_power

set_power(value)

Set the output power of the signal generator.

Parameters:

Name Type Description Default
value float

The desired output power in dBm.

required
Source code in driverlib/rhode_schwarz/rs_source.py
36
37
38
39
40
41
42
def set_power(self, value):
    """Set the output power of the signal generator.

    Args:
        value (float): The desired output power in dBm.
    """
    self.write(":POW " + str(value))

get_frequency

get_frequency()

Query the frequency of the signal generator.

Returns:

Name Type Description
float

The frequency in Hz.

Source code in driverlib/rhode_schwarz/rs_source.py
46
47
48
49
50
51
52
def get_frequency(self):
    """Query the frequency of the signal generator.

    Returns:
        float: The frequency in Hz.
    """
    return float(self.ask(":FREQ?"))

set_frequency

set_frequency(value)

Set the frequency of the signal generator.

Parameters:

Name Type Description Default
value float

The desired frequency in Hz.

required
Source code in driverlib/rhode_schwarz/rs_source.py
54
55
56
57
58
59
60
def set_frequency(self, value):
    """Set the frequency of the signal generator.

    Args:
        value (float): The desired frequency in Hz.
    """
    self.write(f":FREQ {value:.0f}")

get_output

get_output()

Query the output state of the signal generator.

Returns:

Name Type Description
bool bool

True if the output is enabled, False otherwise.

Source code in driverlib/rhode_schwarz/rs_source.py
64
65
66
67
68
69
70
def get_output(self) -> bool:
    """Query the output state of the signal generator.

    Returns:
        bool: True if the output is enabled, False otherwise.
    """
    return bool(int(self.ask("OUTP?")))

set_output

set_output(value)

Set the output state of the signal generator.

Parameters:

Name Type Description Default
value bool | ON | OFF | 0 | 1

The desired output state. True to enable the output, False to disable it.

required
Source code in driverlib/rhode_schwarz/rs_source.py
72
73
74
75
76
77
78
79
80
81
def set_output(self, value: ONOFF_TYPE):
    """Set the output state of the signal generator.

    Args:
        value (bool | ON | OFF | 0 | 1): The desired output state. True to enable the output, False to disable it.
    """
    if self._value_to_bool(value):
        self.write(":OUTP ON")
    else:
        self.write(":OUTP OFF")

get_modulation

get_modulation()

Query the modulation state the signal generator.

Returns:

Name Type Description
bool bool

True if the modulation output is enabled, False otherwise.

Source code in driverlib/rhode_schwarz/rs_source.py
85
86
87
88
89
90
91
def get_modulation(self) -> bool:
    """Query the modulation state the signal generator.

    Returns:
        bool: True if the modulation output is enabled, False otherwise.
    """
    return bool(int(self.ask("MOD:STAT?")))

set_modulation

set_modulation(value)

Turn on or off the modulation output state of the signal generator.

Parameters:

Name Type Description Default
value bool | ON | OFF | 0 | 1

The desired output state. True to enable the output, False to disable it.

required
Source code in driverlib/rhode_schwarz/rs_source.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
def set_modulation(self, value: ONOFF_TYPE):
    """Turn on or off the modulation output state of the signal generator.

    Args:
        value (bool | ON | OFF | 0 | 1): The desired output state. True to enable the output, False to disable it.
    """
    if self._value_to_bool(value):
        self.write("MOD:STAT ON")
    else:
        self.write("MOD:STAT OFF")

get_modulation_frequency

get_modulation_frequency()

Get the modulation frequency of the signal generator.

Returns:

Name Type Description
float

Frequency of the modulation in Hz.

Source code in driverlib/rhode_schwarz/rs_source.py
106
107
108
109
110
111
112
def get_modulation_frequency(self):
    """Get the modulation frequency of the signal generator.

    Returns:
        float: Frequency of the modulation in Hz.
    """
    return float(self.ask("LFO1:FREQ?"))

set_modulation_frequency

set_modulation_frequency(value)

Set the modulation frequency of the signal generator.

Parameters:

Name Type Description Default
value float

The desired modulation frequency in Hz.

required
Source code in driverlib/rhode_schwarz/rs_source.py
114
115
116
117
118
119
120
def set_modulation_frequency(self, value: float):
    """Set the modulation frequency of the signal generator.

    Args:
        value (float): The desired modulation frequency in Hz.
    """
    self.write(f"LFO1:FREQ {value}")

get_phase_modulation_state

get_phase_modulation_state()

Query the phase modulation state of the signal generator.

Returns:

Name Type Description
bool

True if phase modulation is enabled, False otherwise.

Source code in driverlib/rhode_schwarz/rs_source.py
124
125
126
127
128
129
130
def get_phase_modulation_state(self):
    """Query the phase modulation state of the signal generator.

    Returns:
        bool: True if phase modulation is enabled, False otherwise.
    """
    return bool(int(self.ask("PM:STAT?")))

set_phase_modulation_state

set_phase_modulation_state(value)

Set the phase modulation state of the signal generator.

Parameters:

Name Type Description Default
value bool | ON | OFF | 0 | 1

The desired phase modulation state. True to enable phase modulation, False to disable it.

required
Source code in driverlib/rhode_schwarz/rs_source.py
132
133
134
135
136
137
138
139
140
141
142
def set_phase_modulation_state(self, value: ONOFF_TYPE):
    """Set the phase modulation state of the signal generator.

    Args:
        value (bool | ON | OFF | 0 | 1): The desired phase modulation state.
            True to enable phase modulation, False to disable it.
    """
    if self._value_to_bool(value):
        self.write("PM:STAT ON")
    else:
        self.write("PM:STAT OFF")

set_amplitude_modulation_state

set_amplitude_modulation_state(value)

Set the amplitude modulation state of the signal generator.

Parameters:

Name Type Description Default
value bool | ON | OFF | 0 | 1

The desired amplitude modulation state. True to enable amplitude modulation, False to disable it.

required
Source code in driverlib/rhode_schwarz/rs_source.py
146
147
148
149
150
151
152
153
154
155
156
def set_amplitude_modulation_state(self, value: ONOFF_TYPE):
    """Set the amplitude modulation state of the signal generator.

    Args:
        value (bool | ON | OFF | 0 | 1): The desired amplitude modulation state.
            True to enable amplitude modulation, False to disable it.
    """
    if self._value_to_bool(value):
        self.write("AM:STAT ON")
    else:
        self.write("AM:STAT OFF")

get_amplitude_modulation_state

get_amplitude_modulation_state()

Query the amplitude modulation state of the signal generator.

Returns:

Name Type Description
bool

True if amplitude modulation is enabled, False otherwise.

Source code in driverlib/rhode_schwarz/rs_source.py
158
159
160
161
162
163
164
def get_amplitude_modulation_state(self):
    """Query the amplitude modulation state of the signal generator.

    Returns:
        bool: True if amplitude modulation is enabled, False otherwise.
    """
    return bool(int(self.ask("AM:STAT?")))

set_phase_modulation_source

set_phase_modulation_source(value)

Set the phase modulation source of the signal generator.

Parameters:

Name Type Description Default
value Literal['INT', 'EXT']

The desired phase modulation source. Must be either "INT" or "EXT".

required
Source code in driverlib/rhode_schwarz/rs_source.py
168
169
170
171
172
173
174
175
176
177
def set_phase_modulation_source(self, value: Literal["INT", "EXT"]):
    """Set the phase modulation source of the signal generator.

    Args:
        value (Literal["INT", "EXT"]): The desired phase modulation source.
            Must be either "INT" or "EXT".
    """
    if value not in {"INT", "EXT"}:
        raise ValueError("Invalid value. Must be 'INT' or 'EXT'")
    self.write(f"PM:SOUR {value}")

get_phase_modulation_source

get_phase_modulation_source()

Query the phase modulation source of the signal generator.

Returns:

Name Type Description
str

The current phase modulation source. Either "INT" or "EXT".

Source code in driverlib/rhode_schwarz/rs_source.py
179
180
181
182
183
184
185
def get_phase_modulation_source(self):
    """Query the phase modulation source of the signal generator.

    Returns:
        str: The current phase modulation source. Either "INT" or "EXT".
    """
    return self.ask("PM:SOUR?")