Skip to content

Stop the measurement if setting the field timeout #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion exopy_hqc_legacy/instruments/drivers/driver_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class InstrIOError(InstrError):
pass


class InstrTimeoutError(InstrError):
"""Generic error raised when an instrument does not behave as expected
"""
pass


class instrument_property(property):
"""Property allowing to cache the result of a get operation and return it
on the next get. The cache can be cleared.
Expand Down Expand Up @@ -185,6 +191,11 @@ def wait_for_completion(self, break_condition_callable=None, timeout=15,
result : bool
Boolean indicating if the wait succeeded of was interrupted.

Raises
------
InstrTimeoutError:
Raised if the operation timeout.

"""
while True:
remaining_time = (self.expected_waiting_time -
Expand All @@ -205,7 +216,10 @@ def wait_for_completion(self, break_condition_callable=None, timeout=15,
if self.condition_callable():
return True
if remaining_time < 0 or break_condition_callable():
return False
if remaining_time < 0:
raise InstrTimeoutError()
else:
return False

def cancel(self, *args, **kwargs):
"""Cancel the long running job.
Expand Down
14 changes: 10 additions & 4 deletions exopy_hqc_legacy/tasks/tasks/instr/apply_mag_field_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from exopy.tasks.api import InstrumentTask, validators

from exopy_hqc_legacy.instruments.drivers.driver_tools import InstrTimeoutError


class ApplyMagFieldTask(InstrumentTask):
"""Use a supraconducting magnet to apply a magnetic field. Parallel task.
Expand Down Expand Up @@ -71,17 +73,21 @@ def perform(self, target_value=None):

# set the magnetic field
job = driver.sweep_to_field(target_value, self.rate)
normal_end = job.wait_for_completion(self.check_for_interruption,
timeout=60,
refresh_time=10)
try:
normal_end = job.wait_for_completion(self.check_for_interruption,
timeout=60,
refresh_time=10)
except InstrTimeoutError:
normal_end = False

# Always close the switch heater when the ramp was interrupted.
if not normal_end:
job.cancel()
driver.heater_state = 'Off'
sleep(self.post_switch_wait)
self.write_in_database('field', driver.read_persistent_field())
return False
self.root.should_stop.set()
return

# turn off heater
if self.auto_stop_heater:
Expand Down