diff --git a/labdrivers/oxford/ips120.py b/labdrivers/oxford/ips120.py index 6a94387..13f43c1 100644 --- a/labdrivers/oxford/ips120.py +++ b/labdrivers/oxford/ips120.py @@ -14,6 +14,7 @@ ips120: a class for interfacing with a IPS 120-10 magnet power supply """ +import datetime as dt import time import logging @@ -46,7 +47,7 @@ def __init__(self, GPIBaddr): """Connect to an IPS 120-10 at the specified GPIB address Args: - - GPIBaddr(int): GPIB address of the IPS 120-10 + GPIBaddr(int): GPIB address of the IPS 120-10 """ self._visa_resource = resource_manager.open_resource("GPIB::%d" % GPIBaddr) self.setDisplay('tesla') @@ -61,7 +62,7 @@ def setControl(self, state=3): 3 - Remote & Locked Args: - - state(int): the state in which to place the IPS 120-10 + state(int): the state in which to place the IPS 120-10 """ assert type(state) == int, 'argument must be integer' assert state in [0,1,2,3], 'argument must be one of [0,1,2,3]' @@ -73,25 +74,25 @@ def readField(self): """Read the current magnetic field in Tesla Returns: - - field(float): current magnetic field in Tesla + field(float): current magnetic field in Tesla """ return self._visa_resource.query_ascii_values('R 7') - def readSetpoint(self): + def readFieldSetpoint(self): """Read the current set point for the magnetic field in Tesla Returns: - - field(float): current set point for the magnetic field in Tesla + setpoint(float): current set point for the magnetic field in Tesla """ return self._visa_resource.query_ascii_values('R 8') - def readSweepRate(self): + def readFieldSweepRate(self): """Read the current magnetic field sweep rate in Tesla/min Returns: - - field(float): current magnetic field sweep rate in Tesla/min + sweep_rate(float): current magnetic field sweep rate in Tesla/min """ return self._visa_resource.query_ascii_values('R 9') @@ -99,13 +100,13 @@ def readSweepRate(self): def setActivity(self, state=1): """Set the field activation method - 0 - Hold - 1 - To Set Point - 2 - To Zero + 0 - Hold + 1 - To Set Point + 2 - To Zero 3 - Clamp (clamp the power supply output) Args: - - state(int): the field activation method + state(int): the field activation method """ assert type(state) == int, 'argument must be integer' assert state in [0,1,2,3], 'argument must be one of [0,1,2,3]' @@ -120,7 +121,7 @@ def setHeater(self, state=1): 2 - Heater On, no checks (open switch) Args: - - state(int): the switch heater activation state + state(int): the switch heater activation state """ assert type(state) == int, 'argument must be integer' assert state in [0,1,2], 'argument must be one of [0,1,2]' @@ -133,7 +134,7 @@ def setFieldSetpoint(self, field): """Set the magnetic field set point, in Tesla Args: - - field(float): the magnetic field set point, in Tesla + field(float): the magnetic field set point, in Tesla """ MAX_FIELD = 8 assert abs(field) < MAX_FIELD, 'field must be less than {}'.format(MAX_FIELD) @@ -145,7 +146,7 @@ def setFieldSweepRate(self, rate): """Set the magnetic field sweep rate, in Tesla/min Args: - - rate(float): the magnetic field sweep rate, in Tesla/min + rate(float): the magnetic field sweep rate, in Tesla/min """ self._visa_resource.write("T{}".format(i)) @@ -154,7 +155,7 @@ def setDisplay(self, display): """Set the display to show amps or tesla Args: - - display(str): One of ['amps','tesla'] + display(str): One of ['amps','tesla'] """ assert display in ['amps','tesla'], "argument must be one of ['amps','tesla']" @@ -163,3 +164,29 @@ def setDisplay(self, display): } self._visa_resource.write("M{}".format(mode_dict[display])) + + + def waitForField(self, timeout=600, error_margin=0.01): + """Wait for the field to reach the set point + + Args: + timeout(int): maximum time to wait, in seconds + error_margin(float): how close the field needs to be to the set point, in tesla + + Returns: + (bool): whether the field set point was reached + """ + + start_time = dt.now() + stop_time = start_time + dt.timedelta(seconds=timeout) + + while dt.now() < stop_time: + field = self.readField() + set_point = self.readFieldSetpoint() + + if abs(field - set_point) < error_margin: + return True + + time.sleep(5) + + return False