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
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
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 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
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 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)
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)