Skip to content

Instantly share code, notes, and snippets.

@danielballan
Last active May 18, 2023 20:01
Show Gist options
  • Save danielballan/7a30d994d950d527a7c82a41ab735462 to your computer and use it in GitHub Desktop.
Save danielballan/7a30d994d950d527a7c82a41ab735462 to your computer and use it in GitHub Desktop.
Device with custom set
from ophyd.sim import Signal
from ophyd import Component, Device
class Filters(Device):
a = Component(Signal, value=0)
b = Component(Signal, value=1)
def set(self, a, b):
return (
self.a.set(a) &
self.b.set(b)
)
def set_attenuation(self, value):
# math..
return self.set(value, -value)
f = Filters(name="f")
@danielballan
Copy link
Author

In [7]: f
Out[7]: Filters(prefix='', name='f', read_attrs=['a', 'b'], configuration_attrs=[])

In [8]: f.read()
Out[8]: 
OrderedDict([('f_a', {'value': 0, 'timestamp': 1684439958.1712534}),
             ('f_b', {'value': 1, 'timestamp': 1684439958.1712852})])

In [9]: f.get()
Out[9]: FiltersTuple(a=0, b=1)

In [10]: f.set(a=5, b=10).wait()

In [11]: f.read()
Out[11]: 
OrderedDict([('f_a', {'value': 5, 'timestamp': 1684439994.8954685}),
             ('f_b', {'value': 10, 'timestamp': 1684439994.895793})])

In [12]: f.set_attenuation(7).wait()

In [13]: f.read()
Out[13]: 
OrderedDict([('f_a', {'value': 7, 'timestamp': 1684440007.746424}),
             ('f_b', {'value': -7, 'timestamp': 1684440007.7467787})])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment