コード例 #1
0
ファイル: axis_ds.py プロジェクト: tiagocoutinho/bliss
def initialize_logging(argv):
    try:
        log_param = [param for param in argv if "-v" in param]
        if log_param:
            log_param = log_param[0]
            # print "-vN log flag found   len=%d" % len(log_param)
            if len(log_param) > 2:
                tango_log_level = int(log_param[2:])
            elif len(log_param) > 1:
                tango_log_level = 4
            else:
                print "BlissAxisManager.py - ERROR LOG LEVEL"

            if tango_log_level == 1:
                elog.level(40)
            elif tango_log_level == 2:
                elog.level(30)
            elif tango_log_level == 3:
                elog.level(20)
            else:
                elog.level(10)
        else:
            # by default : show INFO
            elog.level(20)
            tango_log_level = 0
    except tango.DevFailed:
        print traceback.format_exc()
        elog.exception("Error in initializing logging")
        sys.exit(0)
コード例 #2
0
ファイル: PM600.py プロジェクト: mguijarr/bliss
    def __init__(self, name, config, axes, encoders):
        Controller.__init__(self, name, config, axes, encoders)

        # Get the host and port from xml configuration
        self.host = self.config.get("host")
        self.port = self.config.get("port")
        log.level(10)
コード例 #3
0
def initialize_logging(argv):
    try:
        log_param = [param for param in argv if "-v" in param]
        if log_param:
            log_param = log_param[0]
            # print "-vN log flag found   len=%d" % len(log_param)
            if len(log_param) > 2:
                tango_log_level = int(log_param[2:])
            elif len(log_param) > 1:
                tango_log_level = 4
            else:
                print "BlissAxisManager.py - ERROR LOG LEVEL"

            if tango_log_level == 1:
                elog.level(40)
            elif tango_log_level == 2:
                elog.level(30)
            elif tango_log_level == 3:
                elog.level(20)
            else:
                elog.level(10)
        else:
            # by default : show INFO
            elog.level(20)
            tango_log_level = 0
    except tango.DevFailed:
        print traceback.format_exc()
        elog.exception("Error in initializing logging")
        sys.exit(0)
コード例 #4
0
ファイル: IcePAPTraj.py プロジェクト: mguijarr/bliss
    def log_level(self, lvl):
        """Changes IcePAP and eMotion libraries verbose level"""

        # Change in the eMotion library
        log.level(lvl)

        # Value mapping between the two libraries
        #        eMotion == IcePAP
        #   NOTSET ==  0 == 0 == DBG_NONE
        #   DEBUG  == 10 == 4 == DBG_DATA
        #   INFO   == 20 == 2 == DBG_TRACE
        #   WARNING== 30 ==
        #   ERROR  == 40 == 1 == DBG_ERROR
        #   CRITIC == 50 ==
        #
        val = {
            log.NOTSET: 0,
            log.DEBUG: 4,
            log.INFO: 2,
            log.ERROR: 1,
        }[lvl]

        # Change in the IcePAP library
        self.libdevice.set_verbose(val)

        # Always return the current eMotion level
        self.log_info("log_level(%s) called, lib(%d)" %
                      (log.getLevelName(lvl), val))
        return log.level()
コード例 #5
0
ファイル: test_logging.py プロジェクト: tiagocoutinho/bliss
 def test_info(self):
     log.level(log.INFO)
     with wrapped_stdout() as stdout:
         log.info("test")
     output = stdout.getvalue()
     self.assertEquals(
         output,
         "INFO: test\n")
コード例 #6
0
ファイル: test_logging.py プロジェクト: tiagocoutinho/bliss
 def test_debug(self):
     log.level(log.DEBUG)
     with wrapped_stdout() as stdout:
         log.debug("debugging test")
     output = stdout.getvalue()
     # Must suppress 13 firsts chars.
     self.assertTrue(output.endswith(
         "test_debug() (misc/test_logging.py, l.56): debugging test\n"))
コード例 #7
0
ファイル: TestLogging.py プロジェクト: mguijarr/bliss
 def test_debug(self):
     log.level(log.DEBUG)
     with wrapped_stdout() as stdout:
         log.debug("debugging test")
     output = stdout.getvalue()
     self.assertEquals(
         output,
         "DEBUG: test_debug ('TestLogging.py`, line 49): debugging test\n")
