Skip to content

Commit

Permalink
formatting, adding other controls
Browse files Browse the repository at this point in the history
  • Loading branch information
rerpha committed Aug 15, 2024
1 parent c7d2ca3 commit 0eb1fe7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 31 deletions.
7 changes: 5 additions & 2 deletions src/ibex_bluesky_core/demo_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ def run_demo_plan() -> None:
prefix = get_pv_prefix()
block = Block(prefix, "mot", float)
dae = Dae(prefix)
RE(demo_plan(block, dae), LiveTable(["mot", "DAE-good_uah", "DAE-run_state", "DAE-rb_number"], default_prec=10))
#RE(demo_plan(block, dae), print)
RE(
demo_plan(block, dae),
LiveTable(["mot", "DAE-good_uah", "DAE-run_state", "DAE-rb_number"], default_prec=10),
)
# RE(demo_plan(block, dae), print)


def demo_plan(block: Block, dae: Dae) -> Generator[Msg, None, None]:
Expand Down
51 changes: 32 additions & 19 deletions src/ibex_bluesky_core/devices/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import asyncio
from enum import Enum

import numpy as np
from bluesky.protocols import Triggerable
from ophyd_async.core import AsyncStatus, SignalR, SignalX, StandardReadable, ConfigSignal, SignalRW
from ophyd_async.epics.signal import epics_signal_r, epics_signal_x
from ophyd_async.core import AsyncStatus, ConfigSignal, SignalR, SignalRW, StandardReadable
from ophyd_async.epics.signal import epics_signal_r

from ibex_bluesky_core.devices.dae_controls import DaeControls
from ibex_bluesky_core.utils.isis_epics_signals import isis_epics_signal_rw
Expand All @@ -32,9 +33,7 @@ def __str__(self):
return str(self.value)


class Dae(
StandardReadable, Triggerable
):
class Dae(StandardReadable, Triggerable):
"""Device representing the ISIS data acquisition electronics."""

def __init__(self, prefix: str, name: str = "DAE") -> None:
Expand All @@ -44,9 +43,11 @@ def __init__(self, prefix: str, name: str = "DAE") -> None:
self.good_uah: SignalR[float] = epics_signal_r(float, f"{dae_prefix}GOODUAH")
self.count_rate: SignalR[float] = epics_signal_r(float, f"{dae_prefix}COUNTRATE")
self.m_events: SignalR[float] = epics_signal_r(float, f"{dae_prefix}MEVENTS")
self.sim_mode : SignalR[bool] = epics_signal_r(bool, f"{dae_prefix}SIM_MODE")
self.sim_mode: SignalR[bool] = epics_signal_r(bool, f"{dae_prefix}SIM_MODE")

self.neutron_proton_ratio: SignalR[float] = epics_signal_r(float, f"{dae_prefix}NPRATIO")
self.neutron_proton_ratio: SignalR[float] = epics_signal_r(
float, f"{dae_prefix}NPRATIO"
)
self.good_frames: SignalR[int] = epics_signal_r(int, f"{dae_prefix}GOODFRAMES")
self.raw_frames: SignalR[int] = epics_signal_r(int, f"{dae_prefix}RAWFRAMES")
self.total_counts: SignalR[int] = epics_signal_r(int, f"{dae_prefix}TOTALCOUNTS")
Expand All @@ -62,12 +63,18 @@ def __init__(self, prefix: str, name: str = "DAE") -> None:
self.inst_name: SignalR[str] = epics_signal_r(str, f"{dae_prefix}INSTNAME")
self.run_start_time: SignalR[str] = epics_signal_r(str, f"{dae_prefix}STARTTIME")
self.run_duration: SignalR[int] = epics_signal_r(int, f"{dae_prefix}RUNDURATION")
self.num_time_channels: SignalR[int] = epics_signal_r(int, f"{dae_prefix}NUMTIMECHANNELS")
self.num_time_channels: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}NUMTIMECHANNELS"
)
self.num_spectra: SignalR[int] = epics_signal_r(int, f"{dae_prefix}NUMSPECTRA")

# TODO move this out to subdevice?
self.period_run_duration: SignalR[int] = epics_signal_r(int, f"{dae_prefix}RUNDURATION_PD")
self.period_good_frames: SignalR[int] = epics_signal_r(int, f"{dae_prefix}GOODFRAMES_PD")
self.period_run_duration: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}RUNDURATION_PD"
)
self.period_good_frames: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}GOODFRAMES_PD"
)
self.period_raw_frames: SignalR[int] = epics_signal_r(int, f"{dae_prefix}RAWFRAMES_PD")
self.period_good_uah: SignalR[float] = epics_signal_r(float, f"{dae_prefix}GOODUAH_PD")
self.period_type: SignalR[str] = epics_signal_r(str, f"{dae_prefix}PERIODTYPE")
Expand All @@ -81,10 +88,18 @@ def __init__(self, prefix: str, name: str = "DAE") -> None:
self.monitor_from: SignalR[float] = epics_signal_r(float, f"{dae_prefix}MONITORFROM")

