Commit 124293cf authored by Antonia Beteva's avatar Antonia Beteva

Merge branch 'transfocator_simulator' into 'master'

transfocator: new simulator that allows all commands, added more tests, updated docs

See merge request !1998
parents 9c70aec2 3200e0ef
Pipeline #21127 failed with stages
in 5 minutes and 6 seconds
......@@ -68,7 +68,7 @@ Usage::
>>> # shortcut to put multiple at same place
>>> t1[1:6] = 1 # put everything IN
"""
import random
import gevent
import tabulate
from bliss.common.utils import grouped
......@@ -228,10 +228,6 @@ class Transfocator:
def close(self):
self.wago.close()
try:
self.__mockup.close()
except AttributeError:
pass
def __close__(self):
self.close()
......@@ -454,3 +450,24 @@ class Transfocator:
"<bliss.controllers.transfocator.Transfocator "
"instance at {:x}>".format(id(self))
)
class TransfocatorMockup(Transfocator):
def __init__(self, name, config_tree):
"""This will emulate a transfocator"""
temp_transf = Transfocator(name, config_tree)
lens = temp_transf.nb_lens
pinhole = temp_transf.nb_pinhole
self.__mockup_state = random.randint(0, 2 ** (lens + pinhole))
super().__init__(name, config_tree)
def connect(self):
pass
def tfstatus_set(self, value):
self.__mockup_state = value
def pos_read(self):
return self.__mockup_state
......@@ -53,3 +53,7 @@ within the transfocator, with incident beam coming from **left to right**.
- any other value means the opposite, that the first transfocator state switch is wired last
* `cmd_mode`: 0 (default) means **first transfocator lens action switch is wired first in Wago**
- any other value means the opposite, that the first transfocator action switch is wired last
### Transfocator Simulator
We can simulate any Transfocator simply changing the yml parameter `class: Transfocator` with `class: TransfocatorMockup`.
......@@ -14,3 +14,27 @@ def test_transfocator(default_session):
# only reading is possible due to simulator limitations
transfocator.status_read()
transfocator.status_dict()
def test_transfocator_inout(default_session):
transfocator = default_session.config.get("transfocator_simulator")
transfocator[:] = 0
assert transfocator.pos_read() == 0
assert (
transfocator.__info__()
== "Transfocator transfocator_simulator:\nP0 L1 L2 L3 L4 L5 L6 L7 L8\nOUT OUT OUT OUT OUT OUT OUT OUT OUT"
)
transfocator[:] = 1
assert transfocator.pos_read() == 0b111111111
assert (
transfocator.__info__()
== "Transfocator transfocator_simulator:\nP0 L1 L2 L3 L4 L5 L6 L7 L8\nIN IN IN IN IN IN IN IN IN"
)
transfocator.set_all(False)
assert transfocator.pos_read() == 0
transfocator.set_all()
assert transfocator.pos_read() == 0b111111111
transfocator.set_pin(False)
assert transfocator.pos_read() == 0b111111110
......@@ -61,6 +61,7 @@
- test
- test_mg
- thermo_sample
- transfocator_simulator
synoptic:
svg-file: ./test_synoptic.svg
elements:
......
plugin: bliss
class: Transfocator
module: transfocator
class: TransfocatorMockup
name: transfocator_simulator
lenses: 8 # (1)
pinhole: 1 # (2)
......@@ -7,4 +8,4 @@
controller_ip: localhost # (4)
read_mode: 0 # (5)
cmd_mode: 0 # (6)
wago: $transfocator_wago_simulator
wago: $transfocator_wago_simulator # not really used
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