Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Jan 7, 2025
1 parent aaafcd0 commit b058049
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/ophyd_async/epics/sim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# Start IOC with demo pvs in subprocess
prefix = testing.generate_random_pv_prefix()
prefix = "foo:"
sim.start_ioc_subprocess(prefix, num_counters=3)

# All Devices created within this block will be
Expand Down
5 changes: 2 additions & 3 deletions src/ophyd_async/epics/sim/_counter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Annotated as A

from ophyd_async.core import SignalR, SignalRW, SignalX, StandardReadable, StrictEnum
from ophyd_async.core import SignalR, SignalRW, StandardReadable, StrictEnum
from ophyd_async.core import StandardReadableFormat as Format
from ophyd_async.epics.core import EpicsDevice, PvSuffix

Expand All @@ -17,6 +17,5 @@ class EnergyMode(StrictEnum):
class Counter(StandardReadable, EpicsDevice):
"""A demo sensor that produces a scalar value based on X and Y Movers"""

value: A[SignalR[int], PvSuffix("Value"), Format.HINTED_SIGNAL]
value: A[SignalR[int], PvSuffix("Value"), Format.HINTED_UNCACHED_SIGNAL]
mode: A[SignalRW[EnergyMode], PvSuffix("Mode"), Format.CONFIG_SIGNAL]
reset: A[SignalX, PvSuffix("Reset")]
7 changes: 3 additions & 4 deletions src/ophyd_async/epics/sim/_multichannelcounter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from typing import Annotated as A

from ophyd_async.core import (
Expand All @@ -18,8 +17,9 @@

class MultiChannelCounter(StandardReadable, EpicsDevice):
acquire_time: A[SignalRW[float], PvSuffix("AcquireTime"), Format.CONFIG_SIGNAL]
start: A[SignalX, PvSuffix("Start")]
start: A[SignalX, PvSuffix("Start.PROC")]
acquiring: A[SignalR[bool], PvSuffix("Acquiring")]
reset: A[SignalX, PvSuffix("Reset.PROC")]

def __init__(self, prefix: str, name: str = "", num_counters: int = 3) -> None:
with self.add_children_as_readables():
Expand All @@ -30,7 +30,6 @@ def __init__(self, prefix: str, name: str = "", num_counters: int = 3) -> None:

@AsyncStatus.wrap
async def trigger(self):
coros = [counter.reset.trigger() for counter in self.counters.values()]
await asyncio.gather(*coros)
await self.reset.trigger()
timeout = await self.acquire_time.get_value() + DEFAULT_TIMEOUT
await self.start.trigger(timeout=timeout)
14 changes: 3 additions & 11 deletions src/ophyd_async/epics/sim/counter.db
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ record(calc, "$(P)$(CHANNEL):Value") {
field(INPB, "$(Y)Readback")
field(INPC, "$(CHANNEL)")
field(INPD, "$(P)$(CHANNEL):Mode.RVAL")
field(INPE, "$(P)$(CHANNEL):Value")
field(CALC, "CEIL(SIN(A)**C+COS(D+B*A)+2)*999+E")
field(EGU, "cts/s")
field(INPE, "$(P)Elapsed CP")
field(CALC, "CEIL((SIN(A)**C+COS(D+B*A)+2)*10000*E)")
field(EGU, "cts")
field(PREC, "0")
field(SCAN, ".1 second")
field(SDIS, "$(P)Acquiring")
field(DISV, "0")
}

record(calcout, "$(P)$(CHANNEL):Reset") {
field(OUT, "$(P)$(CHANNEL):Value PP")
field(OCAL, "0")
}
46 changes: 42 additions & 4 deletions src/ophyd_async/epics/sim/multichannelcounter.db
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
record(ao, "$(P)AcquireTime") {
field(DESC, "Time to acquire for")
field(VAL, "0.1")
field(OUT, "$(P)Start.DLY1")
field(OUT, "$(P)Start.DLY2")
field(PINI, "YES")
}

record(seq, "$(P)Start") {
field(DESC, "Start sequence")
field(LNK0, "$(P)Acquiring PP")
field(DO0, "1")
# Grab the start time
field(LNK0, "$(P)StartTime.PROC")
# Set it to be acquiring
field(LNK1, "$(P)Acquiring PP")
field(DO0, "0")
field(DO1, "1")
# Set it back to idle
field(LNK2, "$(P)Acquiring PP")
field(DO2, "0")
# Set the elapsed time to the full acquire time
field(LNK3, "$(P)Elapsed PP")
field(DOL3, "$(P)AcquireTime")
}

record(ai, "$(P)StartTime") {
field(DTYP, "Soft Timestamp")
}

record(bi, "$(P)Acquiring") {
Expand All @@ -19,3 +30,30 @@ record(bi, "$(P)Acquiring") {
field(ONAM, "Acquiring")
field(PINI, "YES")
}

record(ai, "$(P)CurrentTime") {
field(DTYP, "Soft Timestamp")
}

record(calcout, "$(P)Process") {
field(DESC, "Process elapsed time if acquiring")
field(INPA, "$(P)StartTime")
field(INPB, "$(P)CurrentTime PP")
field(SCAN, ".1 second")
field(CALC, "B-A")
field(OUT, "$(P)Elapsed PP")
field(SDIS, "$(P)Acquiring")
field(DISV, "0")
}

record(ai, "$(P)Elapsed") {
field(DESC, "Elapsed time")
field(EGU, "s")
field(PREC, "1")
field(PINI, "YES")
}

record(calcout, "$(P)Reset") {
field(OUT, "$(P)Elapsed PP")
field(CALC, "0")
}
3 changes: 0 additions & 3 deletions src/ophyd_async/epics/sim/plot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import matplotlib.cbook as cbook
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import PathPatch
from matplotlib.path import Path

delta = 0.025
x = y = np.arange(-10.0, 10.0, delta)
Expand Down

0 comments on commit b058049

Please sign in to comment.