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

Ophyd device for DG-645 #874

Closed
prjemian opened this issue Aug 21, 2023 · 2 comments · Fixed by #877
Closed

Ophyd device for DG-645 #874

prjemian opened this issue Aug 21, 2023 · 2 comments · Fixed by #877
Assignees
Milestone

Comments

@prjemian
Copy link
Contributor

prjemian commented Aug 21, 2023

I noticed the DG-645 is listed here but I don't see any issues or commits that add it. Happy to do it myself, just checking before I get started in case it's been done already. Thanks!

Originally posted by @canismarko in #489 (comment)

@canismarko
Copy link
Collaborator

Sounds good. I'll get on it.

@prjemian prjemian added this to To do in 1.6.18 project via automation Aug 30, 2023
@prjemian prjemian added this to the 1.6.18 milestone Aug 30, 2023
@prjemian prjemian moved this from To do to Review in progress in 1.6.18 project Aug 30, 2023
1.6.18 project automation moved this from Review in progress to Done Aug 30, 2023
@canismarko
Copy link
Collaborator

@prjemian, putting this here so it's documented in case anyone runs into this problem.

The DG-645 support I put in the PR uses a subclass of ophyd.EpicsSignal: EpicsSignalWithIO.

I came across an edge case where if you use the DG645 delay device with ophyd.sim.make_fake_device it doesn't recognize EpicsSignalWithIO, and so doesn't fake it. You can still create a fake device from it, but if you access any of the signals that use the custom EpicsSignalWithIO class, it will time out because the PV is not available:

from ophyd.sim import make_fake_device
from apstools.devices.delay import DG645Delay

@pytest.fixture()
def fake_delay():
    Delay = make_fake_device(DG645Delay)
    return Delay("255id:DG645:", name="fake_delay")

def test_fake_delay(fake_delay):
    fake_delay.label.get()  # Success, since it's a regular EpicsSignal
    fake_delay.dhcp_state.get()  # TimeoutError, since it's an EpicsSignalWithIO

Ophyd sim module builds a cache of signals that it knows how to fake, so we can add our own fake signal to the cache before calling make_fake_device(DG645Delay). The solution then, assuming you use pytest, is to place the following in conftest.py

from ophyd.sim import FakeEpicsSignal, fake_device_cache

from apstools.devices.delay import EpicsSignalWithIO

class FakeEpicsSignalWithIO(FakeEpicsSignal):
    """An EPICS signal that simply uses the DG-645 convention of
    'AO' being the setpoint and 'AI' being the read-back."""
    _metadata_keys = EpicsSignalWithIO._metadata_keys

    def __init__(self, prefix, **kwargs):
        super().__init__(f"{prefix}I", write_pv=f"{prefix}O", **kwargs)


fake_device_cache[EpicsSignalWithIO] = FakeEpicsSignalWithIO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants