Exemple #1
0
    def init(self):
        self.device = None

        try:
            self._video_mode = self.getProperty("video_mode", "RGB24")
            self.device = DeviceProxy(self.tangoname)
            # try a first call to get an exception if the device
            # is not exported
            self.device.ping()
        except PyTango.DevFailed as traceback:
            last_error = traceback[-1]
            logging.getLogger("HWR").error("%s: %s", str(self.name()),
                                           last_error.desc)

            self.device = BaseHardwareObjects.Null()
        else:
            if self.getProperty("exposure_time"):
                self._sleep_time = float(self.getProperty("exposure_time"))
            elif self.getProperty("interval"):
                self._sleep_time = float(self.getProperty("interval")) / 1000.0

            if self.getProperty("control_video", "True"):
                logging.getLogger("HWR").info("MXCuBE controlling video")

                if self.device.video_live:
                    self.device.video_live = False

                self.device.video_mode = self._video_mode
                self.set_exposure(self._sleep_time)

                self.device.video_live = True
            else:
                logging.getLogger("HWR").info("MXCuBE NOT controlling video")

        self.setIsReady(True)
    def _init(self):
        try:
            self.device = PyTango.DeviceProxy(self.tangoname)
        except PyTango.DevFailed as traceback:
            last_error = traceback[-1]
            logging.getLogger('HWR').error("%s: %s", str(self.name()),
                                           last_error['desc'])

            self.device = BaseHardwareObjects.Null()
        else:
            self.setIsReady(True)
Exemple #3
0
    def init(self):
        self.device = None

        try:
            self.device = DeviceProxy(self.tangoname)
            #try a first call to get an exception if the device
            #is not exported
            self.device.ping()
        except PyTango.DevFailed, traceback:
            last_error = traceback[-1]
            logging.getLogger('HWR').error("%s: %s", str(self.name()),
                                           last_error.desc)

            self.device = BaseHardwareObjects.Null()
