Skip to content

Commit

Permalink
Updated tango demo in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
burkeds committed Sep 12, 2024
1 parent e586a24 commit 73f8e5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
41 changes: 21 additions & 20 deletions docs/examples/tango_demo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import asyncio

import bluesky.plan_stubs as bps
import bluesky.plans as bp
from bluesky import RunEngine
from bluesky.callbacks.best_effort import BestEffortCallback
from bluesky.utils import ProgressBarManager

from ophyd_async.tango.demo import (
DemoCounter,
DemoMover,
TangoCounter,
TangoMover,
TangoDetector,
)
from tango.test_context import MultiDeviceTestContext

Expand All @@ -28,25 +26,28 @@


async def main():
with tango_context as context:
motor1 = TangoMover(
trl=context.get_device_access("demo/motor/1"), name="motor1"
with tango_context:
detector = TangoDetector(
trl="",
name="detector",
counters_kwargs={"prefix": "demo/counter/", "count": 2},
mover_kwargs={"trl": "demo/motor/1"},
)
counter1 = TangoCounter(
trl=context.get_device_access("demo/counter/1"), name="counter1"
)
counter2 = TangoCounter(
trl=context.get_device_access("demo/counter/2"), name="counter2"
)
await motor1.connect()
await counter1.connect()
await counter2.connect()
await detector.connect()

RE = RunEngine()
RE.subscribe(BestEffortCallback())
RE.waiting_hook = ProgressBarManager()
# RE(bps.mv(motor1, 1))
RE(bp.scan([counter1, counter2], motor1, -1, 1, 10))

RE(bps.read(detector))
RE(bps.mv(detector, 0))
RE(bp.count(list(detector.counters.values())))

set_status = detector.set(1.0)
await asyncio.sleep(0.1)
stop_status = detector.stop()
await set_status
await stop_status
assert all([set_status.done, stop_status.done])
assert all([set_status.success, stop_status.success])


if __name__ == "__main__":
Expand Down
7 changes: 4 additions & 3 deletions src/ophyd_async/tango/demo/_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
)
from ophyd_async.tango import TangoReadable

from . import TangoCounter, TangoMover
from ._counter import TangoCounter
from ._mover import TangoMover


class TangoDetector(TangoReadable):
Expand All @@ -24,8 +25,8 @@ def __init__(self, *args, **kwargs):
def set(self, value):
return self.mover.set(value)

def stop(self):
return self.mover.stop()
def stop(self, success: bool = True) -> AsyncStatus:
return self.mover.stop(success)

@AsyncStatus.wrap
async def trigger(self):
Expand Down

0 comments on commit 73f8e5d

Please sign in to comment.