ophyd-async 0.8.0a2__py3-none-any.whl → 0.8.0a3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ophyd_async/_version.py +1 -1
- ophyd_async/core/__init__.py +7 -1
- ophyd_async/core/_device.py +1 -0
- ophyd_async/core/_device_filler.py +208 -130
- ophyd_async/core/_readable.py +128 -129
- ophyd_async/core/_utils.py +9 -1
- ophyd_async/epics/adaravis/_aravis_io.py +1 -1
- ophyd_async/epics/adcore/_core_io.py +1 -1
- ophyd_async/epics/adcore/_single_trigger.py +4 -9
- ophyd_async/epics/adkinetix/_kinetix_io.py +1 -1
- ophyd_async/epics/adpilatus/_pilatus_io.py +1 -1
- ophyd_async/epics/advimba/_vimba_io.py +1 -1
- ophyd_async/epics/core/__init__.py +26 -0
- ophyd_async/epics/{signal → core}/_aioca.py +3 -6
- ophyd_async/epics/core/_epics_connector.py +53 -0
- ophyd_async/epics/core/_epics_device.py +13 -0
- ophyd_async/epics/{signal → core}/_p4p.py +3 -6
- ophyd_async/epics/core/_pvi_connector.py +92 -0
- ophyd_async/epics/{signal → core}/_signal.py +31 -16
- ophyd_async/epics/{signal/_common.py → core/_util.py} +19 -1
- ophyd_async/epics/demo/_mover.py +4 -5
- ophyd_async/epics/demo/_sensor.py +9 -12
- ophyd_async/epics/eiger/_eiger_io.py +1 -1
- ophyd_async/epics/eiger/_odin_io.py +1 -1
- ophyd_async/epics/motor.py +4 -5
- ophyd_async/epics/signal.py +11 -0
- ophyd_async/fastcs/core.py +2 -2
- ophyd_async/sim/demo/_sim_motor.py +3 -4
- ophyd_async/tango/base_devices/_base_device.py +15 -16
- ophyd_async/tango/demo/_counter.py +6 -16
- ophyd_async/tango/demo/_mover.py +3 -4
- {ophyd_async-0.8.0a2.dist-info → ophyd_async-0.8.0a3.dist-info}/METADATA +1 -1
- {ophyd_async-0.8.0a2.dist-info → ophyd_async-0.8.0a3.dist-info}/RECORD +37 -35
- ophyd_async/epics/pvi/__init__.py +0 -3
- ophyd_async/epics/pvi/_pvi.py +0 -73
- ophyd_async/epics/signal/__init__.py +0 -20
- {ophyd_async-0.8.0a2.dist-info → ophyd_async-0.8.0a3.dist-info}/LICENSE +0 -0
- {ophyd_async-0.8.0a2.dist-info → ophyd_async-0.8.0a3.dist-info}/WHEEL +0 -0
- {ophyd_async-0.8.0a2.dist-info → ophyd_async-0.8.0a3.dist-info}/entry_points.txt +0 -0
- {ophyd_async-0.8.0a2.dist-info → ophyd_async-0.8.0a3.dist-info}/top_level.txt +0 -0
ophyd_async/core/_readable.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import warnings
|
|
2
|
-
from collections.abc import Callable, Generator, Sequence
|
|
2
|
+
from collections.abc import Awaitable, Callable, Generator, Sequence
|
|
3
3
|
from contextlib import contextmanager
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Any, cast
|
|
4
6
|
|
|
5
7
|
from bluesky.protocols import HasHints, Hints, Reading
|
|
6
8
|
from event_model import DataKey
|
|
@@ -11,11 +13,61 @@ from ._signal import SignalR
|
|
|
11
13
|
from ._status import AsyncStatus
|
|
12
14
|
from ._utils import merge_gathered_dicts
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
class StandardReadableFormat(Enum):
|
|
18
|
+
"""Declare how a `Device` should contribute to the `StandardReadable` verbs."""
|
|
19
|
+
|
|
20
|
+
#: Detect which verbs the child supports and contribute to:
|
|
21
|
+
#:
|
|
22
|
+
#: - ``read()``, ``describe()`` if it is `bluesky.protocols.Readable`
|
|
23
|
+
#: - ``read_configuration()``, ``describe_configuration()`` if it is
|
|
24
|
+
#: `bluesky.protocols.Configurable`
|
|
25
|
+
#: - ``stage()``, ``unstage()`` if it is `bluesky.protocols.Stageable`
|
|
26
|
+
#: - ``hints`` if it `bluesky.protocols.HasHints`
|
|
27
|
+
CHILD = "CHILD"
|
|
28
|
+
#: Contribute the `Signal` value to ``read_configuration()`` and
|
|
29
|
+
#: ``describe_configuration()``
|
|
30
|
+
CONFIG_SIGNAL = "CONFIG_SIGNAL"
|
|
31
|
+
#: Contribute the monitored `Signal` value to ``read()`` and ``describe()``` and
|
|
32
|
+
#: put the signal name in ``hints``
|
|
33
|
+
HINTED_SIGNAL = "HINTED_SIGNAL"
|
|
34
|
+
#: Contribute the uncached `Signal` value to ``read()`` and ``describe()```
|
|
35
|
+
UNCACHED_SIGNAL = "UNCACHED_SIGNAL"
|
|
36
|
+
#: Contribute the uncached `Signal` value to ``read()`` and ``describe()``` and
|
|
37
|
+
#: put the signal name in ``hints``
|
|
38
|
+
HINTED_UNCACHED_SIGNAL = "HINTED_UNCACHED_SIGNAL"
|
|
39
|
+
|
|
40
|
+
def __call__(self, parent: Device, child: Device):
|
|
41
|
+
if not isinstance(parent, StandardReadable):
|
|
42
|
+
raise TypeError(f"Expected parent to be StandardReadable, got {parent}")
|
|
43
|
+
parent.add_readables([child], self)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Back compat
|
|
47
|
+
class _WarningMatcher:
|
|
48
|
+
def __init__(self, name: str, target: StandardReadableFormat):
|
|
49
|
+
self._name = name
|
|
50
|
+
self._target = target
|
|
51
|
+
|
|
52
|
+
def __eq__(self, value: object) -> bool:
|
|
53
|
+
warnings.warn(
|
|
54
|
+
DeprecationWarning(
|
|
55
|
+
f"Use `StandardReadableFormat.{self._target.name}` "
|
|
56
|
+
f"instead of `{self._name}`"
|
|
57
|
+
),
|
|
58
|
+
stacklevel=2,
|
|
59
|
+
)
|
|
60
|
+
return value == self._target
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _compat_format(name: str, target: StandardReadableFormat) -> StandardReadableFormat:
|
|
64
|
+
return cast(StandardReadableFormat, _WarningMatcher(name, target))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
ConfigSignal = _compat_format("ConfigSignal", StandardReadableFormat.CONFIG_SIGNAL)
|
|
68
|
+
HintedSignal: Any = _compat_format("HintedSignal", StandardReadableFormat.HINTED_SIGNAL)
|
|
69
|
+
HintedSignal.uncached = _compat_format(
|
|
70
|
+
"HintedSignal.uncached", StandardReadableFormat.HINTED_UNCACHED_SIGNAL
|
|
19
71
|
)
|
|
20
72
|
|
|
21
73
|
|
|
@@ -31,38 +83,13 @@ class StandardReadable(
|
|
|
31
83
|
|
|
32
84
|
# These must be immutable types to avoid accidental sharing between
|
|
33
85
|
# different instances of the class
|
|
34
|
-
|
|
35
|
-
|
|
86
|
+
_describe_config_funcs: tuple[Callable[[], Awaitable[dict[str, DataKey]]], ...] = ()
|
|
87
|
+
_read_config_funcs: tuple[Callable[[], Awaitable[dict[str, Reading]]], ...] = ()
|
|
88
|
+
_describe_funcs: tuple[Callable[[], Awaitable[dict[str, DataKey]]], ...] = ()
|
|
89
|
+
_read_funcs: tuple[Callable[[], Awaitable[dict[str, Reading]]], ...] = ()
|
|
36
90
|
_stageables: tuple[AsyncStageable, ...] = ()
|
|
37
91
|
_has_hints: tuple[HasHints, ...] = ()
|
|
38
92
|
|
|
39
|
-
def set_readable_signals(
|
|
40
|
-
self,
|
|
41
|
-
read: Sequence[SignalR] = (),
|
|
42
|
-
config: Sequence[SignalR] = (),
|
|
43
|
-
read_uncached: Sequence[SignalR] = (),
|
|
44
|
-
):
|
|
45
|
-
"""
|
|
46
|
-
Parameters
|
|
47
|
-
----------
|
|
48
|
-
read:
|
|
49
|
-
Signals to make up :meth:`~StandardReadable.read`
|
|
50
|
-
conf:
|
|
51
|
-
Signals to make up :meth:`~StandardReadable.read_configuration`
|
|
52
|
-
read_uncached:
|
|
53
|
-
Signals to make up :meth:`~StandardReadable.read` that won't be cached
|
|
54
|
-
"""
|
|
55
|
-
warnings.warn(
|
|
56
|
-
DeprecationWarning(
|
|
57
|
-
"Migrate to `add_children_as_readables` context manager or "
|
|
58
|
-
"`add_readables` method"
|
|
59
|
-
),
|
|
60
|
-
stacklevel=2,
|
|
61
|
-
)
|
|
62
|
-
self.add_readables(read, wrapper=HintedSignal)
|
|
63
|
-
self.add_readables(config, wrapper=ConfigSignal)
|
|
64
|
-
self.add_readables(read_uncached, wrapper=HintedSignal.uncached)
|
|
65
|
-
|
|
66
93
|
@AsyncStatus.wrap
|
|
67
94
|
async def stage(self) -> None:
|
|
68
95
|
for sig in self._stageables:
|
|
@@ -75,19 +102,17 @@ class StandardReadable(
|
|
|
75
102
|
|
|
76
103
|
async def describe_configuration(self) -> dict[str, DataKey]:
|
|
77
104
|
return await merge_gathered_dicts(
|
|
78
|
-
[
|
|
105
|
+
[func() for func in self._describe_config_funcs]
|
|
79
106
|
)
|
|
80
107
|
|
|
81
108
|
async def read_configuration(self) -> dict[str, Reading]:
|
|
82
|
-
return await merge_gathered_dicts(
|
|
83
|
-
[sig.read_configuration() for sig in self._configurables]
|
|
84
|
-
)
|
|
109
|
+
return await merge_gathered_dicts([func() for func in self._read_config_funcs])
|
|
85
110
|
|
|
86
111
|
async def describe(self) -> dict[str, DataKey]:
|
|
87
|
-
return await merge_gathered_dicts([
|
|
112
|
+
return await merge_gathered_dicts([func() for func in self._describe_funcs])
|
|
88
113
|
|
|
89
114
|
async def read(self) -> dict[str, Reading]:
|
|
90
|
-
return await merge_gathered_dicts([
|
|
115
|
+
return await merge_gathered_dicts([func() for func in self._read_funcs])
|
|
91
116
|
|
|
92
117
|
@property
|
|
93
118
|
def hints(self) -> Hints:
|
|
@@ -127,27 +152,13 @@ class StandardReadable(
|
|
|
127
152
|
@contextmanager
|
|
128
153
|
def add_children_as_readables(
|
|
129
154
|
self,
|
|
130
|
-
|
|
155
|
+
format: StandardReadableFormat = StandardReadableFormat.CHILD,
|
|
131
156
|
) -> Generator[None, None, None]:
|
|
132
|
-
"""Context manager
|
|
157
|
+
"""Context manager that calls `add_readables` on child Devices added within.
|
|
133
158
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
The provided wrapper class will be applied to all Devices and can be used to
|
|
138
|
-
specify their behaviour.
|
|
139
|
-
|
|
140
|
-
Parameters
|
|
141
|
-
----------
|
|
142
|
-
wrapper:
|
|
143
|
-
Wrapper class to apply to all Devices created inside the context manager.
|
|
144
|
-
|
|
145
|
-
See Also
|
|
146
|
-
--------
|
|
147
|
-
:func:`~StandardReadable.add_readables`
|
|
148
|
-
:class:`ConfigSignal`
|
|
149
|
-
:class:`HintedSignal`
|
|
150
|
-
:meth:`HintedSignal.uncached`
|
|
159
|
+
Scans ``self.children()`` on entry and exit to context manager, and calls
|
|
160
|
+
`add_readables` on any that are added with the provided
|
|
161
|
+
`StandardReadableFormat`.
|
|
151
162
|
"""
|
|
152
163
|
|
|
153
164
|
dict_copy = dict(self.children())
|
|
@@ -167,95 +178,83 @@ class StandardReadable(
|
|
|
167
178
|
flattened_values.append(value)
|
|
168
179
|
|
|
169
180
|
new_devices = list(filter(lambda x: isinstance(x, Device), flattened_values))
|
|
170
|
-
self.add_readables(new_devices,
|
|
181
|
+
self.add_readables(new_devices, format)
|
|
171
182
|
|
|
172
183
|
def add_readables(
|
|
173
184
|
self,
|
|
174
|
-
devices: Sequence[
|
|
175
|
-
|
|
185
|
+
devices: Sequence[Device],
|
|
186
|
+
format: StandardReadableFormat = StandardReadableFormat.CHILD,
|
|
176
187
|
) -> None:
|
|
177
|
-
"""Add
|
|
188
|
+
"""Add devices to contribute to various bluesky verbs.
|
|
178
189
|
|
|
179
|
-
|
|
180
|
-
interfaces
|
|
190
|
+
Use output from the given devices to contribute to the verbs of the following
|
|
191
|
+
interfaces:
|
|
181
192
|
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
- `bluesky.protocols.Readable`
|
|
194
|
+
- `bluesky.protocols.Configurable`
|
|
195
|
+
- `bluesky.protocols.Stageable`
|
|
196
|
+
- `bluesky.protocols.HasHints`
|
|
184
197
|
|
|
185
198
|
Parameters
|
|
186
199
|
----------
|
|
187
200
|
devices:
|
|
188
201
|
The devices to be added
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
See Also
|
|
193
|
-
--------
|
|
194
|
-
:func:`~StandardReadable.add_children_as_readables`
|
|
195
|
-
:class:`ConfigSignal`
|
|
196
|
-
:class:`HintedSignal`
|
|
197
|
-
:meth:`HintedSignal.uncached`
|
|
202
|
+
format:
|
|
203
|
+
Determines which of the devices functions are added to which verb as per the
|
|
204
|
+
`StandardReadableFormat` documentation
|
|
198
205
|
"""
|
|
199
206
|
|
|
200
|
-
for
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
207
|
+
for device in devices:
|
|
208
|
+
match format:
|
|
209
|
+
case StandardReadableFormat.CHILD:
|
|
210
|
+
if isinstance(device, AsyncConfigurable):
|
|
211
|
+
self._describe_config_funcs += (device.describe_configuration,)
|
|
212
|
+
self._read_config_funcs += (device.read_configuration,)
|
|
213
|
+
if isinstance(device, AsyncReadable):
|
|
214
|
+
self._describe_funcs += (device.describe,)
|
|
215
|
+
self._read_funcs += (device.read,)
|
|
216
|
+
if isinstance(device, AsyncStageable):
|
|
217
|
+
self._stageables += (device,)
|
|
218
|
+
if isinstance(device, HasHints):
|
|
219
|
+
self._has_hints += (device,)
|
|
220
|
+
case StandardReadableFormat.CONFIG_SIGNAL:
|
|
221
|
+
assert isinstance(device, SignalR), f"{device} is not a SignalR"
|
|
222
|
+
self._describe_config_funcs += (device.describe,)
|
|
223
|
+
self._read_config_funcs += (device.read,)
|
|
224
|
+
case StandardReadableFormat.HINTED_SIGNAL:
|
|
225
|
+
assert isinstance(device, SignalR), f"{device} is not a SignalR"
|
|
226
|
+
self._describe_funcs += (device.describe,)
|
|
227
|
+
self._read_funcs += (device.read,)
|
|
228
|
+
self._stageables += (device,)
|
|
229
|
+
self._has_hints += (_HintsFromName(device),)
|
|
230
|
+
case StandardReadableFormat.UNCACHED_SIGNAL:
|
|
231
|
+
assert isinstance(device, SignalR), f"{device} is not a SignalR"
|
|
232
|
+
self._describe_funcs += (device.describe,)
|
|
233
|
+
self._read_funcs += (_UncachedRead(device),)
|
|
234
|
+
case StandardReadableFormat.HINTED_UNCACHED_SIGNAL:
|
|
235
|
+
assert isinstance(device, SignalR), f"{device} is not a SignalR"
|
|
236
|
+
self._describe_funcs += (device.describe,)
|
|
237
|
+
self._read_funcs += (_UncachedRead(device),)
|
|
238
|
+
self._has_hints += (_HintsFromName(device),)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class _UncachedRead:
|
|
242
|
+
def __init__(self, signal: SignalR) -> None:
|
|
221
243
|
self.signal = signal
|
|
222
244
|
|
|
223
|
-
async def
|
|
224
|
-
return await self.signal.read()
|
|
225
|
-
|
|
226
|
-
async def describe_configuration(self) -> dict[str, DataKey]:
|
|
227
|
-
return await self.signal.describe()
|
|
228
|
-
|
|
229
|
-
@property
|
|
230
|
-
def name(self) -> str:
|
|
231
|
-
return self.signal.name
|
|
245
|
+
async def __call__(self) -> dict[str, Reading]:
|
|
246
|
+
return await self.signal.read(cached=False)
|
|
232
247
|
|
|
233
248
|
|
|
234
|
-
class
|
|
235
|
-
def __init__(self,
|
|
236
|
-
|
|
237
|
-
self.signal = signal
|
|
238
|
-
self.cached = None if allow_cache else allow_cache
|
|
239
|
-
if allow_cache:
|
|
240
|
-
self.stage = signal.stage
|
|
241
|
-
self.unstage = signal.unstage
|
|
242
|
-
|
|
243
|
-
async def read(self) -> dict[str, Reading]:
|
|
244
|
-
return await self.signal.read(cached=self.cached)
|
|
245
|
-
|
|
246
|
-
async def describe(self) -> dict[str, DataKey]:
|
|
247
|
-
return await self.signal.describe()
|
|
249
|
+
class _HintsFromName(HasHints):
|
|
250
|
+
def __init__(self, device: Device) -> None:
|
|
251
|
+
self.device = device
|
|
248
252
|
|
|
249
253
|
@property
|
|
250
254
|
def name(self) -> str:
|
|
251
|
-
return self.
|
|
255
|
+
return self.device.name
|
|
252
256
|
|
|
253
257
|
@property
|
|
254
258
|
def hints(self) -> Hints:
|
|
255
|
-
if self.
|
|
256
|
-
|
|
257
|
-
return {"fields": [self.signal.name]}
|
|
258
|
-
|
|
259
|
-
@classmethod
|
|
260
|
-
def uncached(cls, signal: ReadableChild) -> "HintedSignal":
|
|
261
|
-
return cls(signal, allow_cache=False)
|
|
259
|
+
fields = [self.name] if self.name else []
|
|
260
|
+
return {"fields": fields}
|
ophyd_async/core/_utils.py
CHANGED
|
@@ -5,7 +5,15 @@ import logging
|
|
|
5
5
|
from collections.abc import Awaitable, Callable, Iterable, Sequence
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from enum import Enum, EnumMeta
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import (
|
|
9
|
+
Any,
|
|
10
|
+
Generic,
|
|
11
|
+
Literal,
|
|
12
|
+
ParamSpec,
|
|
13
|
+
TypeVar,
|
|
14
|
+
get_args,
|
|
15
|
+
get_origin,
|
|
16
|
+
)
|
|
9
17
|
|
|
10
18
|
import numpy as np
|
|
11
19
|
|
|
@@ -3,13 +3,8 @@ from collections.abc import Sequence
|
|
|
3
3
|
|
|
4
4
|
from bluesky.protocols import Triggerable
|
|
5
5
|
|
|
6
|
-
from ophyd_async.core import
|
|
7
|
-
|
|
8
|
-
ConfigSignal,
|
|
9
|
-
HintedSignal,
|
|
10
|
-
SignalR,
|
|
11
|
-
StandardReadable,
|
|
12
|
-
)
|
|
6
|
+
from ophyd_async.core import AsyncStatus, SignalR, StandardReadable
|
|
7
|
+
from ophyd_async.core import StandardReadableFormat as Format
|
|
13
8
|
|
|
14
9
|
from ._core_io import ADBaseIO, NDPluginBaseIO
|
|
15
10
|
from ._utils import ImageMode
|
|
@@ -28,10 +23,10 @@ class SingleTriggerDetector(StandardReadable, Triggerable):
|
|
|
28
23
|
|
|
29
24
|
self.add_readables(
|
|
30
25
|
[self.drv.array_counter, *read_uncached],
|
|
31
|
-
|
|
26
|
+
Format.HINTED_UNCACHED_SIGNAL,
|
|
32
27
|
)
|
|
33
28
|
|
|
34
|
-
self.add_readables([self.drv.acquire_time],
|
|
29
|
+
self.add_readables([self.drv.acquire_time], Format.CONFIG_SIGNAL)
|
|
35
30
|
|
|
36
31
|
super().__init__(name=name)
|
|
37
32
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from ophyd_async.core import StrictEnum
|
|
2
2
|
from ophyd_async.epics import adcore
|
|
3
|
-
from ophyd_async.epics.
|
|
3
|
+
from ophyd_async.epics.core import epics_signal_r, epics_signal_rw_rbv
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class PilatusTriggerMode(StrictEnum):
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from ._epics_connector import EpicsDeviceConnector, PvSuffix
|
|
2
|
+
from ._epics_device import EpicsDevice
|
|
3
|
+
from ._pvi_connector import PviDeviceConnector
|
|
4
|
+
from ._signal import (
|
|
5
|
+
CaSignalBackend,
|
|
6
|
+
PvaSignalBackend,
|
|
7
|
+
epics_signal_r,
|
|
8
|
+
epics_signal_rw,
|
|
9
|
+
epics_signal_rw_rbv,
|
|
10
|
+
epics_signal_w,
|
|
11
|
+
epics_signal_x,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"PviDeviceConnector",
|
|
16
|
+
"EpicsDeviceConnector",
|
|
17
|
+
"PvSuffix",
|
|
18
|
+
"EpicsDevice",
|
|
19
|
+
"CaSignalBackend",
|
|
20
|
+
"PvaSignalBackend",
|
|
21
|
+
"epics_signal_r",
|
|
22
|
+
"epics_signal_rw",
|
|
23
|
+
"epics_signal_rw_rbv",
|
|
24
|
+
"epics_signal_w",
|
|
25
|
+
"epics_signal_x",
|
|
26
|
+
]
|
|
@@ -24,7 +24,6 @@ from ophyd_async.core import (
|
|
|
24
24
|
Array1D,
|
|
25
25
|
Callback,
|
|
26
26
|
NotConnected,
|
|
27
|
-
SignalBackend,
|
|
28
27
|
SignalDatatype,
|
|
29
28
|
SignalDatatypeT,
|
|
30
29
|
SignalMetadata,
|
|
@@ -34,7 +33,7 @@ from ophyd_async.core import (
|
|
|
34
33
|
wait_for_connection,
|
|
35
34
|
)
|
|
36
35
|
|
|
37
|
-
from .
|
|
36
|
+
from ._util import EpicsSignalBackend, format_datatype, get_supported_values
|
|
38
37
|
|
|
39
38
|
|
|
40
39
|
def _limits_from_augmented_value(value: AugmentedValue) -> Limits:
|
|
@@ -227,19 +226,17 @@ def _use_pyepics_context_if_imported():
|
|
|
227
226
|
_tried_pyepics = True
|
|
228
227
|
|
|
229
228
|
|
|
230
|
-
class CaSignalBackend(
|
|
229
|
+
class CaSignalBackend(EpicsSignalBackend[SignalDatatypeT]):
|
|
231
230
|
def __init__(
|
|
232
231
|
self,
|
|
233
232
|
datatype: type[SignalDatatypeT] | None,
|
|
234
233
|
read_pv: str = "",
|
|
235
234
|
write_pv: str = "",
|
|
236
235
|
):
|
|
237
|
-
self.read_pv = read_pv
|
|
238
|
-
self.write_pv = write_pv
|
|
239
236
|
self.converter: CaConverter = DisconnectedCaConverter(float, dbr.DBR_DOUBLE)
|
|
240
237
|
self.initial_values: dict[str, AugmentedValue] = {}
|
|
241
238
|
self.subscription: Subscription | None = None
|
|
242
|
-
super().__init__(datatype)
|
|
239
|
+
super().__init__(datatype, read_pv, write_pv)
|
|
243
240
|
|
|
244
241
|
def source(self, name: str, read: bool):
|
|
245
242
|
return f"ca://{self.read_pv if read else self.write_pv}"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from ophyd_async.core import Device, DeviceConnector, DeviceFiller
|
|
7
|
+
|
|
8
|
+
from ._signal import EpicsSignalBackend, get_signal_backend_type, split_protocol_from_pv
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class PvSuffix:
|
|
13
|
+
read_suffix: str
|
|
14
|
+
write_suffix: str | None = None
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def rbv(cls, write_suffix: str, rbv_suffix: str = "_RBV") -> PvSuffix:
|
|
18
|
+
return cls(write_suffix + rbv_suffix, write_suffix)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def fill_backend_with_prefix(
|
|
22
|
+
prefix: str, backend: EpicsSignalBackend, annotations: list[Any]
|
|
23
|
+
):
|
|
24
|
+
unhandled = []
|
|
25
|
+
while annotations:
|
|
26
|
+
annotation = annotations.pop(0)
|
|
27
|
+
if isinstance(annotation, PvSuffix):
|
|
28
|
+
backend.read_pv = prefix + annotation.read_suffix
|
|
29
|
+
backend.write_pv = prefix + (
|
|
30
|
+
annotation.write_suffix or annotation.read_suffix
|
|
31
|
+
)
|
|
32
|
+
else:
|
|
33
|
+
unhandled.append(annotation)
|
|
34
|
+
annotations.extend(unhandled)
|
|
35
|
+
# These leftover annotations will now be handled by the iterator
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class EpicsDeviceConnector(DeviceConnector):
|
|
39
|
+
def __init__(self, prefix: str) -> None:
|
|
40
|
+
self.prefix = prefix
|
|
41
|
+
|
|
42
|
+
def create_children_from_annotations(self, device: Device):
|
|
43
|
+
if not hasattr(self, "filler"):
|
|
44
|
+
protocol, prefix = split_protocol_from_pv(self.prefix)
|
|
45
|
+
self.filler = DeviceFiller(
|
|
46
|
+
device,
|
|
47
|
+
signal_backend_factory=get_signal_backend_type(protocol),
|
|
48
|
+
device_connector_factory=DeviceConnector,
|
|
49
|
+
)
|
|
50
|
+
for backend, annotations in self.filler.create_signals_from_annotations():
|
|
51
|
+
fill_backend_with_prefix(prefix, backend, annotations)
|
|
52
|
+
|
|
53
|
+
list(self.filler.create_devices_from_annotations())
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from ophyd_async.core import Device
|
|
2
|
+
|
|
3
|
+
from ._epics_connector import EpicsDeviceConnector
|
|
4
|
+
from ._pvi_connector import PviDeviceConnector
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class EpicsDevice(Device):
|
|
8
|
+
def __init__(self, prefix: str, with_pvi: bool = False, name: str = ""):
|
|
9
|
+
if with_pvi:
|
|
10
|
+
connector = PviDeviceConnector(prefix)
|
|
11
|
+
else:
|
|
12
|
+
connector = EpicsDeviceConnector(prefix)
|
|
13
|
+
super().__init__(name=name, connector=connector)
|
|
@@ -18,7 +18,6 @@ from ophyd_async.core import (
|
|
|
18
18
|
Array1D,
|
|
19
19
|
Callback,
|
|
20
20
|
NotConnected,
|
|
21
|
-
SignalBackend,
|
|
22
21
|
SignalDatatype,
|
|
23
22
|
SignalDatatypeT,
|
|
24
23
|
SignalMetadata,
|
|
@@ -30,7 +29,7 @@ from ophyd_async.core import (
|
|
|
30
29
|
wait_for_connection,
|
|
31
30
|
)
|
|
32
31
|
|
|
33
|
-
from .
|
|
32
|
+
from ._util import EpicsSignalBackend, format_datatype, get_supported_values
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
def _limits_from_value(value: Any) -> Limits:
|
|
@@ -293,19 +292,17 @@ def _pva_request_string(fields: Sequence[str]) -> str:
|
|
|
293
292
|
return f"field({','.join(fields)})"
|
|
294
293
|
|
|
295
294
|
|
|
296
|
-
class PvaSignalBackend(
|
|
295
|
+
class PvaSignalBackend(EpicsSignalBackend[SignalDatatypeT]):
|
|
297
296
|
def __init__(
|
|
298
297
|
self,
|
|
299
298
|
datatype: type[SignalDatatypeT] | None,
|
|
300
299
|
read_pv: str = "",
|
|
301
300
|
write_pv: str = "",
|
|
302
301
|
):
|
|
303
|
-
self.read_pv = read_pv
|
|
304
|
-
self.write_pv = write_pv
|
|
305
302
|
self.converter: PvaConverter = DisconnectedPvaConverter(float)
|
|
306
303
|
self.initial_values: dict[str, Any] = {}
|
|
307
304
|
self.subscription: Subscription | None = None
|
|
308
|
-
super().__init__(datatype)
|
|
305
|
+
super().__init__(datatype, read_pv, write_pv)
|
|
309
306
|
|
|
310
307
|
def source(self, name: str, read: bool):
|
|
311
308
|
return f"pva://{self.read_pv if read else self.write_pv}"
|