Commit e64cca92 authored by Vincent Michel's avatar Vincent Michel
Browse files

Add trigger mode to the mercury controller

parent 5fbd4a80
......@@ -110,9 +110,6 @@ class BaseMCA(object):
# Acquisition
def prepare_acquisition(self):
raise NotImplementedError
def start_acquisition(self):
raise NotImplementedError
......@@ -131,13 +128,14 @@ class BaseMCA(object):
# Extra logic
def run_single_acquisition(self, acquisition_time=1., polling_time=0.1):
# Prepare
# Trigger mode
self.set_trigger_mode(None)
# Preset mode
realtime = PresetMode.REALTIME in self.supported_preset_modes
if realtime:
self.set_preset_mode(PresetMode.REALTIME, acquisition_time)
else:
self.set_preset_mode(None)
self.prepare_acquisition()
# Start and wait
self.start_acquisition()
if realtime:
......@@ -148,3 +146,25 @@ class BaseMCA(object):
# Stop and return data
self.stop_acquisition()
return self.get_acquisition_data(), self.get_acquisition_statistics()
def run_external_acquisition(self, acquistion_time=None, polling_time=0.1):
# Trigger mode
mode = TriggerMode.EXTERNAL if acquistion_time else TriggerMode.GATE
if mode not in self.supported_trigger_modes:
raise ValueError('{} is not supported'.format(mode))
self.set_trigger_mode(mode)
# Preset mode
if acquistion_time:
self.set_preset_mode(PresetMode.REALTIME, acquistion_time)
else:
self.set_preset_mode(None)
# Start and wait
self.start_acquisition()
previous = current = 0.
while current == 0. or previous != current:
time.sleep(polling_time)
previous = current
current = self.get_acquisition_statistics()[0].realtime
# Stop and return data
self.stop_acquisition()
return self.get_acquisition_data(), self.get_acquisition_statistics()
......@@ -6,7 +6,7 @@ from numbers import Number
import zerorpc
import msgpack_numpy
from .mca import BaseMCA, Brand, DetectorType, PresetMode, Stats
from .mca import BaseMCA, Brand, DetectorType, PresetMode, Stats, TriggerMode
# Patch msgpack
msgpack_numpy.patch()
......@@ -109,9 +109,6 @@ class Mercury(BaseMCA):
# Acquisition
def prepare_acquisition(self):
pass
def start_acquisition(self):
self._proxy.start_run()
......@@ -160,13 +157,15 @@ class Mercury(BaseMCA):
if mode is None:
mode = PresetMode.NONE
# Check arguments
if mode not in self.supported_preset_modes:
raise ValueError('{:s} preset mode not supported'.format(mode))
if mode == PresetMode.NONE and value is not None:
raise TypeError(
'P1reset value should be None when no preset mode is set')
'Preset value should be None when no preset mode is set')
if mode != PresetMode.NONE and not isinstance(value, Number):
raise TypeError(
'Preset value should be a number when a preset mode is set')
# Get hw values
# Get hardware values
ptype, pcast = {
PresetMode.NONE: (0, lambda x: 0),
PresetMode.REALTIME: (1, float),
......@@ -178,3 +177,21 @@ class Mercury(BaseMCA):
self._proxy.set_acquisition_value('preset_type', ptype)
self._proxy.set_acquisition_value('preset_value', pvalue)
self._proxy.apply_acquisition_values()
@property
def supported_trigger_modes(self):
return [TriggerMode.SOFTWARE,
TriggerMode.GATE]
def set_trigger_mode(self, mode):
# Cast arguments
if mode is None:
mode = TriggerMode.SOFTWARE
# Check arguments
if mode not in self.supported_trigger_modes:
raise ValueError('{:s} trigger mode not supported'.format(mode))
# Get hardware value
value = 0 if mode == TriggerMode.GATE else 1
# Configure
self._proxy.set_acquisition_value('gate_ignore', value)
self._proxy.apply_acquisition_values()
"""Test module for MCA base class."""
import pytest
from bliss.controllers.mca import BaseMCA, Brand, DetectorType, PresetMode
from bliss.controllers.mca import BaseMCA, Brand, DetectorType
from bliss.controllers.mca import PresetMode, TriggerMode
def test_mca_enums():
......@@ -49,7 +50,6 @@ def test_base_mca():
mca.set_acquisition_mode: ('some_mode',),
mca.set_trigger_mode: ('some_mode',),
mca.set_spectrum_range: ('some', 'range'),
mca.prepare_acquisition: (),
mca.start_acquisition: (),
mca.stop_acquisition: (),
mca.is_acquiring: (),
......@@ -86,15 +86,17 @@ def test_base_mca_logic(mocker):
def set_preset_mode(self, mode):
assert mode in (None, PresetMode.NONE)
supported_trigger_modes = [TriggerMode.SOFTWARE]
def set_trigger_mode(self, mode):
assert mode in (None, TriggerMode.SOFTWARE)
def initialize_attributes(self):
pass
def initialize_hardware(self):
pass
def prepare_acquisition(self):
pass
def start_acquisition(self):
pass
......
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