Exemple #1
0
    def check_attribute(self,
                        attr_name,
                        dev_name,
                        target_value,
                        period=0.3,
                        timeout=1.0,
                        tolerance=None,
                        write=True):
        """
        Check an attribute to see if it reaches a target value. Returns a deferred for the result of the
        check.
        Upon calling the function the target is written to the attribute if the "write" parameter is True.
        Then reading the attribute is polled with the period "period" for a maximum number of retries.
        If the read value is within tolerance, the callback deferred is fired.
        If the read value is outside tolerance after retires attempts, the errback is fired.
        The maximum time to check is then period x retries

        :param attr_name: Tango name of the attribute to check, e.g. "position"
        :param dev_name: Tango device name to use, e.g. "gunlaser/motors/zaber01"
        :param target_value: Attribute value to wait for
        :param period: Polling period when checking the value
        :param timeout: Time to wait for the attribute to reach target value
        :param tolerance: Absolute tolerance for the value to be accepted
        :param write: Set to True if the target value should be written initially
        :return: Deferred that will fire depending on the result of the check
        """
        self.logger.info("Check attribute \"{0}\" on \"{1}\"".format(
            attr_name, dev_name))
        if dev_name in self.device_names:
            factory = self.device_factory_dict[self.device_names[dev_name]]
            d = factory.buildProtocol("check",
                                      attr_name,
                                      None,
                                      write=write,
                                      target_value=target_value,
                                      tolerance=tolerance,
                                      period=period,
                                      timeout=timeout)
            d.addCallback(self.update_attribute)
        else:
            self.logger.error("Device name {0} not found among {1}".format(
                dev_name, self.device_factory_dict))
            err = tango.DevError(
                reason="Device {0} not used".format(dev_name),
                severety=tango.ErrSeverity.ERR,
                desc=
                "The device is not in the list of devices used by this controller",
                origin="check_attribute")
            d = Failure(tango.DevFailed(err))
        return d
Exemple #2
0
 def write_attribute(self, name, device_name, data):
     self.logger.info("Write attribute \"{0}\" on \"{1}\"".format(
         name, device_name))
     if device_name in self.device_names:
         factory = self.device_factory_dict[self.device_names[device_name]]
         d = factory.buildProtocol("write", name, data)
     else:
         self.logger.error("Device name {0} not found among {1}".format(
             device_name, self.device_factory_dict))
         err = tango.DevError(
             reason="Device {0} not used".format(device_name),
             severety=tango.ErrSeverity.ERR,
             desc=
             "The device is not in the list of devices used by this controller",
             origin="write_attribute")
         d = Failure(tango.DevFailed(err))
     return d