Example #1
0
	def __init__(self, model, parent=None):
		QWidget.__init__(self, parent)
		uic.loadUi("MotorWidget.ui", self)

		self.connect(self.configButton, SIGNAL("clicked()"), self.openConfig)
		self.connect(self.goButton, SIGNAL("clicked()"), self.go)
		self.connect(self.moveNegButton, SIGNAL("clicked()"), self.moveNeg)
		self.connect(self.movePosButton, SIGNAL("clicked()"), self.movePos)
		self.connect(self.disableButton, SIGNAL("toggled(bool)"), self.disable)

		self.stateLabel.setModel("%s/state" % model)
		self.positionLCD.setModel("%s/position" % model)

		self.motor = DeviceProxy(str(model))
		try:
			self.nameLabel.setText(self.motor.alias())
		except Exception:
			match = re.search(r"((?:[^/]+/){2}[^/]+)$", model)
			if not match:
				self.nameLabel.setText(model)
			else:
				self.nameLabel.setText(match.group(1))

		pos = AttributeProxy("%s/position" % model)
		try:
			self.unitLabel.setText(pos.get_config().unit)
		except Exception:
			self.unitLabel.setText("")

		self.absMotionEdit.setText(str(self.motor.position))
Example #2
0
    def test_alarm_propagation(self):
        device_name = '%s/sub1/1' % self.DOMAIN_NAME
        members_template = ['%s/capability/sub1cap1', '%s/capability/sub1cap2']
        members = [member % self.DOMAIN_NAME for member in members_template]

        self.add_members(device_name, 'tiles', members)
        dp = DeviceProxy(device_name)
        self.assertNotEqual(dp.state(), AttrQuality.ATTR_ALARM)
        member_dp = DeviceProxy(members[0])
        alarm_data = json.dumps({
            'name': 'an_attr',
            'min_alarm': '20',
            'max_alarm': '50'
        })
        member_dp.command_inout('set_attribute_alarm', alarm_data)
        member_dp.an_attr = 10
        attr = AttributeProxy(members[0] + '/an_attr')
        self.assertEqual(attr.read().quality, AttrQuality.ATTR_ALARM)
        self.assertEqual(member_dp.state(), PyTango._PyTango.DevState.ALARM)
        i = 0
        while (dp.state() != PyTango._PyTango.DevState.ALARM) and i < 3:
            sleep(1)
            i += 1

        self.assertEqual(dp.state(), PyTango._PyTango.DevState.ALARM)
 def power_on(self):
     motors = []
     motors = motors + self.get_pool_motors('hfm_y')
     motors = motors + self.get_pool_motors('vfm_x1')
     motors = motors + self.get_pool_motors('vfm_x2')
     attrs = []
     all_on = True
     for mot in motors:
         try:
             power_attr = AttributeProxy(mot.name + '/PowerOn')
             attrs.append(power_attr)
             if power_attr.read().value == False:
                 power_attr.write(True)
                 all_on = False
         except PyTango.DevFailed as e:
             self._log.warning(
                 "Motor {} doesn't have a PowerOn attribute".format(
                     mot.name))
     starttime = time.time()
     while all_on == False:
         if time.time() - starttime > 2:
             raise PyTango.DevFailed(
                 "Timeout while waiting for motors to power on")
         all_on = True
         time.sleep(0.1)
         for attr in attrs:
             if attr.read().value == False:
                 all_on = False
