FREQUENCY_33120A
Python Code
from flojoy import flojoy, DataContainer, String, SerialConnection
from typing import Optional, Literal
@flojoy(inject_connection=True)
def FREQUENCY_33120A(
connection: SerialConnection,
frequency: float = 0.1,
options: Literal["min", "max", "input"] = "input",
default: Optional[DataContainer] = None,
) -> String:
"""Set the output frequency for a 33120A function generator.
Requires an OPEN SERIAL block at the start of the app to connect with
the instrument.
Parameters
----------
connection: SerialConnection
The VISA address (requires a OPEN SERIAL node).
frequency: float
The frequency of the output waveform.
option: Literal
Use the input value, or set to the maximum or minimum.
Returns
-------
DataContainer
String: Summary of waveform generator settings.
"""
instru = connection.get_handle()
match options:
case "input":
write = f"FREQ {frequency}\n"
case "max":
write = "FREQ max\n"
case "min":
write = "FREQ min\n"
instru.write(write.encode())
return String(s=f"{frequency}")
Example App
In this example, a HP 33120A is used to generate a waveform and save the setting for later use.
First the necessary blocks were added and their parameters set:
OPEN_SERIAL
CLEAR BUFFER 33120A
RESET 33120A
IMPEDANCE 33120A
TRIGGER 33120A
VOLT UNIT 33120A
- unit = VPPFUNCTION 33120A
- waveform - squareFREQUENCY 33120A
- frequency - 20000 (Hz)DUTY 33120A
- duty - 60 (%)AMPLITUDE 33120A
- amplitude - 0.2 (Vpp)OFFSET 33120A
- offset - 0.15 (V)SAVE 33120A
RECALL 33120A
ERRORS 33120A
- number - 5TEXT VIEW
If no parameters are specified they were left at default settings. The instrument address was set for each instrument block to the corrent COM port.
The CLEAR BUFFER 33120A
and RESET 33120A
blocks can be important to prevent some errors such as a buffer overflow. The impedance, trigger, volt unit, frequency, duty, amplitude, and offset blocks all set parameters corresponding to the output function. The ERRORS 33120A
will return any errors in the instrument’s buffer (first in first out).
The blocks were connected as shown and the app was run. The SAVE 33120A
block can be used to save the current state of the instrument. When you wish the recall those setting you can use the RECALL 33120A
block. RECALL 33120A
can replace all blocks in the app except OPEN_SERIAL
, CLEAR BUFFER 33120A
, RESET 33120A
, and ERRORS 33120A
(as long as the settings are saved).