コード例 #8
0
 def test_debug(self):
     log.level(log.DEBUG)
     with wrapped_stdout() as stdout:
         log.debug("debugging test")
     output = stdout.getvalue()
     # Must suppress 13 firsts chars.
     self.assertTrue(
         output.endswith(
             "test_debug() (misc/test_logging.py, l.56): debugging test\n"))
コード例 #9
0
ファイル: PiezoJack.py プロジェクト: mguijarr/bliss
    def __init__(self, name, config, axes, encoders):
        """

        :type self: ???
        """
        Controller.__init__(self, name, config, axes, encoders)

        # *Analog* limits of linear use of capacitive sensor.
        self.TADmin = self.config.get("TADmin", int, default=150000)
        self.TADmax = self.config.get("TADmax", int, default=700000)

        self.factor = 1  # conversion factor from TNS to microns.

        self._move_task = None

        # set the length of the given piezo,
        # the other needed attributes being calculated in class PiezoSize
        length = self.config.get("PiezoLength", float, 15)  # microns
        band = self.config.get("PiezoBand", float, 4)       # microns
        self._PiezoSize = PiezoSize(length, band)
        self._piezo_settle_sleep = 1  # seconds

        self._icepap_retries = 8

        # Capacitive Sensor's TNS to microns.
        # Measured by Leo Rousset in linear system.
        # 1 TNS = 1.75887 microns
        self.CS_tns2microns = 1.75887

        # leverage arm
        self.system_factor = 82.0/28.0   # ~2.93 (theorical value)
        self.system_factor = 2.8         # measured (cos taken into account in measurement...)

        # TNS to bender movement conversion factor
        self.bender_factor = self.CS_tns2microns * self.system_factor  # 4.925

        # Default factor for TNS to microns conversion   # 4.74
        # This value has shown to be different for the two sides of the mirror
        # we used for testing. It needs to be configurable.
        self.bender_factor = self.config.get("factor", float, default=self.bender_factor)

        # This value will decide in which distance from the calculated target_tns the icepap position
        # needs to be, before it is acceptable to go on to regulate the position with the piezo.
        self.tns_allowed_divergence = self.config.get("tns_allowed_divergence", float, default=0.5)

        # the controllers name. The axes will have names given by the configuration.
        self.cname = "PiezoJack"
        # one has to start somewhere. Be ready for the start.
        self._hw_status = AxisState("READY")

        # Attempt to open a logger for the controller
        self.log = alog.getLogger('Contr '+self.cname)
        # set axis logging to the same level as elog.level
        self.log.setLevel(elog.level())
        self.log.info(
            "{0:s}logging for controller {1:s}: level {2:s}{3:s}".format(bcolors.RED + bcolors.BOLD, self.cname,
                                                                         elog.getLevelName(elog.level()), bcolors.ENDC))
        self.piezo = None
        self.icepap = None
コード例 #10
0
ファイル: test_logging.py プロジェクト: tiagocoutinho/bliss
 def test_error(self):
     log.level(log.ERROR)
     with wrapped_stderr():
         self.assertRaises(RuntimeError, log.error, "an error to log")
コード例 #11
0
ファイル: NewportXPS.py プロジェクト: tiagocoutinho/bliss
 def __init__(self, *args, **kwargs):
     Controller.__init__(self, *args, **kwargs)
     elog.level(10)
コード例 #12
0
    def __init__(self, *args, **kwargs):
        Controller.__init__(self, *args, **kwargs)

        log.level(10)
コード例 #13
0
 def test_level(self):
     self.assertEquals(log.level(log.INFO), log.INFO)
コード例 #14
0
ファイル: vscanner_demo.py プロジェクト: mguijarr/bliss
# Simple python program driving VSCANNER through EMotion.
import os
import sys
import time

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

import bliss
import bliss.common.log as elog

elog.level(10)

