# American Magnetics 430

Control the American Magnetics 430 power supply from Python with the `AMI430` driver.

**Driver:** [pymeasure](https://pymeasure.readthedocs.io)  
**Type:** [Power supplies](https://dev.nominal.io/instro/instruments/type/psu.md)  
**Manufacturer:** [American Magnetics](https://dev.nominal.io/instro/instruments/manufacturer/american-magnetics.md)

Represents the AMI 430 Power supply and provides a high-level for interacting with the instrument.

## Publishing through instro

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

with PymeasureInstrument(
    name="magnet",
    instrument=AMI430("TCPIP::web.address.com::7180::SOCKET"),
    dataset_rid="<dataset rid>",
) as magnet:

    magnet.device.coilconst = 1.182                 # kGauss/A
    magnet.device.voltage_limit = 2.2               # Sets the voltage limit in V

    magnet.device.target_current = 10               # Sets the target current to 10 A
    magnet.device.target_field = 1                  # Sets target field to 1 kGauss

    magnet.device.ramp_rate_current = 0.0357       # Sets the ramp rate in A/s
    magnet.device.ramp_rate_field = 0.0422         # Sets the ramp rate in kGauss/s
    magnet.device.ramp                             # Initiates the ramping
    magnet.device.pause                            # Pauses the ramping
    magnet.device.status                           # Returns the status of the magnet

    magnet.device.ramp_to_current(5)             # Ramps the current to 5 A

    magnet.device.shutdown()                     # Ramps the current to zero and disables output
```

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

magnet = AMI430("TCPIP::web.address.com::7180::SOCKET")
recorder = attach(magnet, "magnet", [NominalCorePublisher(dataset_rid="<dataset rid>")])

magnet.coilconst = 1.182                 # kGauss/A
magnet.voltage_limit = 2.2               # Sets the voltage limit in V

magnet.target_current = 10               # Sets the target current to 10 A
magnet.target_field = 1                  # Sets target field to 1 kGauss

magnet.ramp_rate_current = 0.0357       # Sets the ramp rate in A/s
magnet.ramp_rate_field = 0.0422         # Sets the ramp rate in kGauss/s
magnet.ramp                             # Initiates the ramping
magnet.pause                            # Pauses the ramping
magnet.status                           # Returns the status of the magnet

magnet.ramp_to_current(5)             # Ramps the current to 5 A

magnet.shutdown()                     # Ramps the current to zero and disables output

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

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