Skip to content

Commit

Permalink
tango_polling will take a tuple to enable polling across all signals …
Browse files Browse the repository at this point in the history
…in a device and/or a dict to enable polling for individual signals.
  • Loading branch information
burkeds committed Sep 5, 2024
1 parent 063bf7a commit 3a91d77
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/ophyd_async/tango/base_devices/_tango_readable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Optional, Tuple, Union
from typing import Optional, Union

from ophyd_async.core import (
StandardReadable,
Expand All @@ -24,8 +24,6 @@ class TangoReadable(TangoDevice, StandardReadable):
device is connected.
"""

_polling: Tuple = (False, 0.1, None, 0.1)

def __init__(
self,
trl: Optional[str] = None,
Expand Down
5 changes: 4 additions & 1 deletion src/ophyd_async/tango/demo/_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
Signal,
SignalX,
)
from ophyd_async.tango import TangoReadable
from ophyd_async.tango import TangoReadable, tango_polling


@dataclass
class TangoCounterConfig:
sample_time: Optional[float] = None


# Enable device level polling, useful for servers that do not support events
# Polling for individual signal can be enabled with a dict
@tango_polling((0.1, 0.1, 0.1), {"counts": (1.0, 0.1, 0.1)})
class TangoCounter(TangoReadable):
# Enter the name and type of the signals you want to use
# If type is None or Signal, the type will be inferred from the Tango device
Expand Down
3 changes: 2 additions & 1 deletion src/ophyd_async/tango/demo/_mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class TangoMoverConfig:
velocity: Optional[float] = None


@tango_polling(0.1, 0.1, 0.1)
# Enable device level polling, useful for servers that do not support events
@tango_polling((0.1, 0.1, 0.1))
class TangoMover(TangoReadable, Movable, Stoppable):
# Enter the name and type of the signals you want to use
# If type is None or Signal, the type will be inferred from the Tango device
Expand Down
8 changes: 4 additions & 4 deletions src/ophyd_async/tango/signal/_tango_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def __init__(
}
self.trl_configs: Dict[str, AttributeInfoEx] = {}
self.descriptor: Descriptor = {} # type: ignore
self.polling = (False, 0.1, None, 0.1)
self._polling = (False, 0.1, None, 0.1)
self.support_events = True
self.status = None

Expand All @@ -619,7 +619,7 @@ async def connect(self, timeout: float = DEFAULT_TIMEOUT):
else:
# The same, so only need to connect one
await self._connect_and_store_config(self.read_trl)
self.proxies[self.read_trl].set_polling(*self.polling)
self.proxies[self.read_trl].set_polling(*self._polling)
self.descriptor = get_trl_descriptor(
self.datatype, self.read_trl, self.trl_configs
)
Expand All @@ -642,7 +642,7 @@ async def get_setpoint(self) -> T:
return await self.proxies[self.write_trl].get_w_value()

def set_callback(self, callback: Optional[ReadingValueCallback]) -> None:
if self.support_events is False and self.polling[0] is False:
if self.support_events is False and self._polling[0] is False:
raise RuntimeError(
f"Cannot set event for {self.read_trl}. "
"Cannot set a callback on an attribute that does not support events and"
Expand All @@ -668,7 +668,7 @@ def set_polling(
abs_change=None,
rel_change=0.1,
):
self.polling = (allow_polling, polling_period, abs_change, rel_change)
self._polling = (allow_polling, polling_period, abs_change, rel_change)

def allow_events(self, allow: Optional[bool] = True):
self.support_events = allow

0 comments on commit 3a91d77

Please sign in to comment.