Exemple #4
0
    def _init(self):

       self.udiffVER_Ok  = False
       self.badimg       = 0
       self.pollInterval = 500
       self.connected    = False

       try:
          self.device = PyTango.DeviceProxy(self.tangoname)
       except PyTango.DevFailed, traceback:
          last_error = traceback[-1]
          print "last error ",str(last_error)
          logging.getLogger('HWR').error("%s: %s", str(self.name()), last_error['desc'])
    
          self.device = BaseHardwareObjects.Null()
    def init(self):
        self.device = None
        
        try:
            self.device = DeviceProxy(self.tangoname)
            #try a first call to get an exception if the device
            #is not exported
            self.device.ping()
        except PyTango.DevFailed as traceback:
            last_error = traceback[-1]
            logging.getLogger('HWR').error("%s: %s", str(self.name()), last_error.desc)
            
            self.device = BaseHardwareObjects.Null()
        else:
            self.setExposure(self.getProperty("interval")/1000.0)
            self.device.video_mode = "BAYER_RG16"

        self.setIsReady(True)
    def startElement(self, name, attrs):
        if self.classError:
            return

        self.buffer = ""

        if len(self.objects) == 0:
            objectName = self.name
        else:
            objectName = name

        assert not self.elementIsAReference

        self.elementRole = None
        self.property = ""
        self.command = {}
        self.channel = {}

        #
        # determine path to the new object
        #
        self.path += "/" + str(name) + "[%d]"
        i = self.previousPath.rfind("[")

        if i >= 0 and self.path[:-4] == self.previousPath[:i]:
            objectIndex = int(self.previousPath[i + 1 : -1]) + 1
        else:
            objectIndex = 1  # XPath indexes begin at 1

        self.path %= objectIndex

        _attrs = attrs
        attrs = {}

        for k in list(_attrs.keys()):
            v = str(_attrs[k])

            if v == "None":
                attrs[str(k)] = None
            else:
                try:
                    attrs[str(k)] = int(v)
                except Exception:
                    try:
                        attrs[str(k)] = float(v)
                    except Exception:
                        if v == "False":
                            attrs[str(k)] = False
                        elif v == "True":
                            attrs[str(k)] = True
                        else:
                            attrs[str(k)] = v
        if name == "hwr_import":
            self.hwr_import_reference = attrs["href"]

        if "role" in attrs:
            self.elementRole = attrs["role"]
        if name == "device":
            # maybe we have to add the DeviceContainer mix-in class to each node of
            # the Hardware Object hierarchy
            i = len(self.objects) - 1
            while i >= 0 and not isinstance(
                self.objects[i], BaseHardwareObjects.DeviceContainer
            ):
                # newClass = new.classobj("toto", (self.objects[i].__class__,) + self.objects[i].__class__.__bases__ + (BaseHardwareObjects.DeviceContainer, ), {})
                # TODO replace deprecated DeviceContainerNode with a different class
                self.objects[i].__class__ = BaseHardwareObjects.DeviceContainerNode
                i -= 1

        #
        # is element a reference to another hardware object ?
        #
        ref = "hwrid" in attrs and attrs["hwrid"] or "href" in attrs and attrs["href"]
        if ref:
            self.elementIsAReference = True
            self.reference = str(ref)

            if self.reference.startswith("../"):
                self.reference = "/".join(
                    self.name.split("/")[:-1] + [self.reference[3:]]
                )
            elif self.reference.startswith("./"):
                self.reference = "/".join(
                    self.name.split("/")[:-1] + [self.reference[2:]]
                )
            return

        if name in newObjectsClasses:
            if "class" in attrs:
                moduleName = str(attrs["class"])
                className = moduleName.split(".")[-1]

                newObject = instanciateClass(moduleName, className, objectName)

                if newObject is None:
                    self.classError = True
                    return
                else:
                    newObject.setPath(self.path)
                    self.objects.append(newObject)
            else:
                newObjectClass = newObjectsClasses[name]
                newObject = newObjectClass(objectName)
                newObject.setPath(self.path)

                self.objects.append(newObject)
        elif name == "command":
            if "name" in attrs and "type" in attrs:
                # short command notation
                self.command.update(attrs)
            else:
                # long command notation (allow arguments)
                self.objects.append(BaseHardwareObjects.HardwareObjectNode(objectName))
        elif name == "channel":
            if "name" in attrs and "type" in attrs:
                self.channel.update(attrs)
        else:
            if len(self.objects) == 0:
                if "class" in attrs:
                    moduleName = str(attrs["class"])
                    className = moduleName.split(".")[-1]

                    newObject = instanciateClass(moduleName, className, objectName)

                    if newObject is None:
                        self.classError = True
                        return
                else:
                    newObject = BaseHardwareObjects.HardwareObject(objectName)

                newObject.setPath(self.path)
                self.objects.append(newObject)
                """
                # maybe we can create a HardwareObject ? be strict for the moment...
                logging.getLogger("HWR").error("%s: unknown Hardware Object type (should be one of %s)", objectName, str(newObjectsClasses.keys()))
                self.classError = True
                return
                """
            else:
                newObject = BaseHardwareObjects.HardwareObjectNode(objectName)
                newObject.setPath(self.path)
                self.objects.append(newObject)

                self.property = name  # element is supposed to be a Property
                def _init(self):
                    self.forceUpdate = False
                    self.device = None
                    self.imgtype = None
                    try:
                        self.device = PyTango.DeviceProxy(self.tangoname)
                        #try a first call to get an exception if the device
                        #is not exported
                        self.device.ping()
                    except PyTango.DevFailed as traceback:
                        last_error = traceback[-1]
                        logging.getLogger('HWR').error("%s: %s", str(self.name()), last_error.desc)

                        self.device = BaseHardwareObjects.Null()
                        self.bpmDevice = None
                    else:
                        self.setImageTypeFromXml('imagetype')


                        self.__brightnessExists = False
                        self.__contrastExists   = False
                        self.__gainExists       = False
                        self.__gammaExists      = False

                        _attribute_list = self.device.get_attribute_list()
                        #self.oprint ("attribute list:")
                        #self.oprint (_attribute_list)

                        imgChan    = self.addChannel({ 'type': 'tango', 'name': 'image', "read_as_str": 1 }, "RgbImage")
                        imgWidth   = self.addChannel({ 'type': 'tango', 'name': 'width' },     "Width")
                        imgHeight  = self.addChannel({ 'type': 'tango', 'name': 'height'},     "Height")
                        fullWidth  = self.addChannel({ 'type': 'tango', 'name': 'fullwidth' }, "FullWidth")
                        fullHeight = self.addChannel({ 'type': 'tango', 'name': 'fullheight'}, "FullHeight")
                        roi        = self.addChannel({ 'type': 'tango', 'name': 'roi'},        "Roi")
                        exposure   = self.addChannel({ 'type': 'tango', 'name': 'exposure'},   "Exposure")

                        if "Brightness" in _attribute_list:
                            print("add brightness")
                            brightness = self.addChannel({ 'type': 'tango', 'name': 'brightness'}, "Brightness")
                            self.__brightnessExists = True

                        if "Contrast" in _attribute_list:
                            contrast = self.addChannel({ 'type': 'tango', 'name': 'contrast'},   "Contrast")
                            self.__contrastExists = True

                        if "Gain" in _attribute_list:
                            gain = self.addChannel({ 'type': 'tango', 'name': 'gain'},       "Gain")
                            self.__gainExists = True

                        if "Gamma" in _attribute_list:
                            gamma = self.addChannel({ 'type': 'tango', 'name': 'gamma'},      "Gamma")
                            self.__gammaExists = True

                        self.setIsReady(True)

                        """
                        Check wether there is a BPM device defined or not
                        """
                        if self.getProperty("bpmname"):
                            self.bpmDevice = CommandContainer.CommandContainer()
                            self.bpmDevice.tangoname = self.bpmname
                            threshold = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'threshold'}, "Threshold")
                            centerx   = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'centerx'}, "X")
                            centery   = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'centery'}, "Y")
                            fwhmx     = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'fwhmx'}, "XFwhm")
                            fwhmy     = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'fwhmy'}, "YFwhm")
                            maxpix    = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'maxpix'}, "MaxPixelValue")
                            intensity = self.bpmDevice.addChannel({ 'type': 'tango', 'name': 'intensity'}, "Intensity")
                            onCmd     = self.bpmDevice.addCommand({ 'type': 'tango', 'name': 'on'}, "On")
                            offCmd    = self.bpmDevice.addCommand({ 'type': 'tango', 'name': 'off'}, "Off")
                            stateCmd  = self.bpmDevice.addCommand({ 'type': 'tango', 'name': 'state'}, "State")
                        else:
                            self.bpmDevice = None
                            logging.getLogger('HWR').warning("%s: No BPM defined", str(self.name()))