Commit 65525325 authored by Benoit Formet's avatar Benoit Formet

TrigCounter: update to bliss 1.1.0

parent 4f3aa7d5
Pipeline #20459 canceled with stage
......@@ -9,34 +9,39 @@
YAML_ configuration example:
.. code-block:: yaml
- class: TrigCounter
- class: TrigCounterController
package: pel.TrigCounter
name: interf
high_time: 0.3
period: 0.6
nb_pulses: 10
trigger_device:
type: opiom
name: $OPIOM_NAME
counter_number: 1 # CNT 1
"""
import gevent
import numpy
from bliss.common.measurement import BaseCounter, IntegratingCounter
from bliss.common.counter import IntegratingCounter
from bliss.controllers.counter import IntegratingCounterController
from bliss.scanning.acquisition.counter import IntegratingCounterAcquisitionSlave
from bliss.config.settings import HashSetting
from bliss.scanning.chain import AcquisitionMaster
from bliss.common.measurement import counter_namespace
from bliss.scanning.chain import AcquisitionChain, AcquisitionChannel
class TrigCounter(IntegratingCounter):
def __init__(self, name, config):
class TrigCounterController(IntegratingCounterController):
"""Trigger with OPIOM card for measurements with PEL"""
IntegratingCounter.__init__(self, name, None, self)
def __init__(self, name, config):
super().__init__(name)
self.config = config
trig_config = config["trigger_device"]
self._opiom_card = trig_config.get("name")
self._opiom_counter = trig_config.get("counter_number", 1) # default 1
high_time = trig_config.get("high_time", 1)
period = trig_config.get("period", 1)
nb_pulses = trig_config.get("nb_pulses", 1)
high_time = config.get("high_time", 1)
period = config.get("period", 1)
nb_pulses = config.get("nb_pulses", 1)
self.__trigger_clock = config.get("_clock", 2000000)
......@@ -49,6 +54,13 @@ class TrigCounter(IntegratingCounter):
},
)
counter_name = f"out{self._opiom_counter}"
self.create_counter(IntegratingCounter, counter_name)
def __info__(self):
params = " ".join(["%s=%s" % (k, v) for k, v in self._counter_config.items()])
return "%s %s: %s" % (self.__class__.__name__, self.name, params)
@property
def clock(self):
return self.__trigger_clock
......@@ -87,29 +99,14 @@ class TrigCounter(IntegratingCounter):
self._counter_config["nb_pulses"] = value
def get_values(self, from_index, *counters):
return [self.nb_pulses]
return [[self.nb_pulses]]
def create_master_device(self, scan_pars, **settings):
npoints = scan_pars.get("npoints", 1)
count_time = scan_pars.get("count_time", 1)
def get_acquisition_object(self, acq_params, ctrl_params, parent_acq_params):
return TrigCounterAcquisitionSlave(self, ctrl_params=ctrl_params, **acq_params)
return _TrigCounterAcqMaster(
self, self.name, npoints=npoints, count_time=count_time
)
def __info__(self):
params = " ".join(["%s=%s" % (k, v) for k, v in self._counter_config.items()])
return "TrigCounter %s: %s" % (self.name, params)
class _TrigCounterAcqMaster(AcquisitionMaster):
def __init__(self, device, name, npoints=None, count_time=None):
AcquisitionMaster.__init__(
self, device, name=name, npoints=npoints, prepare_once=True, start_once=True
)
self._count_time = count_time
def prepare(self):
class TrigCounterAcquisitionSlave(IntegratingCounterAcquisitionSlave):
def prepare_device(self):
opiom = self.device._opiom_card
counter = self.device._opiom_counter
high_time = self.device.high_time * self.device.clock
......@@ -120,33 +117,30 @@ class _TrigCounterAcqMaster(AcquisitionMaster):
"CNT %d CLK2 PULSE %d %d %d" % (counter, high_time, low_time, nb_pulses)
)
def add_counter(self, counter):
self.counter = counter
self.channels.append(AcquisitionChannel(self.counter.name, numpy.float, ()))
# def add_counter(self, counter):
# self.counter = counter
# self.channels.append(AcquisitionChannel(self.counter.name, numpy.float, ()))
def start(self):
def start_device(self):
if not self.parent:
self.trigger()
def stop(self):
def stop_device(self):
opiom = self.device._opiom_card
counter = self.device._opiom_counter
opiom.comm("#CNT %d STOP" % counter)
def trigger(self):
self.trigger_slaves()
# self.trigger_slaves()
opiom = self.device._opiom_card
counter = self.device._opiom_counter
opiom.comm("CNT %d START" % counter)
values = {self.counter.name: self.counter.get_values(0)}
self.channels.update(values)
# values = {self.device.counters[0].name: self.device.get_values(0)}
# self.channels.update(values)
def wait_ready(self):
opiom = self.device._opiom_card
counter = self.device._opiom_counter
comm = "?SCNT %d" % counter
while True:
running = opiom.comm(comm) == "RUN"
if not running:
break
while opiom.comm(comm) == "RUN":
gevent.idle()
Markdown is supported
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