refactor: ES0Filter device with EpicsSignalWithRBVBit
This commit is contained in:
@@ -1,89 +1,53 @@
|
||||
""" ES0 Filter Station"""
|
||||
|
||||
from ophyd import Component as Cpt
|
||||
from ophyd import Device, Kind, EpicsSignalWithRBV
|
||||
from ophyd import Device, Kind, EpicsSignal
|
||||
from typing import Literal
|
||||
from typeguard import typechecked
|
||||
|
||||
from ophyd_devices.utils import bec_utils
|
||||
|
||||
class ES0Filter(Device):
|
||||
"""Class for the ES0 filter station"""
|
||||
class EpicsSignalWithRBVBit(EpicsSignal):
|
||||
|
||||
USER_ACCESS = ['set_filters']
|
||||
def __init__(self, prefix, *, bit:int, **kwargs):
|
||||
super().__init__(prefix, **kwargs)
|
||||
self.bit = bit
|
||||
|
||||
filter_output = Cpt(
|
||||
EpicsSignalWithRBV,
|
||||
suffix="BIO",
|
||||
kind="config",
|
||||
doc='Packed value of filter positions'
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, prefix="", *, name: str, kind: Kind = None, device_manager=None, parent=None, **kwargs
|
||||
):
|
||||
"""Initialize the ES0 Filter Station.
|
||||
|
||||
Args:
|
||||
prefix (str): EPICS prefix for the device
|
||||
name (str): Name of the device
|
||||
kind (Kind): Kind of the device
|
||||
device_manager (DeviceManager): Device manager instance
|
||||
parent (Device): Parent device
|
||||
kwargs: Additional keyword arguments
|
||||
"""
|
||||
super().__init__(prefix, name=name, kind=kind, parent=parent, **kwargs)
|
||||
self.device_manager = device_manager
|
||||
self.service_cfg = None
|
||||
|
||||
self.timeout_for_pvwait = 2.5
|
||||
self.readback.name = self.name
|
||||
# Wait for connection on all components, ensure IOC is connected
|
||||
self.wait_for_connection(all_signals=True, timeout=5)
|
||||
|
||||
if device_manager:
|
||||
self.device_manager = device_manager
|
||||
@typechecked
|
||||
def put(self, value:Literal[0,1], **kwargs):
|
||||
bit_value = super().get()
|
||||
#convert to int
|
||||
bit_value = int(bit_value)
|
||||
if value ==1:
|
||||
new_value = bit_value | (1 << self.bit)
|
||||
else:
|
||||
self.device_manager = bec_utils.DMMock()
|
||||
new_value = bit_value & ~(1 << self.bit)
|
||||
super().put(new_value, **kwargs)
|
||||
|
||||
self.connector = self.device_manager.connector
|
||||
def get(self, **kwargs) -> Literal[0,1]:
|
||||
bit_value = super().get()
|
||||
#convert to int
|
||||
bit_value = int(bit_value)
|
||||
if (bit_value & (1 << self.bit)) ==0:
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def set_filters(self, filters: list) -> None:
|
||||
"""Configure the filters according to the list
|
||||
|
||||
Args:
|
||||
filters (list) : List of strings representing the filters, e.g. ['Mo400', 'Al20']
|
||||
"""
|
||||
class ES0Filter(Device):
|
||||
"""Class for the ES0 filter station X01DA-ES0-FI:"""
|
||||
|
||||
output = 0
|
||||
for filter in filters:
|
||||
match filter:
|
||||
case 'Mo400':
|
||||
output = output & (1 << 1)
|
||||
case 'Mo300':
|
||||
output = output & (1 << 2)
|
||||
case 'Mo200':
|
||||
output = output & (1 << 3)
|
||||
case 'Zn500':
|
||||
output = output & (1 << 4)
|
||||
case 'Zn250':
|
||||
output = output & (1 << 5)
|
||||
case 'Zn125':
|
||||
output = output & (1 << 6)
|
||||
case 'Zn50':
|
||||
output = output & (1 << 7)
|
||||
case 'Zn25':
|
||||
output = output & (1 << 8)
|
||||
case 'Al500':
|
||||
output = output & (1 << 9)
|
||||
case 'Al320':
|
||||
output = output & (1 << 10)
|
||||
case 'Al200':
|
||||
output = output & (1 << 11)
|
||||
case 'Al100':
|
||||
output = output & (1 << 12)
|
||||
case 'Al50':
|
||||
output = output & (1 << 13)
|
||||
case 'Al20':
|
||||
output = output & (1 << 14)
|
||||
case 'Al10':
|
||||
output = output & (1 << 15)
|
||||
self.filter_output.put(output)
|
||||
Mo400 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=1,kind="config",doc='Mo400 filter')
|
||||
Mo300 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=2,kind="config",doc='Mo300 filter')
|
||||
Mo200 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=3,kind="config",doc='Mo200 filter')
|
||||
Zn500 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=4,kind="config",doc='Zn500 filter')
|
||||
Zn250 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=5,kind="config",doc='Zn250 filter')
|
||||
Zn125 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=6,kind="config",doc='Zn125 filter')
|
||||
Zn50 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=7,kind="config",doc='Zn50 filter')
|
||||
Zn25 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=8,kind="config",doc='Zn25 filter')
|
||||
Al500 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=9,kind="config",doc='Al500 filter')
|
||||
Al320 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=10,kind="config",doc='Al320 filter')
|
||||
Al200 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=11,kind="config",doc='Al200 filter')
|
||||
Al100 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=12,kind="config",doc='Al100 filter')
|
||||
Al50 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=13,kind="config",doc='Al50 filter')
|
||||
Al20 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=14,kind="config",doc='Al20 filter')
|
||||
Al10 = Cpt(EpicsSignalWithRBVBit, suffix="BIO", bit=15,kind="config",doc='Al10 filter')
|
||||
Reference in New Issue
Block a user