# Agilent 33500

Control the Agilent 33500 function generator from Python with the `Agilent33500` driver.

**Driver:** [pymeasure](https://pymeasure.readthedocs.io)  
**Type:** [Function and waveform generators](https://dev.nominal.io/instro/instruments/type/awg.md)  
**Manufacturer:** [Agilent](https://dev.nominal.io/instro/instruments/manufacturer/agilent.md)

Represents the Agilent 33500 Function/Arbitrary Waveform Generator family.

## Publishing through instro

instro publishes the commands you send to a Agilent33500 and the values you read from it, through any [publisher](https://dev.nominal.io/instro/library/publishers.md). It takes two forms, both described in the [pymeasure guide](https://dev.nominal.io/instro/library/pymeasure.md). Install with `uv add "instro[pymeasure]"`.

### With a PymeasureInstrument

[`PymeasureInstrument`](https://dev.nominal.io/instro/library/pymeasure.md#write-new-instro-code) wraps the driver in an instro instrument, with tags and background polling. The instrument is created inside the `with` block, and `.device` is the pymeasure instrument.

```python
from pymeasure.instruments.agilent import Agilent33500
from instro.pymeasure import PymeasureInstrument

with PymeasureInstrument(
    name="generator",
    instrument=Agilent33500("GPIB::1"),
    dataset_rid="<dataset rid>",
) as generator:

    generator.device.shape = 'SIN'                 # Sets default channel output signal shape to sine
    generator.device.channels[1].shape = 'SIN'           # Sets channel 1 output signal shape to sine
    generator.device.frequency = 1e3               # Sets default channel output frequency to 1 kHz
    generator.device.channels[1].frequency = 1e3         # Sets channel 1 output frequency to 1 kHz
    generator.device.channels[2].amplitude = 5           # Sets channel 2 output amplitude to 5 Vpp
    generator.device.channels[2].output = 'on'           # Enables channel 2 output

    generator.device.channels[1].shape = 'ARB'           # Set channel 1 shape to arbitrary
    generator.device.channels[1].arb_srate = 1e6         # Set channel 1 sample rate to 1MSa/s

    generator.device.channels[1].data_volatile_clear()   # Clear channel 1 volatile internal memory
    generator.device.channels[1].data_arb(               # Send data of arbitrary waveform to channel 1
        'test',
        range(-10000, 10000, +20),          # In this case a simple ramp
        data_format='DAC'                   # Data format is set to 'DAC'
     )
    generator.device.channels[1].arb_file = 'test'       # Select the transmitted waveform 'test'
```

### With existing pymeasure code (`attach()`)

[`attach()`](https://dev.nominal.io/instro/library/pymeasure.md#publish-from-existing-code) adds publishing to pymeasure code you already have. The imports, the `attach()` call after the instrument is created, and `recorder.close()` are all that instro adds.

```python
from pymeasure.instruments.agilent import Agilent33500
from instro.lib import NominalCorePublisher
from instro.pymeasure import attach

generator = Agilent33500("GPIB::1")
recorder = attach(generator, "generator", [NominalCorePublisher(dataset_rid="<dataset rid>")])

generator.shape = 'SIN'                 # Sets default channel output signal shape to sine
generator.channels[1].shape = 'SIN'           # Sets channel 1 output signal shape to sine
generator.frequency = 1e3               # Sets default channel output frequency to 1 kHz
generator.channels[1].frequency = 1e3         # Sets channel 1 output frequency to 1 kHz
generator.channels[2].amplitude = 5           # Sets channel 2 output amplitude to 5 Vpp
generator.channels[2].output = 'on'           # Enables channel 2 output

generator.channels[1].shape = 'ARB'           # Set channel 1 shape to arbitrary
generator.channels[1].arb_srate = 1e6         # Set channel 1 sample rate to 1MSa/s

generator.channels[1].data_volatile_clear()   # Clear channel 1 volatile internal memory
generator.channels[1].data_arb(               # Send data of arbitrary waveform to channel 1
    'test',
    range(-10000, 10000, +20),          # In this case a simple ramp
    data_format='DAC'                   # Data format is set to 'DAC'
 )
generator.channels[1].arb_file = 'test'       # Select the transmitted waveform 'test'

recorder.close()  # flush and close the publishers
```

The examples are adapted from the [pymeasure documentation for `Agilent33500`](https://pymeasure.readthedocs.io/en/latest/api/instruments/agilent/agilent33500.html#pymeasure.instruments.agilent.agilent33500.Agilent33500), which lists every property and method.
