ARBITRARY_AFG31000
Python Code
from flojoy import flojoy, OrderedPair, TextBlob, VisaConnection, Vector
from typing import Literal
from numpy import max, min
@flojoy(inject_connection=True)
def ARBITRARY_AFG31000(
input: OrderedPair | Vector,
connection: VisaConnection,
memory_state: Literal["EMEM1", "EMEM2"] = "EMEM1",
source: Literal["1", "2"] = "1",
frequency: float = 1e6,
amplitude: float = 1,
offset: float = 0,
phase: float = 0,
) -> TextBlob:
"""Take the input waveform and use it as the arbitrary wavefunction.
This block should also work with compatible Tektronix AFG31XXX instruments.
Parameters
----------
connection: VisaConnection
The VISA address (requires the CONNECTION_AFG31000 block).
memory_state: select, default=EMEM1
Save the function in "Edit Memory" 1 or 2.
channel: select, default=1
Choose the channel to use with the waveform.
frequency: float, default=1e6
The voltage of the waveform to set, in Hz.
amplitude: float, default=1
The voltage of the waveform to set.
offset: float, default=0
The voltage offset to set the waveform to, in volts.
phase: float, default=0
The phase to set the waveform to, in degrees.
Returns
-------
TextBlob
Placeholder
"""
assert -180.0 <= phase <= 180.0, "The phase must be between -180 and 180 degrees."
afg = connection.get_handle()
match input:
case OrderedPair():
y = input.y
case Vector():
y = input.v
y -= min(y)
y /= max(y)
y *= 16383
afg.write_binary_values(
f"DATA:DATA {memory_state}, ", y, is_big_endian=True, datatype="h"
)
afg.write(f"SOURCE{source}:FUNCTION {memory_state}")
afg.write(f"SOURCE{source}:FREQUENCY {frequency}")
afg.write(f"SOURCE{source}:VOLTAGE:AMPLITUDE {amplitude}")
afg.write(f"SOURCE{source}:VOLTAGE:OFFSET {offset}")
afg.write(f"SOURCE{source}:PHASE:ADJUST {phase}DEG")
return TextBlob(text_blob="Set FG parameters")
Example
In this example, an Tektronix AFG31000 is used to generate an arbitrary waveform.
First the necessary blocks were added:
CONNECT_AFG31000
COPY_AFG31000
ARBITRARY_AFG31000
BASIC_PARAMETERS_AFG31000
OUTPUT_AFG31000
- 3x
BASIC_OSCILLATOR
MULTIPLY
LINE
The instrument address was set for each AFG31000
block. Ensure the OUTPUT_AFG31000
block has channel 1 output turned on. Note the COPY_AFG31000
block is rename PLACEHOLDER
here and it preset for block running order reasons. The BASIC_PARAMETERS_AFG31000
block is used to change frequency, offset, voltage, and phase for a single channel, without changing the function itself.
The blocks were connected as shown and the app was run. The 3 BASIC_OSCILLATOR
blocks were used to generate the arbitrary waveform. Any waveform generated in Flojoy can be used as the input for ARBITRARY_AFG31000
to allow for any output.
An oscilloscope was connected to the AFG31000 resulting in waveform: