Commit f04daa1c authored by bliss administrator's avatar bliss administrator
Browse files

ID26FastShutter based on bliss.common BaseShutter for daiquiri

remove unused definition of some BaseShutter methods

use Cache for state + typo bug fix

add callback for emitting channel change
parent 78eba0be
import time
from bliss import setup_globals, current_session
from enum import Enum
from bliss import setup_globals, global_map
from bliss.comm.serial import CommunicationError
#from bliss.common import event
from bliss.common.shutter import BaseShutter, BaseShutterState
#from bliss.config.channels import Channel
from bliss.config.channels import Cache
from bliss.config.settings import SimpleSetting
from bliss.scanning.chain import ChainPreset, ChainIterationPreset
from bliss.common import event
'''
package: id26.controllers.fast_shutter
class: ID26FastShutter
name: fsh
opiom: $opiom_cc1
name: fsh2
multiplexer: $multiplexer_opiom_cc1
opiom: $opiom_cc1
'''
class FShutterChainPreset (ChainPreset):
def __init__(self, sh_ctrl):
ChainPreset.__init__(self)
self.sh_ctrl = sh_ctrl
print (f'{self.sh_ctrl.name} will automatically operate Fast Shutter')
def prepare(self, acq_chain):
pass
def start(self, acq_chain):
print (f'{self.sh_ctrl.name} opens Fast Shutter')
self.sh_ctrl.open_fast()
time.sleep(self.sh_ctrl.delay)
def stop(self, acq_chain):
print (f'{self.sh_ctrl.name} closes Fast Shutter')
self.sh_ctrl.close_fast()
class FShutterChainIterationPreset(ChainPreset):
def __init__(self, sh_ctrl):
ChainPreset.__init__(self)
self.sh_ctrl = sh_ctrl
class Iterator(ChainIterationPreset):
def __init__(self,iteration_nb, sh_ctrl):
self.iteration = iteration_nb
self.sh_ctrl = sh_ctrl
def prepare(self):
#print(f"Preparing iteration {self.iteration}")
pass
def start(self):
#print (f'{self.sh_ctrl.name} opens Fast Shutter')
self.sh_ctrl.open_fast()
time.sleep(self.sh_ctrl.delay)
def stop(self):
#print (f'{self.sh_ctrl.name} closes Fast Shutter')
self.sh_ctrl.close_fast()
def get_iterator(self,acq_chain):
iteration_nb = 0
while True:
yield FShutterChainIterationPreset.Iterator(iteration_nb, self.sh_ctrl)
iteration_nb += 1
ID26FastShutterState = Enum(
"ID26FastShutterState",
dict(
{
"AUTO": "Auto",
},
**{item.name: item.value for item in BaseShutterState},
),
)
#class ID26FastShutter_with_chainpreset:
class ID26FastShutter:
class ID26FastShutter(BaseShutter):
def __init__ (self, name, config_dict):
self.__name = name
self.__config = config_dict
self.__control = config_dict['multiplexer']
self.__state = Cache(self, "state", default_value=ID26FastShutterState.UNKNOWN, callback=self.__state_changed)
global_map.register(self, children_list=[self.__control], tag=f"Shutter:{name}")
self.opiom = config_dict['opiom']
self.multiplexer = config_dict['multiplexer']
self.name = name
self._auto = SimpleSetting ('fson',default_value = 0)
self._delay = SimpleSetting ('fsdelay',default_value = 0.05)
self._preset = None
def __state_changed(self, state):
"""Send a signal when state changes"""
event.send(self, "state", state)
@property
def name(self):
"""A unique name"""
return self.__name
@property
def config(self):
"""Config of shutter"""
return self.__config
@property
def state(self):
try:
if self._auto.get():
self.__state.value = ID26FastShutterState.AUTO
else:
state = self.multiplexer.getOutputStat('SOFT_SHUTTER')
if 'CLOSE' in state:
self.__state.value = ID26FastShutterState.CLOSED
else:
self.__state.value = ID26FastShutterState.__members__[state]
except CommunicationError:
self.__state.value = ID26FastShutterState.UNKNOWN
#raise RuntimeError(f"Communication Error with {self.opiom}")
return self.__state.value
def __info__(self):
msg = "Shutter is " + self.state()
msg = "Shutter is " + self.state.value
msg += "\nAutomatic opening during counting: "
msg += 'ON' if self._auto.get() else 'OFF'
msg += "\nAutomatic opening during zap: "
......@@ -83,7 +84,6 @@ class ID26FastShutter:
msg += f'\ndelay for shutter opening is {self.delay*1000} ms'
return(msg)
@property
def delay(self):
return self._delay.get()
......@@ -92,27 +92,27 @@ class ID26FastShutter:
def delay (self, value):
self._delay.set(value)
def state(self):
#print ('.multiplexer.getOutputStat(\'SOFT_SHUTTER\')',self.multiplexer.getOutputStat('SOFT_SHUTTER'))
if self._auto.get():
return 'AUTO'
else:
return (self.multiplexer.getOutputStat('SOFT_SHUTTER'))
def open (self):
self.multiplexer.switch('soft_shutter','open')
if not self._auto.get():
self.__state.value = ID26FastShutterState.OPEN
def close (self):
self.multiplexer.switch('soft_shutter','close')
if not self._auto.get():
self.__state.value = ID26FastShutterState.CLOSED
def open_fast (self):
if self.opiom.comm_ack('IMA 0x01 0x01') != 'OK':
raise RuntimeError ('Bad answer from opiom')
if not self._auto.get():
self.__state.value = ID26FastShutterState.OPEN
def close_fast (self):
if self.opiom.comm_ack('IMA 0x00 0x01') != 'OK':
raise RuntimeError ('Bad answer from opiom')
if not self._auto.get():
self.__state.value = ID26FastShutterState.CLOSED
def auto_on (self):
self.multiplexer.switch('soft_shutter','close')
......@@ -121,6 +121,7 @@ class ID26FastShutter:
if self._preset == None:
self._preset = FShutterChainIterationPreset(self)
setup_globals.DEFAULT_CHAIN.add_preset(self._preset)
self.__state.value = ID26FastShutterState.AUTO
def auto_off (self):
#self.multiplexer.switch('soft_shutter','close')
......@@ -131,12 +132,65 @@ class ID26FastShutter:
except:
pass
self._preset = None
print (f'fast shutter is {self.state}')
class FShutterChainPreset (ChainPreset):
def __init__(self, sh_ctrl):
ChainPreset.__init__(self)
self.sh_ctrl = sh_ctrl
print (f'{self.sh_ctrl.name} will automatically operate Fast Shutter')
def prepare(self, acq_chain):
pass
def start(self, acq_chain):
print (f'{self.sh_ctrl.name} opens Fast Shutter')
self.sh_ctrl.open_fast()
time.sleep(self.sh_ctrl.delay)
def stop(self, acq_chain):
print (f'{self.sh_ctrl.name} closes Fast Shutter')
self.sh_ctrl.close_fast()
class FShutterChainIterationPreset(ChainPreset):
def __init__(self, sh_ctrl):
ChainPreset.__init__(self)
self.sh_ctrl = sh_ctrl
class Iterator(ChainIterationPreset):
def __init__(self,iteration_nb, sh_ctrl):
self.iteration = iteration_nb
self.sh_ctrl = sh_ctrl
def prepare(self):
#print(f"Preparing iteration {self.iteration}")
pass
def start(self):
#print (f'{self.sh_ctrl.name} opens Fast Shutter')
self.sh_ctrl.open_fast()
time.sleep(self.sh_ctrl.delay)
def stop(self):
#print (f'{self.sh_ctrl.name} closes Fast Shutter')
self.sh_ctrl.close_fast()
def get_iterator(self,acq_chain):
iteration_nb = 0
while True:
yield FShutterChainIterationPreset.Iterator(iteration_nb, self.sh_ctrl)
iteration_nb += 1
#class ID26FastShutter:
class ID26FastShutter_with_opiom_fson:
class old_ID26FastShutter_with_opiom_fson:
def __init__ (self, name, config_dict):
self.opiom = config_dict['opiom']
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment