From 81ed48ea4f0da58224ca92069ca861eb041f2786 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Mon, 25 Nov 2024 16:08:55 +0100 Subject: [PATCH 1/9] sub to all readables --- src/secop_ophyd/SECoPDevices.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index 533b7e4..aa5d0e5 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -499,11 +499,15 @@ def trigger(self) -> bps.Status: def subscribe(self, function: Callback[dict[str, Reading]]) -> None: """Subscribe to updates in the reading""" - self.value.subscribe(function=function) + for sig in self._readables: + if isinstance(sig, SignalR): + sig.subscribe(function=function) def clear_sub(self, function: Callback) -> None: """Remove a subscription.""" - self.value.clear_sub(function=function) + for sig in self._readables: + if isinstance(sig, SignalR): + sig.subscribe(function=function) class SECoPTriggerableDevice(SECoPReadableDevice, Triggerable, Stoppable): From f3c398bc5d3e762292c38eeaef2daf261ae4ae59 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 09:09:40 +0100 Subject: [PATCH 2/9] only cached readings on trigger --- src/secop_ophyd/SECoPDevices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index aa5d0e5..2f51b0c 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -549,7 +549,7 @@ async def go_or_read_on_busy(): stat_code = module_status["f0"] if BUSY <= stat_code <= ERROR: - await self.status.get_value(False) + await self.status.get_value(True) return await self.__go_coro(True) From 61f7a6b4712f158ae9f72caa49b9e00a798b4582 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 09:15:38 +0100 Subject: [PATCH 3/9] only cached readings on trigger --- src/secop_ophyd/SECoPDevices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index 2f51b0c..608c91e 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -545,7 +545,7 @@ async def __go_coro(self, wait_for_idle: bool): def trigger(self) -> AsyncStatus: async def go_or_read_on_busy(): - module_status = await self.status.get_value(False) + module_status = await self.status.get_value(True) stat_code = module_status["f0"] if BUSY <= stat_code <= ERROR: From c071dff663d48fd545de7f4420f1c8411bd3a3cc Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 09:30:50 +0100 Subject: [PATCH 4/9] only cached readings on trigger --- src/secop_ophyd/SECoPDevices.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index 608c91e..6bf5cf1 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -549,8 +549,7 @@ async def go_or_read_on_busy(): stat_code = module_status["f0"] if BUSY <= stat_code <= ERROR: - await self.status.get_value(True) - return + return AsyncStatus(awaitable=self.status.get_value(True)) await self.__go_coro(True) From a8482cb9d3dc603ec4a0cc9fa92047c336295127 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 12:51:05 +0100 Subject: [PATCH 5/9] debug --- src/secop_ophyd/SECoPDevices.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index 6bf5cf1..d1e2891 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -549,10 +549,12 @@ async def go_or_read_on_busy(): stat_code = module_status["f0"] if BUSY <= stat_code <= ERROR: + print(f"mass spec BUSY status:{stat_code}") return AsyncStatus(awaitable=self.status.get_value(True)) await self.__go_coro(True) + print('mass spec IDELE sending "GO" Command') return AsyncStatus(awaitable=go_or_read_on_busy()) async def stop(self, success=True): From dd6094d35393c0de4dc5393b20e8f91a61ba0c9a Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 12:57:50 +0100 Subject: [PATCH 6/9] debug --- src/secop_ophyd/SECoPDevices.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index d1e2891..7cbd489 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -550,11 +550,11 @@ async def go_or_read_on_busy(): if BUSY <= stat_code <= ERROR: print(f"mass spec BUSY status:{stat_code}") - return AsyncStatus(awaitable=self.status.get_value(True)) + return + print('mass spec IDELE sending "GO" Command') await self.__go_coro(True) - print('mass spec IDELE sending "GO" Command') return AsyncStatus(awaitable=go_or_read_on_busy()) async def stop(self, success=True): From 3e387a09532bb3f9d06101050965704461eeaf00 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 13:11:36 +0100 Subject: [PATCH 7/9] remove debug, read fresh status on trigger --- src/secop_ophyd/SECoPDevices.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index 7cbd489..c0524f0 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -545,14 +545,12 @@ async def __go_coro(self, wait_for_idle: bool): def trigger(self) -> AsyncStatus: async def go_or_read_on_busy(): - module_status = await self.status.get_value(True) + module_status = await self.status.get_value(False) stat_code = module_status["f0"] if BUSY <= stat_code <= ERROR: - print(f"mass spec BUSY status:{stat_code}") return - print('mass spec IDELE sending "GO" Command') await self.__go_coro(True) return AsyncStatus(awaitable=go_or_read_on_busy()) From c214b28a2e775874613b04b407288279521d15a7 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 15:26:02 +0100 Subject: [PATCH 8/9] added observe status plan --- src/secop_ophyd/SECoPDevices.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index c0524f0..851c4e7 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -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): """ @@ -539,9 +556,14 @@ 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(): From 1f98b4e15c1d395a670c587aeafdab8bde212197 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 26 Nov 2024 15:31:24 +0100 Subject: [PATCH 9/9] remove sub to all readables --- src/secop_ophyd/SECoPDevices.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/secop_ophyd/SECoPDevices.py b/src/secop_ophyd/SECoPDevices.py index 851c4e7..a8a0fa2 100644 --- a/src/secop_ophyd/SECoPDevices.py +++ b/src/secop_ophyd/SECoPDevices.py @@ -516,15 +516,11 @@ def trigger(self) -> bps.Status: def subscribe(self, function: Callback[dict[str, Reading]]) -> None: """Subscribe to updates in the reading""" - for sig in self._readables: - if isinstance(sig, SignalR): - sig.subscribe(function=function) + self.value.subscribe(function=function) def clear_sub(self, function: Callback) -> None: """Remove a subscription.""" - for sig in self._readables: - if isinstance(sig, SignalR): - sig.subscribe(function=function) + self.value.clear_sub(function=function) class SECoPTriggerableDevice(SECoPReadableDevice, Triggerable, Stoppable):