xml_config = """
<config>
  <controller class="VSCANNER">
    <serial_line value = "/dev/ttyS0" />
    <axis name="px">
      <chan_letter value="X"/>
      <velocity value="0" />
      <steps_per_unit value="1" />
   </axis>
  </controller>
</config>
"""

bliss.load_cfg_fromstring(xml_config)
my_axis = bliss.get_axis("px")

while True:
    for ii in range(10):
        print ii
コード例 #15
0
 def test_info(self):
     log.level(log.INFO)
     with wrapped_stdout() as stdout:
         log.info("test")
     output = stdout.getvalue()
     self.assertEquals(output, "INFO: test\n")
コード例 #16
0
 def test_error(self):
     log.level(log.ERROR)
     with wrapped_stderr():
         self.assertRaises(RuntimeError, log.error, "an error to log")
コード例 #17
0
    def __init__(self, *args, **kwargs):
        """

        :type self: ???
        """
        Controller.__init__(self, *args, **kwargs)

        # *Analog* limits of linear use of capacitive sensor.
        self.TADmin = self.config.get("TADmin", int, default=150000)
        self.TADmax = self.config.get("TADmax", int, default=700000)

        self.factor = 1  # conversion factor from TNS to microns.

        self._move_task = None

        # set the length of the given piezo,
        # the other needed attributes being calculated in class PiezoSize
        length = self.config.get("PiezoLength", float, 15)  # microns
        band = self.config.get("PiezoBand", float, 4)  # microns
        self._PiezoSize = PiezoSize(length, band)
        self._piezo_settle_sleep = 1  # seconds

        self._icepap_retries = 8

        # Capacitive Sensor's TNS to microns.
        # Measured by Leo Rousset in linear system.
        # 1 TNS = 1.75887 microns
        self.CS_tns2microns = 1.75887

        # leverage arm
        self.system_factor = 82.0 / 28.0  # ~2.93 (theorical value)
        self.system_factor = 2.8  # measured (cos taken into account in measurement...)

        # TNS to bender movement conversion factor
        self.bender_factor = self.CS_tns2microns * self.system_factor  # 4.925

        # Default factor for TNS to microns conversion   # 4.74
        # This value has shown to be different for the two sides of the mirror
        # we used for testing. It needs to be configurable.
        self.bender_factor = self.config.get("factor",
                                             float,
                                             default=self.bender_factor)

        # This value will decide in which distance from the calculated target_tns the icepap position
        # needs to be, before it is acceptable to go on to regulate the position with the piezo.
        self.tns_allowed_divergence = self.config.get("tns_allowed_divergence",
                                                      float,
                                                      default=0.5)

        # the controllers name. The axes will have names given by the configuration.
        self.cname = "PiezoJack"
        # one has to start somewhere. Be ready for the start.
        self._hw_status = AxisState("READY")

        # Attempt to open a logger for the controller
        self.log = alog.getLogger('Contr ' + self.cname)
        # set axis logging to the same level as elog.level
        self.log.setLevel(elog.level())
        self.log.info(
            "{0:s}logging for controller {1:s}: level {2:s}{3:s}".format(
                bcolors.RED + bcolors.BOLD, self.cname,
                elog.getLevelName(elog.level()), bcolors.ENDC))
        self.piezo = None
        self.icepap = None
