Files
camserver_sf/configuration/user_scripts/SINBC02-DSRM310_sp.py
2021-05-17 17:13:03 +02:00

53 lines
1.7 KiB
Python

from cam_server.pipeline.data_processing import processor
from logging import getLogger
import epics
from cam_server.utils import create_thread_pvs
SELECTION_CHANNEL_NAME = "SGE-CPCW-13-EVR0:FrontUnivOut1-Src-SP"
SELECTION_PULSE_1 = 8
SELECTION_PULSE_2 = 9
selection_pv = None
initialized = False
current_pulse = None
_logger = getLogger(__name__)
def initialize(parameters):
global selection_pv, initialized,current_pulse
epics.ca.clear_cache()
[selection_pv] = create_thread_pvs([SELECTION_CHANNEL_NAME])
selection_pv.wait_for_connection()
#If raising this exception then the pipeline won't start
if not selection_pv.connected:
raise ("Cannot connect to " + SELECTION_CHANNEL_NAME)
current_pulse = 2 if (selection_pv.get()==SELECTION_PULSE_2) else 1
_logger.warning("Initial pulse: " + str(current_pulse))
initialized = True
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
global selection_pv, initialized,current_pulse
if not initialized:
initialize(parameters)
current_pulse = 2 if (selection_pv.value==SELECTION_PULSE_2) else 1
if parameters.get("pulse"):
pulse = 2 if (int(parameters.get("pulse")) == 2) else 1
_logger.warning("Commanded pulse: " + str(pulse))
if pulse != current_pulse:
selection_pv.put(SELECTION_PULSE_2 if (pulse==2) else SELECTION_PULSE_1)
current_pulse = pulse
_logger.warning("Selected pulse: " + str(current_pulse))
parameters["pulse"] = None
ret = processor.process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata)
ret["pulse"]=current_pulse
return ret