Skip to content

Commit

Permalink
Use set and wait in ophyd_async
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Jul 16, 2024
1 parent 6f02f54 commit b0b2114
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/dodal/devices/tetramm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
DirectoryProvider,
ShapeProvider,
StandardDetector,
set_and_wait_for_value,
soft_signal_r_and_setter,
wait_for_value,
)
from ophyd_async.epics.areadetector.utils import stop_busy_record
from ophyd_async.epics.areadetector.writers import HDFWriter, NDFileHDF
Expand Down Expand Up @@ -132,9 +132,10 @@ async def arm(
self._drv.averaging_time.set(exposure), self.set_exposure(exposure)
)

status = await set_and_wait_for_value(self._drv.acquire, 1)
finished_status = self._drv.acquire.set(True)
await wait_for_value(self._drv.acquire, True, 10)

return status
return finished_status

def _validate_trigger(self, trigger: DetectorTrigger) -> None:
supported_trigger_types = {
Expand Down
55 changes: 44 additions & 11 deletions src/dodal/devices/xspress3/xspress3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AsyncStatus,
Device,
DeviceVector,
wait_for_value,
set_and_wait_for_other_value,
)
from ophyd_async.epics.signal.signal import (
epics_signal_r,
Expand Down Expand Up @@ -45,6 +45,16 @@ class AcquireRBVState(str, Enum):
ACQUIRE = "Acquiring"


class WritingRBVState(str, Enum):
DONE = "Done"
CAPTURE = "Capturing"


class WritingState(str, Enum):
DONE = "Done"
CAPTURE = "Capture"


class DetectorState(str, Enum):
IDLE = "Idle"
ACQUIRE = "Acquire"
Expand Down Expand Up @@ -115,6 +125,13 @@ def __init__(
self.acquire_rbv = epics_signal_r(AcquireRBVState, prefix + "Acquire_RBV")
self.trigger_mode = epics_signal_rw_rbv(TriggerMode, prefix + "TriggerMode")

self.file_path = epics_signal_rw_rbv(str, prefix + "HDF5:FilePath")
self.file_name = epics_signal_rw_rbv(str, prefix + "HDF5:FileName")
self.do_file_writing = epics_signal_rw(WritingState, prefix + "HDF5:Capture")
self.file_writing_rbv = epics_signal_r(
WritingRBVState, prefix + "HDF5:Capture_RBV"
)

self.detector_state = epics_signal_r(
DetectorState, prefix + "DetectorState_RBV"
)
Expand All @@ -130,21 +147,37 @@ def __init__(
@AsyncStatus.wrap
async def stage(self) -> None:
LOGGER.info("Arming Xspress3 detector...")
await self.trigger_mode.set(TriggerMode.BURST)
await wait_for_value(
self.detector_state,
lambda v: v in self.detector_busy_states,
await set_and_wait_for_other_value(
self.do_file_writing,
WritingState.CAPTURE,
self.file_writing_rbv,
WritingRBVState.CAPTURE,
timeout=self.timeout,
)
await self.acquire.set(AcquireState.ACQUIRE)
await wait_for_value(
self.acquire_rbv, AcquireRBVState.ACQUIRE, timeout=self.timeout
await self.trigger_mode.set(TriggerMode.BURST)

await set_and_wait_for_other_value(
self.acquire,
AcquireState.ACQUIRE,
self.acquire_rbv,
AcquireRBVState.ACQUIRE,
timeout=self.timeout,
)

@AsyncStatus.wrap
async def unstage(self) -> None:
await self.acquire.set(AcquireState.DONE)
LOGGER.info("unstaging Xspress3 detector...")
await wait_for_value(
self.acquire_rbv, AcquireRBVState.DONE, timeout=self.timeout
await set_and_wait_for_other_value(
self.do_file_writing,
WritingState.DONE,
self.file_writing_rbv,
WritingRBVState.DONE,
timeout=self.timeout,
)
await set_and_wait_for_other_value(
self.acquire,
AcquireState.DONE,
self.acquire_rbv,
AcquireRBVState.DONE,
timeout=self.timeout,
)

0 comments on commit b0b2114

Please sign in to comment.