Skip to content

Commit

Permalink
added waitForField() to ips120.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hinnefe2 committed May 10, 2016
1 parent 1132378 commit 01fb8cc
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions labdrivers/oxford/ips120.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand All @@ -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]'
Expand All @@ -73,39 +74,39 @@ 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')


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]'
Expand All @@ -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]'
Expand All @@ -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)
Expand All @@ -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))

Expand All @@ -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']"

Expand All @@ -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

0 comments on commit 01fb8cc

Please sign in to comment.