Skip to content

Arbitrary Waveform Generator (AWG)¤

This category ships in the instro-unstable package (instro[unstable]); its API is not settled and may change without notice.

Errors raised by these methods are documented in Exceptions.

Interface¤

Bases: Instrument

AWG instrument. Methods return Measurement/Command for publishing.

name instance-attribute ¤

name = name

legacy_naming instance-attribute ¤

legacy_naming = legacy_naming

publishers instance-attribute ¤

publishers = publishers or []

default_tags instance-attribute ¤

default_tags: dict[str, str] = {}

background_interval property writable ¤

background_interval

Seconds between background daemon iterations (0 = no wait).

channel_names property ¤

channel_names: tuple[str, ...]

Return an insertion-ordered snapshot of all published channel names.

Names are complete after one full daemon iteration: {name}.loop_time publishes every iteration, so call get_channel("loop_time", wait_for_new_samples=True) then read channel_names to ensure the complete set has arrived.

Raises:

  • RuntimeError

    No background buffer; start() was not called.

add_publisher ¤

add_publisher(publisher: Publisher)

Register a publisher to receive this instrument's Measurement/Command data.

publish ¤

publish(data: Measurement | Command, **kwargs)

Fan data out to every configured publisher; kwargs pass through.

add_background_daemon_function ¤

add_background_daemon_function(method: Callable, *args, **kwargs)

Append method to the daemon's call list. Use define_background_daemon to replace instead.

stop ¤

stop()

Signal the background daemon to stop and join it. No-op if not running.

get_channel ¤

get_channel(
    channel_name: str,
    length: int = 1,
    wait_for_new_samples: bool = False,
    timeout: float = 10.0,
) -> Measurement

Return the most recent length samples for channel_name from the in-memory buffer.

If the channel does not exist yet, or no sample is available, the code will always block until timeout expires.

Parameters:

  • channel_name ¤

    (str) –

    Name of the channel to retrieve.

  • length ¤

    (int, default: 1 ) –

    Number of trailing samples to return.

  • wait_for_new_samples ¤

    (bool, default: False ) –

    Block until at least length new values arrive.

  • timeout ¤

    (float, default: 10.0 ) –

    Seconds to wait when insufficient data exists or wait_for_new_samples=True.

Raises:

  • RuntimeError

    No background buffer; start() was not called.

  • ChannelNotFoundError

    channel had no values and no data appeared before timeout. wait_for_new_samples=True and channel did not appear within timeout.

  • ChannelValueTimeoutError

    wait_for_new_samples=True and values did not arrive within timeout.

get_single_channel_value ¤

get_single_channel_value(channel_name: str) -> float | None

Return the most recent sample for channel_name from the in-memory buffer.

This will not wait, if data is not available then None is returned.

Parameters:

  • channel_name ¤

    (str) –

    Name of the channel to retrieve.

Raises:

  • RuntimeError

    No background buffer; start() was not called.

define_background_daemon ¤

define_background_daemon(method: Callable, *args, **kwargs)

Replace all daemon functions with a single method (called with the given args).

start ¤

start() -> None

Start the background daemon; raises unless set_waveform was called for at least one channel.

open ¤

open() -> None

Open the underlying driver.

close ¤

close() -> None

Close the underlying driver.

set_waveform ¤

set_waveform(channel: int, waveform: Waveform, **kwargs) -> Command

Program channel with the waveform definition; numeric shape parameters publish as companion channels.

get_waveform ¤

get_waveform(channel: int) -> Waveform

Read back the current waveform definition on channel.

set_amplitude ¤

set_amplitude(
    channel: int,
    amplitude: float,
    unit: AmplitudeMeasurementUnit,
    **kwargs,
) -> Command

Set the output amplitude on channel; the unit ships as a unit tag.

get_amplitude ¤

get_amplitude(channel: int) -> tuple[float, AmplitudeMeasurementUnit]

Read back the current amplitude and its measurement unit on channel.

