InstroAWG
InstroAWG is a hardware abstraction layer (HAL) that provides a unified interface for arbitrary waveform generators. The category class defines the vendor-independent API (set_waveform, set_amplitude, get_offset, …). A vendor-specific driver (e.g. RigolDG1022Z) owns its connection details and translates those calls into vendor commands.
Supported Vendors
- Rigol: DG1022Z (DG1000Z series) via SCPI/VISA (
RigolDG1022Z)
Key Concepts
Driver Composition
AnInstroAWG is built from a concrete driver:
RigolDG1022Zowns the connection setup and vendor-specific command mapping.InstroAWGowns the category-level workflow: waveform programming, publishers, the background daemon.
Lifecycle
The typical InstroAWG workflow:- Construct: instantiate the vendor driver and pass it to
InstroAWG, along with the channel count. open(): establishes the VISA connection.- Configure and generate: define a waveform on a channel, set its amplitude and offset, and enable the output.
start(): begins a periodic background daemon that polls output state. (Optional)stop(): ends the background daemon (if started).close(): disconnects from hardware.
Waveform Definitions
Each channel is programmed with aWaveform, one of the frozen dataclasses in instro.unstable.awg:
Each definition should validate its own parameters at construction time (raising ValueError for out-of-range values), so a Waveform is always well-formed before it reaches a driver.
Driver support variesNot every driver supports every waveform or every parameter combination. For example,
RigolDG1022Z raises ValueError for a nonzero Pulse.delay_s, since the DG1000Z command set has no pulse-delay parameter. Consult your instrument’s manual and driver implementation for exact support.Amplitude Units and Conversion
Amplitude is set and read together with anAmplitudeMeasurementUnit: VPP, VP, VRMS, or DBM. Use convert_amplitude() to convert a value between units for a channel’s currently configured waveform:
VPP/VP/VRMS conversions depend on the waveform’s crest factor (shared math, not vendor-specific). Converting to or from DBM additionally requires the load impedance driving the output: pass impedance_ohms explicitly, or let it fall back to the channel’s get_output_load() value if the driver supports it. set_waveform must be called for the channel before converting, since the crest factor depends on the waveform shape.
Modulation
set_modulation(channel, mod_type, shape, magnitude) configures a modulating signal for the channel’s existing output, without turning it on. Terminology matters here: the carrier is the channel’s own waveform, set separately via set_waveform. shape is the modulator: the signal that encodes onto the carrier by varying its amplitude, frequency, phase, or width.
magnitude’s unit, and whether shape’s waveform type has any effect, both depend on mod_type:
Call
modulation_enable(channel, True) to turn on modulation with the last-configured set_modulation() settings, and modulation_enable(channel, False) to turn it back off. It’s independent of set_modulation(): once configured, a channel can be toggled on and off any number of times without reconfiguring, and disabling keeps the configured settings rather than clearing them.
Creating an InstroAWG Instance
Parameters
name: A name for this AWG instance. Used as a prefix for channel names when publishing.driver: A concreteAWGDriverBaseinstance (e.g.RigolDG1022Z) configured with the connection details for that model.num_channels: Number of output channels on the instrument. Must be at least 1.publishers: Optional list of publishers to attach.**kwargs: Additional keyword arguments become default tags when using a publisher that supports tags (likeNominalCorePublisher).
Choosing a Driver
Choose the concrete driver that matches the AWG model, then pass the instrument connection settings to that driver. For Rigol DG1000Z series generators, useRigolDG1022Z with the VISA resource string for the instrument.
To inspect a VISA instrument’s identity before choosing a driver:
Examples
All measurement methods returnMeasurement objects. This is common amongst all Instrument objects.
Basic Usage
Background Daemon for Continuous Monitoring
start()begins a background daemon, executing a function or list of functions periodically.stop()ends the background daemon.
Default AWG Background DaemonFor each :
- Output enabled state (via
get_output_state())
background_interval property. Other readbacks (get_offset(), get_output_load(), waveform parameters) are opt-in: call add_background_daemon_function() to add them to the daemon’s call list.start() raises ValueError unless set_waveform() has been called for at least one channel first.- To define your own background daemon, call
define_background_daemon(method, *args, **kwargs), which replaces the registered daemon functions. - To add a method to the background daemon stack, call
add_background_daemon_function().
Important Note about PublishersData is published as a direct result of an instrument method being called.For example, when you call
get_output_state(), this not only queries the instrument for the output state but also causes all attached Publishers to publish the measurement response automatically.Therefore the background daemon, when calling these instrument methods, is publishing data in the background as well!Published channels
Every measurement/command call produces a channel keyed under{name}.{descriptor}, where {name} is the constructor argument and {descriptor} is the row below. Substitute {N} with the actual channel number (1, 2, …).
Method Reference
Custom Driver Development
This section is for developers implementingInstroAWG support for waveform generators that aren’t supported out of the box.
Overview
Driver developers subclassAWGDriverBase and own whatever transport their instrument needs. The caller chooses a concrete driver, and that concrete driver exposes connection parameters that make sense for its protocol:
InstroAWG’s vendor-independent API (set_waveform, set_amplitude, get_offset, …) into vendor-specific commands.
Driver Responsibilities
An AWG driver must:- Expose a protocol-native constructor: accept inputs like
visa_resource,host,port,unit_id,interface, ornode_id, depending on the instrument. - Own transport setup: create and store the transport internally. Do not require users to pass a
VisaDriver, socket client, Modbus client, or other transport object. - Own lifecycle: implement
open()andclose()by opening and closing the underlying transport. - Map commands: translate each abstract method into vendor-specific commands, raising
ValueErrorfor aWaveformdefinition the instrument can’t produce. - Parse responses: convert instrument responses to the expected Python types (
float,bool,Waveformsubclasses).
AWGDriverBase Interface
All AWG drivers subclassAWGDriverBase and implement these abstract methods:
NotImplementedError by default, for drivers whose instrument doesn’t support them:
check_errors(): if your vendor exposes an error queue, implement check_errors() to drain and raise on it (see the representative driver below).
Talking to the Instrument
Concrete drivers should hide transport details behind private attributes. For VISA-backed drivers, create aVisaDriver internally and use it for all I/O:
self._visa.write(command): Send a SCPI command (no response expected).self._visa.query(command): Send a SCPI query and receive the response string.
VisaDriver owns the resource lock. Concurrent write / query calls against the same driver are serialized automatically; use self._visa.lock() to hold the lock across a multi-command sequence (for example, programming an Arbitrary waveform point-by-point).
See the VisaDriver guide for the full transport reference, covering configuration, terminators, timeouts, serial settings, and the raw-byte I/O path.
Implementation Example: Rigol DG1022Z Driver
Here’s the driver implementation for the Rigol DG1022Z (DG1000Z series) two-channel arbitrary waveform generator:Using a Custom Driver
For drivers that aren’t shipped in the library, constructInstroAWG with your own driver instance. The driver should accept connection settings directly and create its transport internally:
Summary
Driver development requires careful mapping of vendor-specific behavior to the unifiedInstroAWG interface. Focus on:
- Subclassing
AWGDriverBase - Designing a constructor around natural connection parameters for the instrument
- Hiding transport construction inside the driver
- Implementing all abstract methods on
AWGDriverBase, and the optional load/phase methods your instrument supports - Raising
ValueErrorforWaveformdefinitions and parameter combinations the instrument can’t produce - Using the correct vendor protocol or command syntax
- Converting instrument responses to the expected Python types
- Implementing
check_errors()against your vendor’s error queue or status register - Testing with actual hardware to ensure commands work as expected