示例#1
0
    def init_device(self):
        self.debug_stream("In init_device() of axis")
        self.get_device_properties(self.get_device_class())

        # -v1
        self.info_stream("INFO STREAM ON ++++++++++++++++++++++++++")
        self.warn_stream("WARN STREAM ON ++++++++++++++++++++++++++")
        self.error_stream("ERROR STREAM ON ++++++++++++++++++++++++++")
        self.fatal_stream("FATAL STREAM ON ++++++++++++++++++++++++++")

        # -v3 (-v == -v4)
        self.debug_stream("DEBUG STREAM ON ++++++++++++++++++++++++++")

        try:
            self.axis = TgGevent.get_proxy(bliss.get_axis, self._axis_name)
            self.kontroler = TgGevent.get_proxy(self.axis.controller)
        except:
            elog.error("unable to get kontroller or axis")
            self.set_status(traceback.format_exc())

        self.debug_stream("axis found : %s" % self._axis_name)

        self.once = False

        self._init_time = time.time()
        self._t = time.time()

        self.attr_Home_position_read = 0.0
        self.attr_StepSize_read = 0.0
        self.attr_Steps_per_unit_read = 0.0
        self.attr_Acceleration_read = 1.0
        self.attr_HardLimitLow_read = False
        self.attr_HardLimitHigh_read = False
        self.attr_Backlash_read = 0.0
        self.attr_Offset_read = 0.0
        self.attr_Tolerance_read = 0.0
        self.attr_PresetPosition_read = 0.0
        self.attr_FirstVelocity_read = 0.0

        """
        self.attr_Steps_read = 0
        self.attr_Position_read = 0.0
        self.attr_Measured_Position_read = 0.0
        self.attr_Home_side_read = False
        """

        self.attr_trajpar_read = [[0.0]]

        # To force update of state and status.
        self.dev_state()

        # elog.info("    %s" % self.axis.get_info())
        elog.info(" BlissAxisManager.py Axis " + bcolors.PINK + self._ds_name + bcolors.ENDC + " initialized")
示例#2
0
 def test_axis_move(self):
     robz = TgGevent.get_proxy(emotion.get_axis, "robz")
     self.assertEqual(robz.state(), "READY")
     robz.move(180, wait=False)
     self.assertEqual(robz.state(), "MOVING")
     robz.wait_move()
     self.assertEqual(robz.state(), "READY")
示例#3
0
 def test_stop(self):
     robz = TgGevent.get_proxy(bliss.get_axis, "robz")
     self.assertEqual(robz.state(), "READY")
     robz.move(180, wait=False)
     self.assertEqual(robz.state(), "MOVING")
     robz.stop()
     self.assertEqual(robz.state(), "READY")
示例#4
0
 def init_device(self) :
     self.set_state(tango.DevState.ON)
     self.get_device_properties(self.get_device_class())
     self._nanodac = TgGevent.get_proxy(nanodac.nanodac,'server',{"controller_ip":self.controller_ip})
     self._ramp1 = TgGevent.get_proxy(self._nanodac.get_soft_ramp,1)
     self._ramp2 = TgGevent.get_proxy(self._nanodac.get_soft_ramp,2)
     self._c1 = TgGevent.get_proxy(self._nanodac.get_channel,1)
     self._c2 = TgGevent.get_proxy(self._nanodac.get_channel,2)
     self._c3 = TgGevent.get_proxy(self._nanodac.get_channel,3)
     self._c4 = TgGevent.get_proxy(self._nanodac.get_channel,4)
示例#5
0
 def init_device(self):
     self.set_state(tango.DevState.ON)
     self.get_device_properties(self.get_device_class())
     self._nanodac = TgGevent.get_proxy(
         nanodac.nanodac, 'server', {"controller_ip": self.controller_ip})
     self._ramp1 = TgGevent.get_proxy(self._nanodac.get_soft_ramp, 1)
     self._ramp2 = TgGevent.get_proxy(self._nanodac.get_soft_ramp, 2)
     self._c1 = TgGevent.get_proxy(self._nanodac.get_channel, 1)
     self._c2 = TgGevent.get_proxy(self._nanodac.get_channel, 2)
     self._c3 = TgGevent.get_proxy(self._nanodac.get_channel, 3)
     self._c4 = TgGevent.get_proxy(self._nanodac.get_channel, 4)
示例#6
0
    def __getattr__(self,name):
        if name.startswith('read_') or name.startswith('write_') :
            try:
                _,mod_name,attr_name = name.split('_')
                mod = getattr(self,'_%s' % mod_name)
            except ValueError:
                _,main_mod_name,mod_name,attr_name = name.split('_')
                main_mod = getattr(self,'_%s' % main_mod_name)
                main_mod = main_mod.get_base_obj()
                mod = TgGevent.get_proxy(getattr,main_mod,mod_name)

            if name.startswith('read_'):
                func = _CallableRead(mod,attr_name)
            else:
                func = _CallableWrite(mod,attr_name)
            self.__dict__[name] = func
            return func

        raise AttributeError("Nanodac has no attribute %s" % name)
示例#7
0
    def __getattr__(self, name):
        if name.startswith('read_') or name.startswith('write_'):
            try:
                _, mod_name, attr_name = name.split('_')
                mod = getattr(self, '_%s' % mod_name)
            except ValueError:
                _, main_mod_name, mod_name, attr_name = name.split('_')
                main_mod = getattr(self, '_%s' % main_mod_name)
                main_mod = main_mod.get_base_obj()
                mod = TgGevent.get_proxy(getattr, main_mod, mod_name)

            if name.startswith('read_'):
                func = _CallableRead(mod, attr_name)
            else:
                func = _CallableWrite(mod, attr_name)
            self.__dict__[name] = func
            return func

        raise AttributeError("Nanodac has no attribute %s" % name)
示例#8
0
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()
示例#9
0
 def tearDownClass(cls):
     TgGevent.execute("exit")
示例#10
0
 def test_get_axis(self):
     robz = TgGevent.get_proxy(bliss.get_axis, "robz")
     self.assertTrue(robz)
示例#11
0
 def setUp(self):
     TgGevent.execute(bliss.load_cfg_fromstring, config_xml)
示例#12
0
 def setUp(self):
     TgGevent.execute(emotion.load_cfg_fromstring, config_xml)