convert_amplitude ¤

convert_amplitude(
    channel: int,
    amplitude: float,
    from_unit: AmplitudeMeasurementUnit,
    to_unit: AmplitudeMeasurementUnit,
    impedance_ohms: float | None = None,
) -> float

Convert an amplitude value between units using channel's configured waveform.

DBM conversions need a load impedance; if impedance_ohms isn't given, channel's output load is used instead. Raises ValueError if neither is available.

set_offset ¤

set_offset(channel: int, offset_v: float, **kwargs) -> Command

Set the DC offset (volts) on channel.

output_enable ¤

output_enable(channel: int, enable: bool, **kwargs) -> Command

Enable or disable the output on channel.

set_output_load ¤

set_output_load(channel: int, load: float | None, **kwargs) -> Command

Set the output load impedance; None means high-Z.

align_phase ¤

align_phase(**kwargs) -> Command

Sync the phase of all channels.

get_offset ¤

get_offset(channel: int, **kwargs) -> Measurement | None

Read back the DC offset (volts) on channel.

get_output_state ¤

get_output_state(channel: int, **kwargs) -> Measurement | None

Read back whether the output is enabled on channel.

get_output_load ¤

get_output_load(channel: int, **kwargs) -> Measurement | None

Read back the output load impedance on channel; high-Z is published as float('inf').

Types & Configuration¤

AWG shared types and waveform definitions.

Waveform module-attribute ¤

Waveform = (
    Sine
    | Square
    | Sawtooth
    | Triangle
    | Pulse
    | Arbitrary
    | StaticValue
)

AmplitudeMeasurementUnit ¤

Bases: Enum

VPP class-attribute instance-attribute ¤

VPP = 'VPP'

VP class-attribute instance-attribute ¤

VP = 'VP'

VRMS class-attribute instance-attribute ¤

VRMS = 'VRMS'

DBM class-attribute instance-attribute ¤

DBM = 'DBM'

Sine dataclass ¤

Sine(frequency_hz: float, phase_deg: float = 0.0)

Sine waveform definition.

frequency_hz instance-attribute ¤

frequency_hz: float

phase_deg class-attribute instance-attribute ¤

phase_deg: float = 0.0

StaticValue dataclass ¤

StaticValue(value: float = 0.0)

Static valued waveform definition.

value class-attribute instance-attribute ¤

value: float = 0.0

Square dataclass ¤

Square(
    frequency_hz: float,
    duty_cycle_pct: float = 50.0,
    phase_deg: float = 0.0,
)

Continuous rectangular wave; high for duty_cycle_pct percent of each period.

frequency_hz instance-attribute ¤

frequency_hz: float

duty_cycle_pct class-attribute instance-attribute ¤

duty_cycle_pct: float = 50.0

phase_deg class-attribute instance-attribute ¤

phase_deg: float = 0.0

Sawtooth dataclass ¤

Sawtooth(frequency_hz: float, phase_deg: float = 0.0)

Sawtooth waveform definition.

frequency_hz instance-attribute ¤

frequency_hz: float

phase_deg class-attribute instance-attribute ¤

phase_deg: float = 0.0

Triangle dataclass ¤

Triangle(frequency_hz: float, phase_deg: float = 0.0)

Triangle waveform definition.

frequency_hz instance-attribute ¤

frequency_hz: float

phase_deg class-attribute instance-attribute ¤

phase_deg: float = 0.0

Pulse dataclass ¤

Pulse(frequency_hz: float, width_s: float, delay_s: float = 0.0)

Continuous rectangular wave (not single-shot); each period goes high for width_s seconds after delay_s.

frequency_hz instance-attribute ¤

frequency_hz: float

width_s instance-attribute ¤

width_s: float

delay_s class-attribute instance-attribute ¤

delay_s: float = 0.0

Arbitrary dataclass ¤

Arbitrary(samples: tuple[float, ...], sample_rate_hz: float)

