Commit 2142dd37 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

motors: switch and shutter can be exported by motors controller.

Modify all motors controller to be compatible with the creator signature.
parent 66a8fc23
......@@ -9,6 +9,7 @@ from __future__ import absolute_import
import os
import sys
import pkgutil
import weakref
from bliss.common.axis import Axis, AxisRef
from bliss.common.encoder import Encoder
......@@ -335,6 +336,10 @@ def create_objects_from_config_node(config, node):
axes_names = list()
encoders = list()
encoders_names = list()
switches = list()
switches_names = list()
shutters = list()
shutters_names = list()
for axis_config in node.get('axes'):
axis_name = axis_config.get("name")
if axis_name.startswith("$"):
......@@ -348,37 +353,60 @@ def create_objects_from_config_node(config, node):
axis_class = getattr(controller_module, axis_class_name)
axes_names.append(axis_name)
axes.append((axis_name, axis_class, axis_config))
for encoder_config in node.get('encoders', []):
encoder_name = encoder_config.get("name")
encoder_class_name = encoder_config.get("class")
if encoder_class_name is None:
encoder_class = Encoder
else:
encoder_class = getattr(controller_module, encoder_class_name)
encoders_names.append(encoder_name)
encoders.append((encoder_name, encoder_class, encoder_config))
for objects,objects_names,default_class,default_class_name,objects_config in\
((encoders,encoders_names,Encoder,'',node.get('encoders',[])),
(shutters,shutters_names,None,'Shutter',node.get('shutters',[])),
(switches,switches_names,None,'Switch',node.get('switches',[])),
):
for object_config in objects_config:
object_name = object_config.get("name")
object_class_name = object_config.get("class")
object_config = _checkref(config,object_config)
if object_class_name is None:
object_class = default_class
if object_class is None:
try:
object_class = getattr(controller_module, default_class_name)
except AttributeError:
pass
else:
object_class = getattr(controller_module, object_class_name)
objects_names.append(object_name)
objects.append((object_name, object_class, object_config))
controller = controller_class(controller_name, node, axes, encoders)
controller = controller_class(controller_name, node, axes,
encoders, shutters, switches)
controller._update_refs(config)
controller.initialize()
all_names = axes_names + encoders_names
all_names = axes_names + encoders_names + switches_names + shutters_names
cache_dict = dict(zip(all_names, [controller]*len(all_names)))
if obj_name in axes_names:
cache_dict.pop(obj_name)
return { controller_name: controller, obj_name: controller.get_axis(obj_name) }, cache_dict
elif obj_name in encoders_names:
cache_dict.pop(obj_name)
return {controller_name: controller, obj_name: controller.get_encoder(obj_name) }, cache_dict
ctrl = cache_dict.pop(obj_name,None)
if ctrl is not None:
obj = create_object_from_cache(None, obj_name, controller)
return { controller_name: controller, obj_name: obj }, cache_dict
else:
return {controller_name: controller }, cache_dict
return {controller_name: controller }, cache_dict
def create_object_from_cache(config, name, controller):
try:
o = controller.get_axis(name)
except KeyError:
o = controller.get_encoder(name)
return o
for func in (controller.get_axis,
controller.get_encoder,
controller.get_switch,
controller.get_shutter):
try:
return func(name)
except KeyError:
pass
raise KeyError(name)
def _checkref(config,cfg):
obj_cfg = cfg.deep_copy()
for key,value in obj_cfg.iteritems():
if isinstance(value,str) and value.startswith('$'):
# convert reference to item from config
obj = weakref.proxy(config.get(value))
obj_cfg[key] = obj
return obj_cfg
......@@ -30,7 +30,7 @@ class Controller(object):
:ref:`bliss-how-to-motor-controller`
'''
def __init__(self, name, config, axes, encoders):
def __init__(self, name, config, axes, encoders, shutters, switches):
self.__name = name
self.__config = StaticConfig(config)
self.__initialized_axis = dict()
......@@ -39,6 +39,8 @@ class Controller(object):
self.__initialized_hw_axis = dict()
self._axes = dict()
self._encoders = dict()
self._shutters = dict()
self._switches = dict()
self.__initialized_encoder = dict()
self._tagged = dict()
......@@ -69,6 +71,12 @@ class Controller(object):
encoder_name = axis_config.get("encoder")
ENCODER_AXIS[encoder_name] = axis_name
for obj_config_list,object_dict in ((shutters,self._shutters),
(switches,self._switches)):
for obj_name, obj_class, obj_config in obj_config_list:
if obj_class is None:
raise ValueError("You have to specify a **class** for object named: %s" % obj_name)
object_dict[obj_name] = obj_class(obj_name, self, obj_config)
@property
def axes(self):
return self._axes
......@@ -77,6 +85,20 @@ class Controller(object):
def encoders(self):
return self._encoders
@property
def shutters(self):
return self._shutters
def get_shutter(self, name):
return self._shutters[name]
@property
def switchs(self):
return self._switches
def get_switch(self, name):
return self._switches[name]
@property
def name(self):
return self.__name
......
......@@ -29,8 +29,8 @@ ENABLED = 1
class GalilDMC213(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.socket_lock = lock.Semaphore()
def initialize(self):
......
......@@ -35,9 +35,9 @@ class IcePAP(Controller):
default_group = None
default_groupenc = None
def __init__(self, name, config, axes, encoders):
def __init__(self, *args, **kwargs):
"""Contructor"""
Controller.__init__(self, name, config, axes, encoders)
Controller.__init__(self, *args, **kwargs)
self.libdevice = None
......
......@@ -32,9 +32,9 @@ class IcePAPTraj(Controller):
"""Implement IcePAP stepper motor controller access"""
default_group = None
def __init__(self, name, config, axes, encoders):
def __init__(self, *args, **kwargs):
"""Contructor"""
Controller.__init__(self, name, config, axes, encoders)
Controller.__init__(self, *args, **kwargs)
# Records the list of axes
self.axes_names = []
......
......@@ -11,8 +11,8 @@ import gevent
class MD2(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
host, port = self.config.get("exporter_address").split(":")
self._exporter = Exporter(host, int(port))
......
......@@ -9,8 +9,8 @@ import itertools
class NF8742(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.host = self.config.get("host")
......
......@@ -16,8 +16,8 @@ DELAY = 0.02 # delay between 2 commands
class NF8753(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.__current_selected_channel = None
self.lock = gevent.lock.RLock()
......
......@@ -24,14 +24,11 @@ Cyril Guilloud ESRF BLISS 2016
class PI_C663(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.cname = "C663"
def __del__(self):
print "PI_C663 DESTRUCTORRRRRR******+++++++++++++++++++++++++++++++++"
# Init of controller.
def initialize(self):
"""
......
......@@ -27,8 +27,8 @@ Thu 13 Feb 2014 15:51:41
class PI_E51X(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.__encoder_axis_map = {}
for name, axis, config in axes:
......
......@@ -43,8 +43,8 @@ config example:
class PI_E712(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.sock = None
self.cname = "E712"
......
......@@ -26,8 +26,8 @@ Cyril Guilloud ESRF BLISS 2014-2016
class PI_E753(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.cname = "E753"
......
......@@ -24,14 +24,11 @@ Cyril Guilloud ESRF BLISS 2016
class PI_E871(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.cname = "E871"
def __del__(self):
print "PI_E871 DESTRUCTORRRRRR******+++++++++++++++++++++++++++++++++"
# Init of controller.
def initialize(self):
"""
......
......@@ -28,8 +28,8 @@ Bliss controller for McLennan PM600/PM1000 motor controller.
"""
class PM600(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
log.level(10)
......
......@@ -57,8 +57,8 @@ class PMD206(Controller):
- Thu 10 Apr 2014 09:18:51
"""
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self._controller_error_codes = [
(0x8000, "Abnormal reset detected."),
......
......@@ -61,12 +61,12 @@ class PiezoSize():
class PiezoJack(Controller):
def __init__(self, name, config, axes, encoders):
def __init__(self, *args, **kwargs):
"""
:type self: ???
"""
Controller.__init__(self, name, config, axes, encoders)
Controller.__init__(self, *args, **kwargs)
# *Analog* limits of linear use of capacitive sensor.
self.TADmin = self.config.get("TADmin", int, default=150000)
......
......@@ -47,9 +47,9 @@ class TacoMaxe(Controller):
- Dsc2p server to ETEL Dsc2p controller
"""
def __init__(self, name, config, axes, encoders):
def __init__(self, *args, **kwargs):
"""Contructor"""
Controller.__init__(self, name, config, axes, encoders)
Controller.__init__(self, *args, **kwargs)
def initialize(self):
......
......@@ -25,8 +25,8 @@ computer.
class TangoEMot(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
# Gets DS name from xml config.
self.ds_name = self.config.get("ds_name")
......
......@@ -50,15 +50,15 @@ config_xml = '''
class Undulator(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self.axis_info = dict()
try:
self.ds_name = self.config.get("ds_name")
except:
elog.debug("no 'ds_name' defined in config for %s" % name)
elog.debug("no 'ds_name' defined in config for %s" % self.config.get('name'))
"""
Controller initialization actions.
......
......@@ -28,8 +28,8 @@ Mon 17 Nov 2014 16:53:47
class VSCANNER(Controller):
def __init__(self, name, config, axes, encoders):
Controller.__init__(self, name, config, axes, encoders)
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
self._status = "uninitialized"
def initialize(self):
......
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