# TODO move this out to subdevice?
self.event_mode_fraction: SignalR[float] = epics_signal_r(float, f"{dae_prefix}EVENTMODEFRACTION")
self.event_mode_buf_used: SignalR[float] = epics_signal_r(float, f"{dae_prefix}EVENTMODEBUFUSED")
self.event_mode_file_size: SignalR[float] = epics_signal_r(float, f"{dae_prefix}EVENTMODEFILEMB")
self.event_mode_data_rate: SignalR[float] = epics_signal_r(float, f"{dae_prefix}EVENTMODEDATARATE")
self.event_mode_fraction: SignalR[float] = epics_signal_r(
float, f"{dae_prefix}EVENTMODEFRACTION"
)
self.event_mode_buf_used: SignalR[float] = epics_signal_r(
float, f"{dae_prefix}EVENTMODEBUFUSED"
)
self.event_mode_file_size: SignalR[float] = epics_signal_r(
float, f"{dae_prefix}EVENTMODEFILEMB"
)
self.event_mode_data_rate: SignalR[float] = epics_signal_r(
float, f"{dae_prefix}EVENTMODEDATARATE"
)

self.beam_current: SignalR[float] = epics_signal_r(float, f"{dae_prefix}BEAMCURRENT")
self.total_uamps: SignalR[float] = epics_signal_r(float, f"{dae_prefix}TOTALUAMPS")
Expand All @@ -94,7 +109,9 @@ def __init__(self, prefix: str, name: str = "DAE") -> None:
)

self.title: SignalRW = isis_epics_signal_rw(str, f"{dae_prefix}TITLE")
self.show_title_and_users: SignalRW = isis_epics_signal_rw(bool, f"{dae_prefix}TITLE:DISPLAY")
self.show_title_and_users: SignalRW = isis_epics_signal_rw(
bool, f"{dae_prefix}TITLE:DISPLAY"
)
self.users: SignalRW = isis_epics_signal_rw(str, f"{dae_prefix}_USERNAME")
self.rb_number: SignalRW = isis_epics_signal_rw(str, f"{dae_prefix}_RBNUMBER")

Expand Down Expand Up @@ -128,10 +145,6 @@ async def trigger(self) -> None:
This method is allowed to be "slow" - i.e. it should wait for data to be
ready before returning.
"""

await self.controls.begin_run.trigger()
await asyncio.sleep(2) # This is a placeholder for the moment
await self.controls.end_run.trigger(wait=True)
# await self.begin_run.trigger(wait=True)
# await asyncio.sleep(2) # This is a placeholder for the moment
# await self.end_run.trigger(wait=True)
11 changes: 6 additions & 5 deletions src/ibex_bluesky_core/devices/dae_controls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from bluesky.protocols import Triggerable, Status
from ophyd_async.epics.signal import epics_signal_x
import asyncio
from ophyd_async.core import AsyncStatus, SignalX
from ophyd_async.core import Device, StandardReadable
from ophyd_async.core import SignalX, StandardReadable
from ophyd_async.epics.signal import epics_signal_x


class DaeControls(StandardReadable):
def __init__(self, dae_prefix, name=""):
self.begin_run: SignalX = epics_signal_x(f"{dae_prefix}BEGINRUN")
self.begin_run_ex: SignalX = epics_signal_x(f"{dae_prefix}BEGINRUNEX")

self.end_run: SignalX = epics_signal_x(f"{dae_prefix}ENDRUN")
self.pause_run: SignalX = epics_signal_x(f"{dae_prefix}PAUSERUN")
self.resume_run: SignalX = epics_signal_x(f"{dae_prefix}RESUMERUN")
self.abort_run: SignalX = epics_signal_x(f"{dae_prefix}ABORTRUN")
self.recover_run: SignalX = epics_signal_x(f"{dae_prefix}RECOVERRUN")
self.save_run: SignalX = epics_signal_x(f"{dae_prefix}SAVERUN")

super().__init__(name=name)
6 changes: 3 additions & 3 deletions src/ibex_bluesky_core/utils/isis_epics_signals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

from typing import Type

from ophyd_async.epics.signal import epics_signal_rw
from ophyd_async.core import SignalRW, T
from ophyd_async.epics.signal import epics_signal_rw


def isis_epics_signal_rw(datatype: Type[T], read_pv: str, name: str = "") -> SignalRW[T]:
"""
Utility function for making a RW signal using the ISIS PV naming standard ie. read_pv being TITLE,
"""Utility function for making a RW signal using the ISIS PV naming standard ie. read_pv being TITLE,
write_pv being TITLE:SP
"""
write_pv = f"{read_pv}:SP"
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_isis_epics_signals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ibex_bluesky_core.utils.isis_epics_signals import isis_epics_signal_rw
from unittest.mock import patch
from time import sleep

from ibex_bluesky_core.utils.isis_epics_signals import isis_epics_signal_rw


def test_isis_epics_rw_signal_appends_correct_sp_suffix():
Expand Down

0 comments on commit 0eb1fe7

Please sign in to comment.