Arbitrary waveform definition; samples are normalized to [-1, 1] and scaled by amplitude/offset.

samples instance-attribute ¤

samples: tuple[float, ...]

sample_rate_hz instance-attribute ¤

sample_rate_hz: float

convert_amplitude ¤

convert_amplitude(
    value: float,
    from_unit: AmplitudeMeasurementUnit,
    to_unit: AmplitudeMeasurementUnit,
    waveform: Waveform,
    impedance_ohms: float | None = None,
) -> float

Convert an amplitude value between measurement units for a waveform shape.

VPP/VP/VRMS conversions depend on the waveform's crest factor, which is universal math shared across every driver. DBM additionally requires impedance_ohms (the load the instrument drives), since power depends on it.

Driver Interface¤

Bases: ABC

Vendor AWG driver contract. Concrete drivers own their transport and lifecycle.

open abstractmethod ¤

open() -> None

Open the underlying transport.

close abstractmethod ¤

close() -> None

Close the underlying transport.

check_errors abstractmethod ¤

check_errors() -> None

Drain the instrument error queue; raise if any error is pending.

set_waveform abstractmethod ¤

set_waveform(channel: int, waveform: Waveform) -> None

Program channel with the waveform definition; raise ValueError if the definition is unsupported.

get_waveform abstractmethod ¤

get_waveform(channel: int) -> Waveform

Get the current waveform on channel; drivers may return the last-programmed definition if not readable.

set_amplitude abstractmethod ¤

set_amplitude(
    channel: int, amplitude: float, unit: AmplitudeMeasurementUnit
) -> None

Set the output amplitude on channel.

get_amplitude abstractmethod ¤

get_amplitude(channel: int) -> tuple[float, AmplitudeMeasurementUnit]

Get the current output amplitude and voltage unit on channel.

set_offset abstractmethod ¤

set_offset(channel: int, offset: float) -> None

Set the DC offset (volts) on channel.

get_offset abstractmethod ¤

get_offset(channel: int) -> float

Get the DC offset (volts) on channel.

output_enable abstractmethod ¤

output_enable(channel: int, enable: bool) -> None

Enable or disable the output on channel.

get_output_state abstractmethod ¤

get_output_state(channel: int) -> bool

Return True if the output on channel is enabled.

set_output_load ¤

set_output_load(channel: int, load: float | None) -> None

Set the output load impedance; None means high-Z.

get_output_load ¤

get_output_load(channel: int) -> float | None

Get the output load impedance; None means high-Z.

align_phase ¤

align_phase() -> None

Sync the phase of all channels.

Vendor Drivers¤

Rigol DG1022Z¤

Rigol DG1022Z arbitrary waveform generator driver (DG1000Z series).

RigolDG1022Z ¤

RigolDG1022Z(visa_resource: str | VisaConfig)

Bases: AWGDriverBase

SCPI driver for the Rigol DG1022Z two-channel arbitrary waveform generator.

open ¤
open() -> None
close ¤
close() -> None
check_errors ¤
check_errors() -> None

Query :SYSTem:ERRor? once and raise on a non-zero code. Does not drain the queue.

set_waveform ¤
set_waveform(channel: int, waveform: Waveform) -> None
get_waveform ¤
get_waveform(channel: int) -> Waveform
set_amplitude ¤
set_amplitude(
    channel: int, amplitude: float, unit: AmplitudeMeasurementUnit
) -> None
get_amplitude ¤
get_amplitude(channel: int) -> tuple[float, AmplitudeMeasurementUnit]
set_offset ¤
set_offset(channel: int, offset: float) -> None
get_offset ¤
get_offset(channel: int) -> float
output_enable ¤
output_enable(channel: int, enable: bool) -> None
get_output_state ¤
get_output_state(channel: int) -> bool
set_output_load ¤
set_output_load(channel: int, load: float | None) -> None
get_output_load ¤
get_output_load(channel: int) -> float | None
align_phase ¤
align_phase() -> None