Commit aa2d63ba authored by Matias Guijarro's avatar Matias Guijarro

fix issue #1024: enable the use of encoders as counters in scans

parent 125a3c74
Pipeline #19716 failed with stages
in 144 minutes and 16 seconds
......@@ -6,6 +6,8 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from bliss.common.motor_config import StaticConfig
from bliss.common.counter import SamplingCounter
from bliss.controllers import counter
from bliss.common import event
from functools import wraps
import time
......@@ -14,7 +16,7 @@ import re
import types
class Encoder(object):
class Encoder:
def lazy_init(func):
def func_wrapper(self, *args, **kwargs):
......@@ -26,6 +28,14 @@ class Encoder(object):
def __init__(self, name, controller, config):
self.__name = name
self.__controller = controller
self.__counter_controller = counter.SamplingCounterController(f"encoder:{name}")
# note: read_all is not implemented, multiple encoders from the same controller will not be read in one go = types.MethodType(
lambda this, cnt:, self.__counter_controller
SamplingCounter, "position", unit=config.get("unit")
self.__config = StaticConfig(config)
......@@ -36,6 +46,19 @@ class Encoder(object):
def controller(self):
return self.__controller
def counters(self):
"""CounterContainer protocol"""
return self.__counter_controller.counters
def counter(self):
"""Convenience access to the counter object
Useful to set conversion function for example
return self.__counter_controller.counters[0]
def config(self):
return self.__config
......@@ -6,7 +6,8 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import pytest
import time
import numpy
from bliss.common import scans
def test_get_encoder(m0, m1enc, m1):
......@@ -55,3 +56,12 @@ def test_maxee(m1):
def test_move(m1):
assert m1.position == pytest.approx(
def test_encoder_counter(default_session, m1, m1enc):
s = scans.loopscan(3, 0.1, m1enc)
assert numpy.array_equal(s.get_data()["encoder:m1enc:position"], [] * 3)
m1enc.counter.conversion_function = lambda x: x * 2
ct = scans.ct(0.1, m1enc)
assert ct.get_data()["encoder:m1enc:position"] == * 2
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