Skip to content
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

Wait for prepared #20

Merged
merged 9 commits into from
Nov 26, 2024
Merged
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
23 changes: 22 additions & 1 deletion src/secop_ophyd/SECoPDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ async def wait_for_idle(self):
self._success = False
break

# TODO add timeout
def observe_status_change(self, monitored_status_code: int):
async def switch_from_status_inner():
async for current_stat in observe_value(self.status):
# status is has type Tuple and is therefore transported as
# structured Numpy array ('f0':statuscode;'f1':status Message)

stat_code = current_stat["f0"]

if monitored_status_code != stat_code:
break

def switch_from_status_factory():
return switch_from_status_inner()

yield from bps.wait_for([switch_from_status_factory])


class SECoPCMDDevice(StandardReadable, Flyable, Triggerable):
"""
Expand Down Expand Up @@ -535,17 +552,21 @@ async def __go_coro(self, wait_for_idle: bool):
self._success = True
self._stopped = False
await asyncio.sleep(0.2)

if wait_for_idle:
await self.wait_for_idle()

def wait_for_prepared(self):
yield from self.observe_status_change(IDLE)
yield from self.observe_status_change(PREPARING)

def trigger(self) -> AsyncStatus:

async def go_or_read_on_busy():
module_status = await self.status.get_value(False)
stat_code = module_status["f0"]

if BUSY <= stat_code <= ERROR:
await self.status.get_value(False)
return

await self.__go_coro(True)
Expand Down