Skip to content

Commit

Permalink
Add epics_signal_rw_rbv helper function
Browse files Browse the repository at this point in the history
Add tests for all signal creation helpers
  • Loading branch information
GDYendell committed Apr 17, 2024
1 parent ea7bf60 commit 5fa019d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ophyd_async/epics/signal/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ def epics_signal_rw(
return SignalRW(backend)


def epics_signal_rw_rbv(
datatype: Type[T],
write_pv: Optional[str] = None,
read_suffix: str = "_RBV",
) -> SignalRW[T]:
"""Create a `SignalRW` backed by 1 or 2 EPICS PVs, with a suffix on the readback pv
Parameters
----------
datatype:
Check that the PV is of this type
write_pv:
The PV to write to
read_suffix:
Append this suffix to the write pv to create the readback pv
"""
return epics_signal_rw(datatype, f"{write_pv}{read_suffix}", write_pv)


def epics_signal_r(datatype: Type[T], read_pv: str) -> SignalR[T]:
"""Create a `SignalR` backed by 1 EPICS PV
Expand Down
34 changes: 34 additions & 0 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
wait_for_value,
)
from ophyd_async.core.utils import DEFAULT_TIMEOUT
from ophyd_async.epics.signal.signal import (
epics_signal_r,
epics_signal_rw,
epics_signal_rw_rbv,
epics_signal_w,
epics_signal_x,
)


class MySignal(Signal):
Expand Down Expand Up @@ -119,3 +126,30 @@ async def test_set_and_wait_for_value():
assert not st.done
set_sim_put_proceeds(sim_signal, True)
assert await time_taken_by(st) < 0.1


def test_signal_helpers():
read_write = epics_signal_rw(int, "ReadWrite")
assert read_write._backend.read_pv == "ReadWrite"
assert read_write._backend.write_pv == "ReadWrite"

read_write_rbv_manual = epics_signal_rw(int, "ReadWrite_RBV", "ReadWrite")
assert read_write_rbv_manual._backend.read_pv == "ReadWrite_RBV"
assert read_write_rbv_manual._backend.write_pv == "ReadWrite"

read_write_rbv = epics_signal_rw_rbv(int, "ReadWrite")
assert read_write_rbv._backend.read_pv == "ReadWrite_RBV"
assert read_write_rbv._backend.write_pv == "ReadWrite"

read_write_rbv_suffix = epics_signal_rw_rbv(int, "ReadWrite", read_suffix=":RBV")
assert read_write_rbv_suffix._backend.read_pv == "ReadWrite:RBV"
assert read_write_rbv_suffix._backend.write_pv == "ReadWrite"

read = epics_signal_r(int, "Read")
assert read._backend.read_pv == "Read"

write = epics_signal_w(int, "Write")
assert write._backend.write_pv == "Write"

execute = epics_signal_x("Execute")
assert execute._backend.write_pv == "Execute"

0 comments on commit 5fa019d

Please sign in to comment.