Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper methods to epics adapter for easily PV building #198

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions examples/configs/signal-generator.yaml

This file was deleted.

49 changes: 29 additions & 20 deletions src/tickit/adapters/epics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import logging
from abc import abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Any, Awaitable, Callable, Dict, Optional, Set, TypeVar
from typing import Any, Awaitable, Callable, Dict, Optional, Set

from softioc import asyncio_dispatcher, builder, softioc

Expand Down Expand Up @@ -42,6 +41,7 @@ def register_adapter() -> int:
def register_background_task(task: Awaitable[None]) -> None:
_REGISTERED_IOC_BACKGROUND_TASKS.add(task)


def notify_adapter_ready(adapter_id: int) -> None:
"""Notify the builder that a particular adapter has made all the records it needs.

Expand Down Expand Up @@ -103,25 +103,45 @@ class OutputRecord:
class EpicsAdapter:
"""An adapter interface for the EpicsIo."""

interrupt_records: Dict[InputRecord, Callable[[], Any]] = {}
interrupt_records: Dict[InputRecord, Callable[[], Any]]
interrupt: RaiseInterrupt

def __init__(self) -> None:
self.interrupt_records = {}

def float_rbv(
self,
name: str,
getter: Callable[[], float],
setter: Callable[[float], None],
rbv_name: Optional[str] = None,
precision: int = 2,
):
rbv_name = rbv_name or f"{name}_RBV"
builder.aOut(
name,
initial_value=getter(),
on_update=self.interrupting_callback(setter),
PREC=precision,
)
rbv = builder.aIn(
rbv_name,
initial_value=getter(),
PREC=precision,
)
rbv = builder.aIn(rbv_name, initial_value=getter())
self.link_input_on_interrupt(rbv, getter)

def float_ro(
self,
name: str,
getter: Callable[[], float],
precision: int = 2,
):
self.link_input_on_interrupt(
builder.aIn(name, PREC=precision),
getter,
)

def int_rbv(
self,
name: str,
Expand Down Expand Up @@ -154,22 +174,11 @@ def bool_rbv(
rbv = builder.boolIn(rbv_name, initial_value=getter())
self.link_input_on_interrupt(rbv, getter)

def bool_rbv(
self,
name: str,
getter: Callable[[], bool],
setter: Callable[[bool], None],
rbv_name: Optional[str] = None,
):
rbv_name = rbv_name or f"{name}_RBV"
builder.boolOut(
name,
initial_value=getter(),
on_update=self.interrupting_callback(setter),
def bool_ro(self, name: str, getter: Callable[[], float]):
self.link_input_on_interrupt(
builder.boolIn(name),
getter,
)
rbv = builder.boolIn(rbv_name, initial_value=getter())
self.link_input_on_interrupt(rbv, getter)


def interrupting_callback(
self, action: Callable[[Any], None]
Expand Down Expand Up @@ -208,5 +217,5 @@ async def polling_task() -> None:
while True:
await asyncio.sleep(interval)
await self.interrupt()

register_background_task(polling_task())
Loading
Loading