Commit 7bf41260 authored by Vincent Michel's avatar Vincent Michel
Browse files

Add acquisition number support in the mercury controller

parent e64cca92
......@@ -17,10 +17,6 @@ DetectorType = enum.Enum(
'FALCONX1 FALCONX4 FALCONX8 XMAP MERCURY MERCURY4 MICRO_DXP DXP_2X '
'MAYA2000 MUSST_MCA MCA8000D DSA1000 MULTIMAX')
AcquisitionMode = enum.Enum(
'AcquisitionMode',
'SINGLE MULTIPLE')
TriggerMode = enum.Enum(
'TriggerMode',
'SOFTWARE EXTERNAL GATE')
......@@ -85,13 +81,6 @@ class BaseMCA(object):
def set_preset_mode(self, mode, *args):
raise NotImplementedError
@property
def supported_acquisition_modes(self):
raise NotImplementedError
def set_acquisition_mode(self, mode):
raise NotImplementedError
@property
def supported_trigger_modes(self):
raise NotImplementedError
......@@ -108,6 +97,19 @@ class BaseMCA(object):
def set_spectrum_range(self, first, last):
raise NotImplementedError
# Acquisition number
@property
def acquisition_number(self):
raise NotImplementedError
def set_acquisition_number(self, value):
raise NotImplementedError
@property
def multiple_acquisition(self):
return self.acquisition_number > 1
# Acquisition
def start_acquisition(self):
......@@ -128,6 +130,8 @@ class BaseMCA(object):
# Extra logic
def run_single_acquisition(self, acquisition_time=1., polling_time=0.1):
# Acquisition number
self.set_acquisition_number(1)
# Trigger mode
self.set_trigger_mode(None)
# Preset mode
......@@ -148,6 +152,8 @@ class BaseMCA(object):
return self.get_acquisition_data(), self.get_acquisition_statistics()
def run_external_acquisition(self, acquistion_time=None, polling_time=0.1):
# Acquisition number
self.set_acquisition_number(1)
# Trigger mode
mode = TriggerMode.EXTERNAL if acquistion_time else TriggerMode.GATE
if mode not in self.supported_trigger_modes:
......@@ -160,11 +166,11 @@ class BaseMCA(object):
self.set_preset_mode(None)
# Start and wait
self.start_acquisition()
previous = current = 0.
get_realtime = lambda: self.get_acquisition_statistics()[0].realtime
previous, current = 0., get_realtime()
while current == 0. or previous != current:
time.sleep(polling_time)
previous = current
current = self.get_acquisition_statistics()[0].realtime
previous, current = current, get_realtime()
# Stop and return data
self.stop_acquisition()
return self.get_acquisition_data(), self.get_acquisition_statistics()
......@@ -107,9 +107,38 @@ class Mercury(BaseMCA):
grouped_channels = self._proxy.get_grouped_channels()
assert grouped_channels == ((0, ), )
# Acquisition number
@property
def acquisition_number(self):
mapping = int(self._proxy.get_acquisition_value('mapping_mode', 0))
if mapping == 0:
return 1
# Should be:
# self._proxy.get_acquisition_value('num_map_pixels', 0)
raise NotImplementedError
def set_acquisition_number(self, value):
# Invalid argument
if value < 1:
raise ValueError('Acquisition number should be strictly positive')
# Single mode
if value == 1:
self._proxy.set_acquisition_value('mapping_mode', 0)
self._proxy.apply_acquisition_values()
return
# Multiple mode
# Should be:
# self._proxy.set_acquisition_value('mapping_mode', 1)
# self._proxy.set_acquisition_value('num_map_pixels, value)
# self._proxy.apply_acquisition_values()
raise NotImplementedError
# Acquisition
def start_acquisition(self):
# Make sure the acquisition is stopped first
self._proxy.stop_run()
self._proxy.start_run()
def stop_acquisition(self):
......@@ -158,7 +187,7 @@ class Mercury(BaseMCA):
mode = PresetMode.NONE
# Check arguments
if mode not in self.supported_preset_modes:
raise ValueError('{:s} preset mode not supported'.format(mode))
raise ValueError('{!s} preset mode not supported'.format(mode))
if mode == PresetMode.NONE and value is not None:
raise TypeError(
'Preset value should be None when no preset mode is set')
......@@ -189,7 +218,7 @@ class Mercury(BaseMCA):
mode = TriggerMode.SOFTWARE
# Check arguments
if mode not in self.supported_trigger_modes:
raise ValueError('{:s} trigger mode not supported'.format(mode))
raise ValueError('{!s} trigger mode not supported'.format(mode))
# Get hardware value
value = 0 if mode == TriggerMode.GATE else 1
# Configure
......
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