Commit 0b1f1694 authored by Matias Guijarro's avatar Matias Guijarro

mapping: properly build map from controllers

common/log.py: remove old file
parent 5b871459
......@@ -6,10 +6,12 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from warnings import warn
import logging
from .embl import ExporterClient
from bliss.common.logtools import LogMixin
from bliss.common import session
import gevent
from gevent.queue import Queue
from .embl import ExporterClient
exporter_clients = {}
......@@ -25,7 +27,7 @@ def start_exporter(address, port, timeout=3, retries=1):
return exporter_clients[(address, port)]
class Exporter(ExporterClient.ExporterClient):
class Exporter(ExporterClient.ExporterClient, LogMixin):
STATE_EVENT = "State"
STATUS_EVENT = "Status"
VALUE_EVENT = "Value"
......@@ -57,6 +59,10 @@ class Exporter(ExporterClient.ExporterClient):
self.events_queue = Queue()
self.events_processing_task = None
session.get_current().map.register(
self, parents_list=["comms"], tag=f"exporter: {address}:{port}"
)
def start(self):
pass
# self.started=True
......@@ -139,7 +145,7 @@ class Exporter(ExporterClient.ExporterClient):
try:
cb(self._to_python_value(value))
except:
logging.exception(
self._logger.exception(
"Exception while executing callback %s for event %s", cb, name
)
continue
......
......@@ -21,7 +21,6 @@ __all__ = [
import re
import enum
import logging
import gevent
from gevent import lock
import numpy
......
......@@ -15,7 +15,6 @@ from bliss.common import event
import gevent
import weakref
import types
import logging
(DOREG, DONTREG, WAITREG) = (0, 1, 2)
......
......@@ -16,7 +16,6 @@ SpecCommandA
import sys
import types
import logging
import gevent
from gevent.event import Event
from .connection import SpecConnection
......
......@@ -17,8 +17,9 @@ import gevent
import gevent.socket
import socket
import weakref
import logging
from bliss.common import event
from bliss.common import session
from bliss.common.logtools import LogMixin
from .error import SpecClientNotConnectedError
from .channel import SpecChannel
from .message import *
......@@ -118,7 +119,7 @@ def connectionHandler(conn, socket_to_spec):
try:
reply = conn.registeredReplies[replyID]
except BaseException:
logging.getLogger("SpecClient").exception(
conn._logger.exception(
"Unexpected error while receiving a message from server"
)
else:
......@@ -142,7 +143,7 @@ def connectionHandler(conn, socket_to_spec):
receivedStrings = [s[offset:]]
class SpecConnection:
class SpecConnection(LogMixin):
"""SpecConnection class
Signals:
connected() -- emitted when the required Spec version gets connected
......@@ -183,6 +184,8 @@ class SpecConnection:
self.port = None
self.scanport = True
session.get_current().map.register(self, parents_list=["comms"], tag=str(self))
def __str__(self):
return "<connection to Spec, host=%s, port=%s>" % (
self.host,
......@@ -226,7 +229,7 @@ class SpecConnection:
# we received a value, so emit an update signal
channel.update(channelValue, force=True)
except BaseException:
logging.getLogger("SpecClient").exception(
self._logger.exception(
"Uncaught exception in SpecConnection.registerChannel"
)
......@@ -260,7 +263,7 @@ class SpecConnection:
def error(self, error):
"""Emit the 'error' signal when the remote Spec version signals an error."""
logging.getLogger("SpecClient").error("Error from Spec: %s", error)
self._logger.error("Error from Spec: %s", error)
event.send(self, "error", (error,))
......@@ -273,7 +276,7 @@ class SpecConnection:
old_state = self.state
self.state = CONNECTED
if old_state != CONNECTED:
logging.getLogger("SpecClient").info(
self._logger.info(
"Connected to %s:%s",
self.host,
(self.scanport and self.scanname) or self.port,
......@@ -290,7 +293,7 @@ class SpecConnection:
old_state = self.state
self.state = DISCONNECTED
if old_state == CONNECTED:
logging.getLogger("SpecClient").info(
self._logger.info(
"Disconnected from %s:%s",
self.host,
(self.scanport and self.scanname) or self.port,
......@@ -347,7 +350,7 @@ class SpecConnection:
cmd -- command string
"""
if self.serverVersion < 3:
logging.getLogger("SpecClient").error(
self._logger.error(
"Cannot execute command in Spec : feature is available since Spec server v3 only"
)
else:
......@@ -369,7 +372,7 @@ class SpecConnection:
cmd -- command string
"""
if self.serverVersion < 3:
logging.getLogger("SpecClient").error(
self._logger.error(
"Cannot execute command in Spec : feature is available since Spec server v3 only"
)
else:
......
......@@ -5,7 +5,6 @@
# Copyright (c) 2015-2019 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from bliss.common import log as elog
from bliss.common.motor_config import StaticConfig
from bliss.common import event
import time
......
......@@ -9,12 +9,13 @@
how to use motion hooks in your system"""
import weakref
from bliss.common import session
from bliss.common.logtools import LogMixin
__all__ = ["MotionHook"]
class MotionHook(object):
class MotionHook(LogMixin):
"""
Base motion hook. Executed before a motion starts and after motion ends.
"""
......@@ -22,6 +23,10 @@ class MotionHook(object):
def __init__(self):
self.__axes = weakref.WeakValueDictionary()
session.get_current().map.register(
self, parents_list=["motion hooks"], tag=self.__class__.__name__
)
def add_axis(self, axis):
"""Add a new axis to the hook. Called by bliss when an axis is created
which is linked to this hook
......
......@@ -13,9 +13,9 @@ import math
import gevent
import gevent.event
from bliss.common import session
from bliss.common.task import task
from bliss.common import log
from bliss.common.logtools import LogMixin
from bliss.common.utils import with_custom_members
from bliss.common.measurement import SamplingCounter, counter_namespace
......@@ -37,19 +37,22 @@ class TempControllerCounter(SamplingCounter):
@with_custom_members
class Input(object):
class Input(LogMixin):
""" Implements the access to temperature sensors
"""
def __init__(self, controller, config):
""" Constructor """
log.debug("On Input")
# log.debug(" config type is: %s" % type(config))
# log.debug(" controller type is: %s" % type(controller))
self.__controller = controller
self.__name = config["name"]
self.__config = config
session.get_current().map.register(
self, parents_list=[controller, "counters"], tag=f"{self.name}"
)
# useful attribute for a temperature controller writer
self._attr_dict = {}
......@@ -80,22 +83,21 @@ class Input(object):
def read(self):
""" returns the sensor value """
log.debug("On Input:read")
self._logger.debug("On Input:read")
return self.controller.read_input(self)
def state(self):
""" returns the sensor state """
log.debug("On Input:state")
self._logger.debug("On Input:state")
return self.controller.state_input(self)
@with_custom_members
class Output(object):
class Output(LogMixin):
""" Implements the access to temperature heaters """
def __init__(self, controller, config):
""" Constructor """
log.debug("On Output")
self.__controller = controller
self.__name = config["name"]
try:
......@@ -118,6 +120,10 @@ class Output(object):
# useful attribute for a temperature controller writer
self._attr_dict = {}
session.get_current().map.register(
self, parents_list=[controller, "counters"], tag=f"{self.name}"
)
@property
def controller(self):
""" returns the temperature controller """
......@@ -158,7 +164,7 @@ class Output(object):
def read(self):
""" returns the heater value """
log.debug("On Output:read")
self._logger.debug("On Output:read")
return self.controller.read_output(self)
def ramp(self, new_setpoint=None, wait=False, **kwargs):
......@@ -173,7 +179,7 @@ class Output(object):
- setpoint_abort
- start_ramp
"""
log.debug("On Output:ramp %s" % new_setpoint)
self._logger.debug("On Output:ramp %s" % new_setpoint)
self.__mode = 1
return self._ramp(new_setpoint, wait, **kwargs)
......@@ -189,14 +195,14 @@ class Output(object):
- setpoint_abort
- set
"""
log.debug("On Output:set %s" % new_setpoint)
self._logger.debug("On Output:set %s" % new_setpoint)
self.__mode = 0
return self._ramp(new_setpoint, wait, **kwargs)
def _ramp(self, new_setpoint=None, wait=False, **kwargs):
""" starts the ramp tasks.
"""
log.debug("On Output:_ramp %s" % new_setpoint)
self._logger.debug("On Output:_ramp %s" % new_setpoint)
if new_setpoint is not None:
ll, hl = self.limits
if ll is not None and new_setpoint < ll:
......@@ -218,7 +224,7 @@ class Output(object):
def wait(self):
""" Waits on a setpoint task
"""
log.debug("On Output:wait")
self._logger.debug("On Output:wait")
try:
self.__setpoint_task.get()
except KeyboardInterrupt:
......@@ -243,7 +249,7 @@ class Output(object):
"""
deadband = self.deadband if deadband is None else deadband
log.debug("On output:_setpoint_state: %s" % (deadband))
self._logger.debug("On output:_setpoint_state: %s" % (deadband))
if deadband is None:
return "READY"
mysp = self.controller.get_setpoint(self)
......@@ -258,7 +264,7 @@ class Output(object):
""" Stops a setpoint task.
Calls the controller method setpoint_stop
"""
log.debug("On Output: stop")
self._logger.debug("On Output: stop")
if self.__setpoint_task and not self.__setpoint_task.ready():
self.__setpoint_task.kill()
self.controller.setpoint_stop(self)
......@@ -267,7 +273,7 @@ class Output(object):
""" Aborts a setpoint task.
Calls the controller method setpoint_abort
"""
log.debug("On Output: abort")
self._logger.debug("On Output: abort")
if self.__setpoint_task and not self.__setpoint_task.ready():
self.__setpoint_task.kill()
self.controller.setpoint_abort(self)
......@@ -290,7 +296,7 @@ class Output(object):
Polls until setpoint is reached
Is a gevent coroutine
"""
log.debug("On Output:_do_setpoint : mode = %s" % (self.__mode))
self._logger.debug("On Output:_do_setpoint : mode = %s" % (self.__mode))
try:
while self._setpoint_state() == "RUNNING":
gevent.sleep(self.__setpoint_event_poll)
......@@ -300,7 +306,7 @@ class Output(object):
def _start_setpoint(self, setpoint, **kwargs):
""" launches the coroutine doing the setpoint
"""
log.debug("On Output:_start_setpoint")
self._logger.debug("On Output:_start_setpoint")
sync_event = gevent.event.Event()
@task
......@@ -319,7 +325,7 @@ class Output(object):
def state(self):
""" returns the the state of a heater """
log.debug("On Output:state")
self._logger.debug("On Output:state")
return self.controller.state_output(self)
def pollramp(self, new_poll=None):
......@@ -338,7 +344,7 @@ class Output(object):
Setting/reading the setpoint ramp rate value
"""
log.debug("On Output:ramprate: %s " % (new_ramp))
self._logger.debug("On Output:ramprate: %s " % (new_ramp))
if new_ramp:
self.controller.set_ramprate(self, new_ramp)
else:
......@@ -349,7 +355,7 @@ class Output(object):
Setting/reading the setpoint step value (for step mode ramping)
"""
log.debug("On Output:step: %s " % (new_step))
self._logger.debug("On Output:step: %s " % (new_step))
if new_step:
self.controller.set_step(self, new_step)
else:
......@@ -360,7 +366,7 @@ class Output(object):
Setting/reading the setpoint dwell value (for step mode ramping)
"""
log.debug("On Output:setpoint dwell: %s " % (new_dwell))
self._logger.debug("On Output:setpoint dwell: %s " % (new_dwell))
if new_dwell:
self.controller.set_dwell(self, new_dwell)
else:
......@@ -373,12 +379,11 @@ class Output(object):
@with_custom_members
class Loop(object):
class Loop(LogMixin):
""" Implements the access to temperature regulation loop """
def __init__(self, controller, config):
""" Constructor """
log.debug("On Loop")
self.__controller = controller
self.__name = config["name"]
self.__config = config
......@@ -391,6 +396,13 @@ class Loop(object):
# useful attribute for a temperature controller writer
self._attr_dict = {}
session.get_current().map.register(
self,
parents_list=[controller],
children_list=[self.__input, self.__output],
tag=f"{self.name}",
)
@property
def controller(self):
""" returns the temperature controller """
......@@ -418,31 +430,31 @@ class Loop(object):
def set(self, new_setpoint=None, wait=False, **kwargs):
""" same as a call to the the method set on its output object """
log.debug(("On Loop: set %s") % new_setpoint)
self._logger.debug(("On Loop: set %s") % new_setpoint)
return self.__output.set(new_setpoint, wait, **kwargs)
def ramp(self, new_setpoint=None, wait=False, **kwargs):
""" same as the call to the method ramp on its output object """
log.debug(("On Loop: ramp %s") % new_setpoint)
self._logger.debug(("On Loop: ramp %s") % new_setpoint)
return self.__output.ramp(new_setpoint, wait, **kwargs)
def stop(self):
""" same as the call to the method stop on its output object """
log.debug("On Loop: stop")
self._logger.debug("On Loop: stop")
self.__output.stop()
def on(self):
""" Sets the regulation on
- call to the method 'on' of the controller
"""
log.debug("On Loop: on")
self._logger.debug("On Loop: on")
self.controller.on(self)
def off(self):
""" Sets the regulation off
- call to the method 'off' of the controller
"""
log.debug("On Loop: off")
self._logger.debug("On Loop: off")
self.controller.off(self)
def kp(self, new_kp=None):
......@@ -450,7 +462,7 @@ class Loop(object):
Setting/reading the P value (for PID)
"""
log.debug("On Loop: kp (PID): ")
self._logger.debug("On Loop: kp (PID): ")
if new_kp:
self.controller.set_kp(self, new_kp)
else:
......@@ -461,7 +473,7 @@ class Loop(object):
Setting/reading the I value (for PID)
"""
log.debug("On Loop: ki (PID): ")
self._logger.debug("On Loop: ki (PID): ")
if new_ki:
self.controller.set_ki(self, new_ki)
else:
......@@ -472,7 +484,7 @@ class Loop(object):
Setting/reading the D value (for PID)
"""
log.debug("On Loop: kd (PID): ")
self._logger.debug("On Loop: kd (PID): ")
if new_kd:
self.controller.set_kd(self, new_kd)
else:
......
......@@ -6,8 +6,6 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import logging
from bliss.common import log
from bliss.config.plugins.utils import find_class
......
......@@ -5,6 +5,7 @@
# Copyright (c) 2015-2019 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from bliss.common import session
from bliss.comm.util import UDP, get_comm_type, get_comm
from bliss.comm.tcp import SocketTimeout
from bliss.common.utils import object_method
......@@ -202,6 +203,8 @@ class Elmo(Controller):
opt = {"baudrate": 115200, "eol": ";"}
self._cnx = get_comm(config, **opt)
session.get_current().map.register(self, children_list=[self._cnx])
self._elmostate = AxisState()
for state, human in (
("SLAVESWITCH", "Slave switch activate"),
......
This diff is collapsed.
......@@ -8,7 +8,6 @@
import time
from bliss.controllers.motor import Controller
from bliss.common import log as elog
from bliss.common.axis import AxisState
from bliss.common.tango import DevState, DeviceProxy, AttributeProxy
......@@ -24,7 +23,7 @@ class ESRF_Undulator(Controller):
try:
self.ds_name = self.config.get("ds_name")
except:
elog.debug(
self._logger.debug(
"no 'ds_name' defined in config for %s" % self.config.get("name")
)
......@@ -49,7 +48,7 @@ class ESRF_Undulator(Controller):
"attr_vel_name": attr_vel_name,
"attr_acc_name": attr_acc_name,
}
elog.debug("axis initilized--------------------------")
self._logger.debug("axis initialized--------------------------")
"""
Actions to perform at controller closing.
......
......@@ -8,9 +8,9 @@
from warnings import warn
from bliss.controllers.motor import Controller
from bliss.common import log as elog
from bliss.common.axis import AxisState
from bliss.common.utils import object_method
from bliss.common import session
from bliss.comm.util import get_comm, TCP
......@@ -36,6 +36,8 @@ class FlexDC(Controller):
comm_cfg = {"tcp": {"url": host}}
self.sock = get_comm(comm_cfg, port=4000)
session.get_current().map.register(self, children_list=[self.sock])
def finalize(self):
self.sock.close()
......@@ -80,11 +82,11 @@ class FlexDC(Controller):
# Checks if closed loop parameters have been set.
_ans = self._flexdc_query("%sTT" % axis.channel)
if _ans == "0":
elog.error("Missing closed loop param TT (Target Time)!!")
self._logger.error("Missing closed loop param TT (Target Time)!!")
_ans = self._flexdc_query("%sTR" % axis.channel)
if _ans == "0":
elog.error("Missing closed loop param TR (Target Radius)!!")
self._logger.error("Missing closed loop param TR (Target Radius)!!")
# Minimum dead zone
self.flexdc_parameter(axis, "CA[36]", axis.min_dead_zone)
......@@ -104,22 +106,22 @@ class FlexDC(Controller):
loop control reference position
"""
_pos = int(self._flexdc_query("%sDP" % axis.channel))
elog.debug("FLEXDC *setpoint* position (in steps) : %d" % _pos)
self._logger.debug("FLEXDC *setpoint* position (in steps) : %d" % _pos)
return _pos
def read_encoder(self, encoder):
""" PS : Position from Sensor """
_pos = int(self._flexdc_query("%sPS" % encoder.channel))
elog.debug("FLEXDC *measured* position (in steps) : %d" % _pos)
self._logger.debug("FLEXDC *measured* position (in steps) : %d" % _pos)
return _pos
def read_velocity(self, axis):
_velocity = float(self._flexdc_query("%sSP" % axis.channel))
elog.debug("FLEXDC read velocity : %g" % _velocity)
self._logger.debug("FLEXDC read velocity : %g" % _velocity)
return _velocity
def set_velocity(self, axis, new_velocity):
elog.debug("FLEXDC write velocity (new_velocity=%g)" % new_velocity)
self._logger.debug("FLEXDC write velocity (new_velocity=%g)" % new_velocity)
self._flexdc_query("%sSP=%d" % (axis.channel, new_velocity))
return self.read_velocity(axis)
......@@ -141,21 +143,21 @@ class FlexDC(Controller):
else:
_ret = AxisState("READY")
elog.debug("state : %s" % _ret)
self._logger.debug("state : %s" % _ret)
return _ret
def prepare_move(self, motion):
elog.debug("prepare_move, motion.target_pos=%g" % motion.target_pos)
self._logger.debug("prepare_move, motion.target_pos=%g" % motion.target_pos)
# Prepare axis movement.
self._flexdc_query("%sAP=%d" % (motion.axis.channel, int(motion.target_pos)))
def start_one(self, motion):
elog.debug("start_one, motion.target_pos=%g" % motion.target_pos)
self._logger.debug("start_one, motion.target_pos=%g" % motion.target_pos)
# Start prepared movement.
self._flexdc_query("%sBG" % motion.axis.channel)
def stop(self, axis):
elog.debug("FLEXDC stop")
self._logger.debug("FLEXDC stop")
self._flexdc_query("%sST" % axis.channel)
def home_search(self, axis, switch):
......@@ -179,7 +181,7 @@ class FlexDC(Controller):
def raw_write_read(self, cmd):
_cmd = "%s%s" % (self.ctrl_axis.channel, cmd)
elog.debug("raw_write_read : _cmd=%s" % _cmd)
self._logger.debug("raw_write_read : _cmd=%s" % _cmd)
return self._flexdc_query(_cmd)
def read_acceleration(self, axis):
......@@ -187,7 +189,7 @@ class FlexDC(Controller):
returns acceleration read from flexdc controller in steps/s2
"""
_acc_spss = float(self._flexdc_query("%sAC" % axis.channel))
elog.debug("read Acceleration : _acc_spss=%g " % _acc_spss)
self._logger.debug("read Acceleration : _acc_spss=%g " % _acc_spss)
return _acc_spss
def set_acceleration(self, axis, new_acc):
......@@ -197,14 +199,14 @@ class FlexDC(Controller):
Flexdc works in steps/s2
"""
self._flexdc_query("%sAC=%d" % (axis.channel, new_acc))
elog.debug("write Acceleration : new_acc=%g" % new_acc)
self._logger.debug("write Acceleration : new_acc=%g" % new_acc)
return axis.settings.get("acceleration")
def _flexdc_query(self, cmd):
# Adds "\r" at end of command.
# TODO : test if already present ?
elog.debug("SENDING : %s" % cmd)
self._logger.debug("SENDING : %s" % cmd)
_cmd = cmd + "\r"
# Adds ACK character:
......
......@@ -5,7 +5,7 @@ Bliss controller for ethernet Galil DC controller.
from warnings import warn
from bliss.controllers.motor import Controller
from bliss.common import log as elog
from bliss.common import session
from bliss.common.axis import AxisState
from bliss.comm.util import get_comm, TCP
......@@ -41,6 +41,7 @@ class GalilDMC213(Controller):
warn("'host' keyword is deprecated. Use 'tcp' instead", DeprecationWarning)
comm_cfg = {"tcp": {"url": host}}
self.sock = get_comm(comm_cfg, port=23)
session.get_current().map.register(self, children_list=[self.sock])
def initialize_hardware(self):
# perform hw reset
......
......@@ -9,8 +9,6 @@
General purpose motion hooks.
"""
import logging
from gevent import sleep
from bliss.common.hook import MotionHook
......@@ -36,8 +34,6 @@ class SleepHook(MotionHook):
"""
def __init__(self, name, config):
self._log = logging.getLogger("{0}({1})".format(self.__class__.__name__, name))
self.debug = self._log.debug
self.config = config
self.name = name
super(SleepHook, self).__init__()
......@@ -45,9 +41,9 @@ class SleepHook(MotionHook):
def wait(self, phase):
t = float(self.config.get("{0}_wait".format(phase)))
if t:
self.debug("start %s wait (%ss)...", phase, t)
self._logger.debug("start %s wait (%ss)...", phase, t)
sleep(t)
self.debug("finished %s wait (%ss)", phase, t)
self._logger.debug("finished %s wait (%ss)", phase, t)
def pre_move(self, motion_list):
self.wait("pre_move")
......@@ -78,8 +74,6 @@ class WagoHook(MotionHook):
"""
def __init__(self, name, config):
self._log = logging.getLogger("{0}({1})".format(self.__class__.__name__, name))
self.debug = self._log.debug
self.config = config
self.name = name
self.wago = config["wago"]
......@@ -100,13 +94,13 @@ class WagoHook(MotionHook):
def set(self, phase):
value = self.config[phase]["value"]
wait = self.config[phase].get("wait", 0)
self.debug("start setting %s value to %s...", phase, value)
self._logger.debug("start setting %s value to %s...", phase, value)
self.wago.set(self.channel, value)