# Tektronix AFG3152C

Control the Tektronix AFG3152C function generator from Python with the `AFG3152C` driver.

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

Represents the Tektronix AFG 3000 series (one or two channels) arbitrary function generator and provides a high-level for interacting with the instrument.

## Publishing through instro

instro publishes the commands you send to a AFG3152C 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.tektronix import AFG3152C
from instro.pymeasure import PymeasureInstrument

with PymeasureInstrument(
    name="afg",
    instrument=AFG3152C("GPIB::1"),
    dataset_rid="<dataset rid>",
) as afg:
    afg.device.reset()                    # Reset to default
    afg.device.ch1.shape='sinusoidal'     # Sinusoidal shape
    afg.device.ch1.unit='VPP'             # Sets CH1 unit to VPP
    afg.device.ch1.amp_vpp=1              # Sets the CH1 level to 1 VPP
    afg.device.ch1.frequency=1e3          # Sets the CH1 frequency to 1KHz
    afg.device.ch1.enable()               # Enables the output from CH1
```

### 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.tektronix import AFG3152C
from instro.lib import NominalCorePublisher
from instro.pymeasure import attach

afg=AFG3152C("GPIB::1")        # AFG on GPIB 1
recorder = attach(afg, "afg", [NominalCorePublisher(dataset_rid="<dataset rid>")])
afg.reset()                    # Reset to default
afg.ch1.shape='sinusoidal'     # Sinusoidal shape
afg.ch1.unit='VPP'             # Sets CH1 unit to VPP
afg.ch1.amp_vpp=1              # Sets the CH1 level to 1 VPP
afg.ch1.frequency=1e3          # Sets the CH1 frequency to 1KHz
afg.ch1.enable()               # Enables the output from CH1

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

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