# Oxford Instruments Intelligent Power Supply 120-10 for superconducting magnets

class pymeasure.instruments.oxfordinstruments.IPS120_10(adapter, name='Oxford IPS', clear_buffer=True, switch_heater_heating_delay=None, switch_heater_cooling_delay=None, field_range=None, **kwargs)

  Bases: `OxfordInstrumentsBase`

  Represents the Oxford Superconducting Magnet Power Supply IPS 120-10.

      ips = IPS120_10("GPIB::25")  # Default channel for the IPS

      ips.enable_control()         # Enables the power supply and remote control

      ips.train_magnet([           # Train the magnet after it has been cooled-down
          (11.8, 1.0),
          (13.9, 0.4),
          (14.9, 0.2),
          (16.0, 0.1),
      ])

      ips.set_field(12)           # Bring the magnet to 12 T. The switch heater will
                                  # be turned off when the field is reached and the
                                  # current is ramped back to 0 (i.e. persistent mode).

      print(self.field)           # Print the current field (whether in persistent or
                                  # non-persistent mode)

      ips.set_field(0)            # Bring the magnet to 0 T. The persistent mode will be
                                  # turned off first (i.e. current back to set-point and
                                  # switch-heater on); afterwards the switch-heater will
                                  # again be turned off.

      ips.disable_control()       # Disables the control of the supply, turns off the
                                  # switch-heater and clamps the output.

  Parameters:

    - clear_buffer – A boolean property that controls whether the instrument buffer is clear upon initialisation.

    - switch_heater_heating_delay – The time in seconds (default is 20s) to wait after the switch-heater is turned on before the heater is expected to be heated.

    - switch_heater_cooling_delay – The time in seconds (default is 20s) to wait after the switch-heater is turned off before the heater is expected to be cooled down.

    - field_range – A numeric value or a tuple of two values to indicate the lowest and highest allowed magnetic fields. If a numeric value is provided the range is expected to be from `-field_range` to `+field_range`. The default range is -7 to +7 Tesla.

  property activity

    A string property that controls the activity of the IPS. Valid values are “hold”, “to setpoint”, “to zero” and “clamp”

  property control_mode

    A string property that sets the IPS in local or remote and locked or unlocked, locking the LOC/REM button. Allowed values are:

    value | state
    --- | ---
    LL | local & locked
    RL | remote & locked
    LU | local & unlocked
    RU | remote & unlocked

  property current_measured

    A floating point property that returns the measured magnet current of the IPS in amps. (dynamic)

  property current_setpoint

    A floating point property that controls the magnet current set-point of the IPS in ampere. (dynamic)

  property demand_current

    A floating point property that returns the demand magnet current of the IPS in amps. (dynamic)

  property demand_field

    A floating point property that returns the demand magnetic field of the IPS in Tesla. (dynamic)

  disable_control()

    Disable active control of the IPS (if at 0T) by turning off the switch heater, clamping the output and setting control to local. Raise a `MagnetError` if field not at 0T.

  disable_persistent_mode()

    Disable the persistent magnetic field mode. Raise a `MagnetError` if the magnet is not at rest.

  enable_control()

    Enable active control of the IPS by setting control to remote and turning off the clamp.

  enable_persistent_mode()

    Enable the persistent magnetic field mode. Raise a `MagnetError` if the magnet is not at rest.

  property field

    Property that returns the current magnetic field value in Tesla.

  property field_setpoint

    A floating point property that controls the magnetic field set-point of the IPS in Tesla. (dynamic)

  property persistent_field

    A floating point property that returns the persistent magnetic field of the IPS in Tesla. (dynamic)

  set_field(field, sweep_rate=None, persistent_mode_control=True)

    Change the applied magnetic field to a new specified magnitude. If allowed (via persistent_mode_control) the persistent mode will be turned off if needed and turned on when the magnetic field is reached. When the new field set-point is 0, the set-point of the instrument will not be changed but rather the to zero functionality will be used. Also, the persistent mode will not turned on upon reaching the 0T field in this case.

    Parameters:

      - field – The new set-point for the magnetic field in Tesla.

      - sweep_rate – A numeric value that controls the rate with which to change the magnetic field in Tesla/minute.

      - persistent_mode_control – A boolean that controls whether the persistent mode may be turned off (if needed before sweeping) and on (when the field is reached); if set to `False` but the system is in persistent mode, a `MagnetError` will be raised and the magnetic field will not be changed.

  property sweep_rate

    A floating point property that controls the sweep-rate of the IPS in Tesla/minute. (dynamic)

  property sweep_status

    A string property that returns the current sweeping mode of the IPS.

  property switch_heater_enabled

    A boolean property that controls whether the switch heater is enabled or not. When the switch heater is enabled (`True`), the switch is closed and the switch is open and the current in the magnet can be controlled; when the switch heater is disabled (`False`) the switch is closed and the current in the magnet cannot be controlled.

    When turning on the switch heater with `True`, the switch heater is only activated if the current of the power supply matches the last recorded current in the magnet.

    Warning

    These checks can be omitted by using `"Force"` in stead of `True`. Caution: Not performing these checks can cause serious damage to both the power supply and the magnet.

    After turning on the switch heater it is necessary to wait several seconds for the switch the respond.

    Raises a `SwitchHeaterError` if the system reports a ‘heater fault’ or if no switch is fitted on the system upon getting the status.

  property switch_heater_status

    An integer property that returns the switch heater status of the IPS. Use the `switch_heater_enabled` property for controlling and reading the switch heater. When using this property, the user is referred to the IPS120-10 manual for the meaning of the integer values.

  train_magnet(training_scheme)

    Train the magnet after cooling down. Afterwards, set the field back to 0 tesla (at last-used ramp-rate).

    Parameters:

      training_scheme – The training scheme as a list of tuples; each tuple should consist of a (field [T], ramp-rate [T/min]) pair.

  property version

    A string property that returns the version of the IPS.

  wait_for_idle(delay=1, max_wait_time=None, should_stop=<function IPS120_10.<lambda>>)

    Wait until the system is at rest (i.e. current of field not ramping).

    Parameters:

      - delay – Time in seconds between each query into the state of the instrument.

      - max_wait_time – Maximum time in seconds to wait before is at rest. If the system is not at rest within this time a `TimeoutError` is raised. `None` is interpreted as no maximum time.

      - should_stop – A function that returns `True` when this function should return early.

class pymeasure.instruments.oxfordinstruments.ips120_10.MagnetError

  Bases: `ValueError`

  Exception that is raised for issues regarding the state of the magnet or power supply.

class pymeasure.instruments.oxfordinstruments.ips120_10.SwitchHeaterError

  Bases: `ValueError`

  Exception that is raised for issues regarding the state of the superconducting switch.