Example #4
0
    def __init__(self, model, parent=None):
        QWidget.__init__(self, parent)
        uic.loadUi("MotorWidget.ui", self)

        self.connect(self.configButton, SIGNAL("clicked()"), self.openConfig)
        self.connect(self.goButton, SIGNAL("clicked()"), self.go)
        self.connect(self.moveNegButton, SIGNAL("clicked()"), self.moveNeg)
        self.connect(self.movePosButton, SIGNAL("clicked()"), self.movePos)
        self.connect(self.disableButton, SIGNAL("toggled(bool)"), self.disable)

        self.stateLabel.setModel("%s/state" % model)
        self.positionLCD.setModel("%s/position" % model)

        self.motor = DeviceProxy(str(model))
        try:
            self.nameLabel.setText(self.motor.alias())
        except Exception:
            match = re.search(r"((?:[^/]+/){2}[^/]+)$", model)
            if not match:
                self.nameLabel.setText(model)
            else:
                self.nameLabel.setText(match.group(1))

        pos = AttributeProxy("%s/position" % model)
        try:
            self.unitLabel.setText(pos.get_config().unit)
        except Exception:
            self.unitLabel.setText("")

        self.absMotionEdit.setText(str(self.motor.position))
 def get_limits(attrib_name):
     attr_proxy = AttributeProxy(attrib_name)
     attr_config = attr_proxy.get_config()
     lower_limit = attr_config.min_value
     upper_limit = attr_config.max_value
     lower_warning = attr_config.alarms.min_warning
     upper_warning = attr_config.alarms.max_warning
     lower_alarm = attr_config.alarms.min_alarm
     upper_alarm = attr_config.alarms.max_alarm
     return [lower_limit, lower_alarm,
             lower_warning], [upper_limit, upper_alarm, upper_warning]
 def get_limits(attrib_name):
     attr_proxy = AttributeProxy(attrib_name)
     attr_config = attr_proxy.get_config()
     lower_limit = attr_config.min_value
     upper_limit = attr_config.max_value
     lower_warning = attr_config.alarms.min_warning
     upper_warning = attr_config.alarms.max_warning
     lower_alarm = attr_config.alarms.min_alarm
     upper_alarm = attr_config.alarms.max_alarm
     return [lower_limit, lower_alarm, lower_warning], [upper_limit,
                                                        upper_alarm,
                                                        upper_warning]
 def setEncoderSource(self, axis, value):
     self.attributes[axis]['encoder_source'] = value
     self.attributes[axis]['encoder_source_tango_attribute'] = None
     if value == '':
         return
     try:
         # check if it is an internal attribute
         enc_src_name = 'encoder_source_tango_attribute'
         if value.lower().startswith('attr://'):
             # 2012/03/27 Improve attr:// syntax to
             # allow reading of other axis of the same
             # system without
             # having to access them via tango://
             value_contents = value[7:]
             if ':' not in value_contents:
                 self.attributes[axis][enc_src_name] = \
                     FakedAttributeProxy(self, axis, value)
             else:
                 other_axis, other_value = \
                     value_contents.split(':')
                 other_axis = int(other_axis)
                 other_value = 'attr://' + other_value
                 self.attributes[axis][enc_src_name] = \
                     FakedAttributeProxy(self, other_axis, other_value)
         else:
             self.attributes[axis][enc_src_name] = \
                 AttributeProxy(value)
     except Exception as e:
         self._log.error('SetAxisExtraPar(%d,%s).\nException:\n%s' %
                         (axis, 'EncoderSource', str(e)))
         self.attributes[axis]['use_encoder_source'] = False
Example #8
0
    def calculate_motion(self, new_positions, items=None):
        user_elements = self.get_user_elements()
        if items is None:
            items = {}
        calculated = {}
        for new_position, element in zip(new_positions, user_elements):
            calculated[element] = new_position

            # TODO: get the configuration for an specific sardana class and
            # get rid of AttributeProxy.
            config = AttributeProxy(element.name + '/position').get_config()
            try:
                high = float(config.max_value)
            except ValueError:
                high = None
            try:
                low = float(config.min_value)
            except ValueError:
                low = None
            if high is not None:
                if float(new_position) > high:
                    msg = "requested movement of %s is above its upper limit"\
                        % element.name
                    raise RuntimeError(msg)
            if low is not None:
                if float(new_position) < low:
                    msg = "requested movement of %s is below its lower limit"\
                        % element.name
                    raise RuntimeError(msg)

        for new_position, element in zip(new_positions, user_elements):
            element.calculate_motion(new_position, items=items,
                                     calculated=calculated)
        return items
Example #9
0
class EventsTest(Device):
    """
    Switches beetwen valid and invalid attribute`s values.
    """
    __metaclass__ = DeviceMeta
    # PROTECTED REGION ID(EventsTest.class_variable) ENABLED START #
    # PROTECTED REGION END #    //  EventsTest.class_variable

    # -----------------
    # Device Properties
    # -----------------

    DeviceName = device_property(dtype='str', )

    # ----------
    # Attributes
    # ----------

    Max = attribute(dtype='double', )

    # ---------------
    # General methods
    # ---------------

    def init_device(self):
        Device.init_device(self)
        # PROTECTED REGION ID(EventsTest.init_device) ENABLED START #
        self.set_state(DevState.ON)
        self.proxy = AttributeProxy(self.DeviceName)
        # PROTECTED REGION END #    //  EventsTest.init_device

    def always_executed_hook(self):
        # PROTECTED REGION ID(EventsTest.always_executed_hook) ENABLED START #
        pass
        # PROTECTED REGION END #    //  EventsTest.always_executed_hook

    def delete_device(self):
        # PROTECTED REGION ID(EventsTest.delete_device) ENABLED START #
        pass
        # PROTECTED REGION END #    //  EventsTest.delete_device

    # ------------------
    # Attributes methods
    # ------------------

    def read_Max(self):
        # PROTECTED REGION ID(EventsTest.Attribute1_read) ENABLED START #
        value = self.proxy.read().value
        maximums = []
        for row in value:
            maximums.append(max(row))
        value = max(maximums)
        attr_quality = AttrQuality.ATTR_ALARM
        self.push_change_event("Max", float(value), time(), attr_quality)
        self.push_archive_event("Max", float(value), time(), attr_quality)
        return float(value), time(), attr_quality
