Flipped to explicit finite lock timeouts

This commit is contained in:
Joel Collins 2020-06-29 09:03:27 +01:00
parent 832a9adbe3
commit 9cecb477cb
6 changed files with 35 additions and 30 deletions

View file

@ -376,10 +376,12 @@ class FastAutofocusAPI(ActionView):
if microscope.has_real_stage():
logging.debug("Running autofocus...")
# return a handle on the autofocus task
return fast_up_down_up_autofocus(
microscope, dz=dz, mini_backlash=backlash
)
# Acquire microscope lock with 1s timeout
with microscope.lock(timeout=1):
# Run fast_up_down_up_autofocus
return fast_up_down_up_autofocus(
microscope, dz=dz, mini_backlash=backlash
)
else:
abort(503, "No stage connected. Unable to autofocus.")

View file

@ -325,22 +325,23 @@ class TileScanAPI(ActionView):
logging.info("Running tile scan...")
# return a handle on the scan task
return scan_extension_v2.tile(
microscope,
basename=args.get("filename"),
temporary=args.get("temporary"),
stride_size=args.get("stride_size"),
grid=args.get("grid"),
style=args.get("style"),
autofocus_dz=args.get("autofocus_dz"),
use_video_port=args.get("use_video_port"),
resize=resize,
bayer=args.get("bayer"),
fast_autofocus=args.get("fast_autofocus"),
annotations=args.get("annotations"),
tags=args.get("tags"),
)
# Acquire microscope lock with 1s timeout
with microscope.lock(timeout=1):
# Run scan_extension_v2
return scan_extension_v2.tile(
microscope,
basename=args.get("filename"),
temporary=args.get("temporary"),
stride_size=args.get("stride_size"),
grid=args.get("grid"),
style=args.get("style"),
autofocus_dz=args.get("autofocus_dz"),
use_video_port=args.get("use_video_port"),
resize=resize,
bayer=args.get("bayer"),
fast_autofocus=args.get("fast_autofocus"),
annotations=args.get("annotations"),
tags=args.get("tags"),
)
scan_extension_v2.add_view(TileScanAPI, "/tile", endpoint="tile")

View file

@ -45,8 +45,8 @@ class MoveStageAPI(ActionView):
# Move if stage exists
if microscope.stage:
# Explicitally acquire lock
with microscope.stage.lock:
# Explicitally acquire lock with 1s timeout
with microscope.stage.lock(timeout=1):
microscope.stage.move_rel(position)
else:
logging.warning("Unable to move. No stage found.")
@ -62,7 +62,9 @@ class ZeroStageAPI(ActionView):
Does not move the stage, but rather makes the current position read as [0, 0, 0]
"""
microscope = find_component("org.openflexure.microscope")
microscope.stage.zero_position()
with microscope.stage.lock(timeout=1):
microscope.stage.zero_position()
# TODO: Make schema for microscope state
return microscope.state["stage"]