コード例 #18
0
ファイル: BlissAxisManager.py プロジェクト: mguijarr/bliss
def main():
    try:
        delete_unused_bliss_axes()
    except:
        elog.error(
            "Cannot delete unused bliss axes.",
            raise_exception=False)

    try:
        py = PyTango.Util(sys.argv)

        log_param = [param for param in sys.argv if "-v" in param]
        if log_param:
            log_param = log_param[0]
            # print "-vN log flag found   len=%d" % len(log_param)
            if len(log_param) > 2:
                tango_log_level = int(log_param[2:])
            elif len(log_param) > 1:
                tango_log_level = 4
            else:
                print "BlissAxisManager.py - ERROR LOG LEVEL"

            if tango_log_level == 1:
                elog.level(40)
            elif tango_log_level == 2:
                elog.level(30)
            elif tango_log_level == 3:
                elog.level(20)
            else:
                elog.level(10)
        else:
            # by default : show INFO
            elog.level(20)
            tango_log_level = 0

        print ""

        # elog.info("tango log level=%d" % tango_log_level)
        # elog.debug("BlissAxisManager.py debug message")
        # elog.error("BlissAxisManager.py error message", raise_exception=False)

        # Searches for bliss devices defined in tango database.
        U = PyTango.Util.instance()
        db = U.get_database()
        device_list = get_devices_from_server().get('BlissAxisManager')

        if device_list is not None:
            _device = device_list[0]
            elog.info(" BlissAxisManager.py - BlissAxisManager device : %s" % _device)
            try:
                _config_file = db.get_device_property(_device, "config_file")["config_file"][0]
            except:
                elog.info(" BlissAxisManager.py - 'config_file' property not present ?")
                _config_file = None

            first_run = False
        else:
            elog.error("[FIRST RUN] New server never started ? -> no database entry...", raise_exception=False)
            elog.error("[FIRST RUN] NO CUSTOM COMANDS :( ", raise_exception=False)
            elog.error("[FIRST RUN] Restart DS to havec CUSTOM COMMANDS", raise_exception=False)
            first_run = True

        py.add_class(BlissAxisManagerClass, BlissAxisManager)
        # py.add_class(BlissAxisClass, BlissAxis)

        if not first_run:
            if _config_file is not None:
                elog.info(" BlissAxisManager.py - config file : " + bcolors.PINK + _config_file + bcolors.ENDC)
                try:
                    TgGevent.execute(bliss.load_cfg, _config_file)
                except:
                    elog.error("error (not present or syntax error?) in reading config file : %s" %
                               _config_file, raise_exception=False)
                    sys.excepthook(*sys.exc_info())
                    sys.exit(-1)
                else:
                    # Get axis names defined in config file.
                    axis_names = bliss_config.axis_names_list()
            else:
                elog.info(" BlissAxisManager.py - " + bcolors.PINK + "beacon config" + bcolors.ENDC)
                # Get axes names from property (= use beacon to get axis objects)
                bliss_config.BACKEND = "beacon"
                axis_names = db.get_device_property(_device, "axes")["axes"][0].split()

            elog.debug("axis names list : %s" % axis_names)

            for axis_name in axis_names:
                elog.debug("BlissAxisManager.py : _____________ axis %s _____________" % axis_name)
                try:
                    _axis = TgGevent.get_proxy(bliss.get_axis, axis_name)
                except ConnectionException:
                    elog.error("beacon_server seems not running")
                    sys.exit(-1)
                except:
                    print traceback.format_exc()
                    sys.exit(-1)

                new_axis_class_class = types.ClassType("BlissAxisClass_%s" % axis_name, (BlissAxisClass,), {})
                new_axis_class = types.ClassType("BlissAxis_%s" % axis_name, (BlissAxis,), {})

                types_conv_tab = {
                    None: PyTango.DevVoid,
                    str: PyTango.DevString,
                    int: PyTango.DevLong,
                    float: PyTango.DevDouble,
                    bool: PyTango.DevBoolean,
                    "str": PyTango.DevString,
                    "int": PyTango.DevLong,
                    "float": PyTango.DevDouble,
                    "bool": PyTango.DevBoolean,
                    "None": PyTango.DevVoid,
                    "float_array": PyTango.DevVarFloatArray,
                    "double_array": PyTango.DevVarDoubleArray,
                    "long_array": PyTango.DevVarLongArray,
                    "string_array": PyTango.DevVarStringArray
                }

                """
                CUSTOM COMMANDS
                """
                # Search and adds custom commands.
                _cmd_list = _axis.custom_methods_list()
                elog.debug("'%s' custom commands:" % axis_name)

                new_axis_class_class.cmd_list = dict(BlissAxisClass.cmd_list)

                for (fname, (t1, t2)) in _cmd_list:
                    setattr(new_axis_class, fname, getattr(_axis, fname))

                    tin = types_conv_tab[t1]
                    tout = types_conv_tab[t2]

                    new_axis_class_class.cmd_list.update({fname: [[tin, ""], [tout, ""]]})

                    elog.debug("   %s (in: %s, %s) (out: %s, %s)" % (fname, t1, tin, t2, tout))

                """
                CUSTOM SETTINGS AS ATTRIBUTES.
                """
                elog.debug(" BlissAxisManager.py : %s : -------------- SETTINGS -----------------" % axis_name)

                new_axis_class_class.attr_list = dict(BlissAxisClass.attr_list)

                for setting_name in _axis.settings():
                    if setting_name in ["velocity", "position", "dial_position", "state",
                                        "offset", "low_limit", "high_limit", "acceleration", "_set_position"]:
                        elog.debug(" BlissAxisManager.py -- std SETTING %s " % (setting_name))
                    else:
                        _attr_name = setting_name
                        _setting_type = _axis.controller().axis_settings.convert_funcs[_attr_name]
                        _attr_type = types_conv_tab[_setting_type]
                        elog.debug(" BlissAxisManager.py -- adds SETTING %s as %s attribute" % (setting_name, _attr_type))

                        # Updates Attributes list.
                        new_axis_class_class.attr_list.update({_attr_name:
                                                               [[_attr_type,
                                                                 PyTango._PyTango.AttrDataFormat.SCALAR,
                                                                 PyTango._PyTango.AttrWriteType.READ_WRITE], {
                            'Display level': PyTango._PyTango.DispLevel.OPERATOR,
                            'format': '%10.3f',
                            'description': '%s : u 2' % _attr_name,
                            'unit': 'user units/s^2',
                            'label': _attr_name
                            }]})

                        # Creates functions to read and write settings.
                        def read_custattr(self, attr, _axis=_axis, _attr_name=_attr_name):
                            _val = _axis.get_setting(_attr_name)
                            attr.set_value(_val)
                        new_read_attr_method = types.MethodType(read_custattr, new_axis_class,
                                                                new_axis_class.__class__)
                        setattr(new_axis_class, "read_%s" % _attr_name, new_read_attr_method)

                        def write_custattr(self, attr, _axis=_axis, _attr_name=_attr_name):
                            data = attr.get_write_value()
                            _axis.set_setting(_attr_name, data)

                        new_write_attr_method = types.MethodType(write_custattr, new_axis_class,
                                                                 new_axis_class.__class__)
                        setattr(new_axis_class, "write_%s" % _attr_name, new_write_attr_method)

                # End of custom command and settings
                elog.debug("BlissAxisManager.py : Adds new Axis specific class.")
                py.add_class(new_axis_class_class, new_axis_class)
                elog.debug("BlissAxisManager.py : Class added.")

        elog.debug("BlissAxisManager.py : intitialize server.")
        U.server_init()

    except PyTango.DevFailed:
        print traceback.format_exc()
        elog.exception(
            "Error in server initialization")
        sys.exit(0)

    try:
        bliss_admin_device_names = get_devices_from_server().get('BlissAxisManager')

        if bliss_admin_device_names:
            blname, server_name, device_number = bliss_admin_device_names[
                0].split('/')

            for axis_name in bliss_config.axis_names_list():
                device_name = '/'.join((blname,
                                        '%s_%s' % (server_name, device_number),
                                        axis_name))
                try:
                    elog.debug("Creating %s" % device_name)

                    U.create_device("BlissAxis_%s" % axis_name, device_name)

                except PyTango.DevFailed:
                    # print traceback.format_exc()
                    elog.debug("Device %s already defined in Tango database" % device_name)
                    pass

                # If axis name is not already a tango alias,
                # define it as an alias of the device.
                try:
                    db.get_device_alias(axis_name)
                except PyTango.DevFailed:
                    db.put_device_alias(device_name, axis_name)
                    elog.debug("Created alias %s for device %s" % (axis_name, device_name))

        else:
            # Do not raise exception to be able to use
            # Jive device creation wizard.
            elog.error("No bliss supervisor device",
                       raise_exception=False)

    except PyTango.DevFailed:
        print traceback.format_exc()
        elog.exception(
            "Error in devices initialization")
        sys.exit(0)

    U.server_run()
コード例 #19
0
ファイル: test_logging.py プロジェクト: tiagocoutinho/bliss
 def test_level(self):
     self.assertEquals(log.level(log.INFO), log.INFO)