Example #10
0
 def test_Attributes(self):
     self._total = 0
     for number in self._attrs:
         self._writes = 0
         device = self._devices[number]
         devAttrs = []
         for attrName in list(device.get_attribute_list()):
             attr = AttributeProxy("%s/%s" % (device.name(), attrName))
             if attr.get_config().writable == AttrWriteType.READ_WRITE:
                 devAttrs.append(attrName)
         otherAttrs = []
         for attrName, attrDesc in self._attrs[number].iteritems():
             if isinstance(attrDesc, Descriptor):
                 if attrDesc.hasSubAttrs():
                     for subAttrDesc in attrDesc.subAttrs():
                         if subAttrDesc.writable:
                             subAttrName = "%s_%s" % (attrName,
                                                      subAttrDesc.name)
                             self._checkAttrsLists(subAttrName, devAttrs,
                                                   otherAttrs)
                             # TODO: ignore, they will have their own test
                 elif attrDesc.writable:
                     self._checkAttrsLists(attrName, devAttrs, otherAttrs)
                     self.assertAttibute(attrName, attrDesc, device)
         for attrName, attrDesc in self._deviceStaticAttrs().iteritems():
             if isinstance(attrDesc, Descriptor) and attrDesc.writable:
                 self._checkAttrsLists(attrName, devAttrs, otherAttrs)
                 self.assertAttibute(attrName, attrDesc, device)
         self._subtotal = self._writes
         self._total += self._subtotal
         self._logger.info("plc%d: %d attributes write tested"
                           % (number, self._subtotal))
         if len(devAttrs) > 0:
             self._logger.warning("Unchecked device write attributes: %s"
                                  % (devAttrs))
         if len(otherAttrs) > 0:
             self._logger.warning("Described write attributes not present: "
                                  "%s" % (otherAttrs))
     self._logger.info("Total %d write attributes tested"
                       % (self._total))
     self._logger.info("Attributes write test succeed")
Example #11
0
 def init_device(self):
     Device.init_device(self)
     # PROTECTED REGION ID(EventsTest.init_device) ENABLED START #
     self.set_state(DevState.ON)
     self.proxy = AttributeProxy(self.DeviceName)
Example #12
0
    def calculate_motion(self, new_position, items=None, calculated=None):
        # if items already contains the positions for this pseudo motor
        # underlying motors it means the motion has already been calculated
        # by a sibling
        if items is not None and len(items):
            physical_elements = self.get_physical_elements_set()
            s_items = set(items)
            if s_items == physical_elements:
                if calculated is not None and self in calculated:
                    return

        user_elements = self.get_user_elements()
        positions = self.get_siblings_positions(use=calculated,
                                                write_pos=self.drift_correction)
        positions[self] = new_position
        pseudo_positions = len(positions) * [None]
        for pseudo, position in positions.items():
            pseudo_positions[pseudo.axis - 1] = position
        curr_physical_positions = self._position.get_physical_positions()
        physical_positions = self.controller.calc_all_physical(pseudo_positions,
                                                               curr_physical_positions)
        if physical_positions.error:
            raise PoolException("Cannot calculate motion: "
                                "calc_all_physical raises exception",
                                exc_info=physical_positions.exc_info)
        else:
            if physical_positions.value is None:
                raise PoolException("Cannot calculate motion: "
                                    "calc_all_physical returns None")

        if items is None:
            items = {}

         positions = physical_positions.value
         if not hasattr(positions , "__iter__"):
             positions = [positions]
         for new_position, element in zip(positions, user_elements):
            if new_position is None:
                raise PoolException("Cannot calculate motion: %s reports "
                                    "position to be None" % element.name)
            # TODO: get the configuration for an specific sardana class and
            # get rid of AttributeProxy - see sardana-org/sardana#663
            config = AttributeProxy(element.name + '/position').get_config()
            try:
                high = float(config.max_value)
            except ValueError:
                high = None
            try:
                low = float(config.min_value)
            except ValueError:
                low = None
            if high is not None:
                if float(new_position) > high:
                    msg = "requested movement of %s is above its upper limit"\
                        % element.name
                    raise RuntimeError(msg)
            if low is not None:
                if float(new_position) < low:
                    msg = "requested movement of %s is below its lower limit"\
                        % element.name
                    raise RuntimeError(msg)

            element.calculate_motion(new_position, items=items,
                                     calculated=calculated)