Exemplo n.º 1
0
class SardanaChannel(ChannelObject, SardanaObject):
    def __init__(self,
                 name,
                 attribute_name,
                 username=None,
                 uribase=None,
                 polling=None,
                 **kwargs):

        super(SardanaChannel, self).__init__(name, username, **kwargs)

        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join(uribase, attribute_name)
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            #
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            #
            # if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            # logging.getLogger("HWR").debug("initialized")
        except DevFailed as traceback:
            self.imported = False
            return

        # read information
        try:
            if taurus.Release.version_info[0] == 3:
                ranges = self.attribute.getConfig().getRanges()
                if ranges is not None and ranges[0] != "Not specified":
                    self.info.minval = float(ranges[0])
                if ranges is not None and ranges[-1] != "Not specified":
                    self.info.maxval = float(ranges[-1])
            elif taurus.Release.version_info[0] > 3:  # taurus 4 and beyond
                minval, maxval = self.attribute.ranges()
                self.info.minval = minval.magnitude
                self.info.maxval = maxval.magnitude
        except BaseException:
            import traceback

            logging.getLogger("HWR").info(
                "info initialized. Cannot get limits")
            logging.getLogger("HWR").info("%s" % traceback.format_exc())

        # prepare polling
        # if the polling value is a number set it as the taurus polling period

        if self.polling:
            if isinstance(self.polling, types.IntType):
                self.attribute.changePollingPeriod(self.polling)

            self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue):
        self._writeValue(newValue)

    def _writeValue(self, newValue):
        self.attribute.write(newValue)

    def _readValue(self):
        value = self.attribute.read().value
        return value

    def getInfo(self):
        try:
            b = dir(self.attribute)
            self.info.minval, self.info.maxval = (
                self.attribute._TangoAttribute__attr_config.getLimits())
        except BaseException:
            import traceback

            logging.getLogger("HWR").info("%s" % traceback.format_exc())
        return self.info

    def update(self, event):

        data = event.event[2]

        try:
            newvalue = data.value

            if newvalue is None:
                newvalue = self.getValue()

            if isinstance(newvalue, types.TupleType):
                newvalue = list(newvalue)

            self.value = newvalue
            self.emit("update", self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self, *args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()
Exemplo n.º 2
0
class SardanaChannel(ChannelObject, SardanaObject):
    def __init__(
        self, name, attribute_name, username=None, uribase=None, polling=None, **kwargs
    ):

        super(SardanaChannel, self).__init__(name, username, **kwargs)

        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join(uribase, attribute_name)
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            #
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            #
            # if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            # logging.getLogger("HWR").debug("initialized")
        except DevFailed as traceback:
            self.imported = False
            return

        # read information
        try:
            if taurus.Release.version_info[0] == 3:
                ranges = self.attribute.getConfig().getRanges()
                if ranges is not None and ranges[0] != "Not specified":
                    self.info.minval = float(ranges[0])
                if ranges is not None and ranges[-1] != "Not specified":
                    self.info.maxval = float(ranges[-1])
            elif taurus.Release.version_info[0] > 3:  # taurus 4 and beyond
                minval, maxval = self.attribute.ranges()
                self.info.minval = minval.magnitude
                self.info.maxval = maxval.magnitude
        except BaseException:
            import traceback

            logging.getLogger("HWR").info("info initialized. Cannot get limits")
            logging.getLogger("HWR").info("%s" % traceback.format_exc())

        # prepare polling
        # if the polling value is a number set it as the taurus polling period

        if self.polling:
            if isinstance(self.polling, types.IntType):
                self.attribute.changePollingPeriod(self.polling)

            self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue):
        self._writeValue(newValue)

    def _writeValue(self, newValue):
        self.attribute.write(newValue)

    def _readValue(self):
        value = self.attribute.read().value
        return value

    def getInfo(self):
        try:
            b = dir(self.attribute)
            self.info.minval, self.info.maxval = (
                self.attribute._TangoAttribute__attr_config.getLimits()
            )
        except BaseException:
            import traceback

            logging.getLogger("HWR").info("%s" % traceback.format_exc())
        return self.info

    def update(self, event):

        data = event.event[2]

        try:
            newvalue = data.value

            if newvalue is None:
                newvalue = self.getValue()

            if isinstance(newvalue, types.TupleType):
                newvalue = list(newvalue)

            self.value = newvalue
            self.emit("update", self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self, *args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()
Exemplo n.º 3
0
class SardanaChannel(ChannelObject, SardanaObject):

    def __init__(self, name, attribute_name, username=None, uribase = None, polling=None, **kwargs):

        super(SardanaChannel, self).__init__(name,username,**kwargs)
 
        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join( uribase, attribute_name )
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        logging.getLogger("HWR").debug("creating Sardana model %s, polling=%s", self.model, polling)

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            # 
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            # 
            #if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            logging.getLogger("HWR").info("initialized")
        except DevFailed as traceback:
            self.imported = False
            return
        
        # read information
        try:
            self.info.minval, self.info.maxval = self.attribute._TangoAttribute__attr_config.getLimits()
            logging.getLogger("HWR").info("info initialized. Got minval=%s, maxval=%s" %(self.info.minval, self.info.maxval))
        except:
            logging.getLogger("HWR").info("info initialized. Cannot get limits")
       
        
        # prepare polling
        # if the polling value is a number set it as the taurus polling period
        if self.polling:
             if type(self.polling) == int:
                  self.attribute.changePollingPeriod(self.polling)
             
             self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue, wait=False):
        self._writeValue(newValue)
 
    def _writeValue(self, newValue):
        self.attribute.write(newValue)
            
    def _readValue(self):
        value = self.attribute.read().value
        return value
            
    def getInfo(self):
        return self.info

    def update(self, event):

        data = event.event[2]
        
        try:
            newvalue = data.value

            if newvalue == None:
                newvalue = self.getValue()
    
            if type(newvalue) == tuple:
                newvalue = list(newvalue)
    
            self.value = newvalue
            self.emit('update', self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self,*args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()
Exemplo n.º 4
0
class SardanaChannel(ChannelObject, SardanaObject):
    def __init__(self,
                 name,
                 attribute_name,
                 username=None,
                 uribase=None,
                 polling=None,
                 **kwargs):

        super(SardanaChannel, self).__init__(name, username, **kwargs)

        class ChannelInfo(object):
            def __init__(self):
                super(ChannelInfo, self).__init__()

        self.attributeName = attribute_name
        self.model = os.path.join(uribase, attribute_name)
        self.attribute = None

        self.value = None
        self.polling = polling

        self.info = ChannelInfo()
        self.info.minval = None
        self.info.maxval = None

        logging.getLogger("HWR").debug("creating Sardana model %s, polling=%s",
                                       self.model, polling)

        self.init_device()

    def init_device(self):

        try:
            self.attribute = Attribute(self.model)
            #
            # DIRTY FIX to make compatible taurus listeners and existence of Tango channels/commands
            # as defined in Command/Tango.py
            #
            #if self.attribute.__class__ == taurus.core.tango.tangoattribute.TangoAttribute:
            #    dev = self.attribute.getParentObj()
            #    dp = dev.getHWObj()
            #    try:
            #        dp.subscribe_event = dp._subscribe_event
            #    except AttributeError:
            #        pass
            logging.getLogger("HWR").info("initialized")
        except DevFailed as traceback:
            self.imported = False
            return

        # read information
        try:
            self.info.minval, self.info.maxval = self.attribute._TangoAttribute__attr_config.getLimits(
            )
            logging.getLogger("HWR").info(
                "info initialized. Got minval=%s, maxval=%s" %
                (self.info.minval, self.info.maxval))
        except:
            logging.getLogger("HWR").info(
                "info initialized. Cannot get limits")

        # prepare polling
        # if the polling value is a number set it as the taurus polling period
        if self.polling:
            if type(self.polling) == int:
                self.attribute.changePollingPeriod(self.polling)

            self.attribute.addListener(self.objectListener)

    def getValue(self):
        return self._readValue()

    def setValue(self, newValue, wait=False):
        self._writeValue(newValue)

    def _writeValue(self, newValue):
        self.attribute.write(newValue)

    def _readValue(self):
        value = self.attribute.read().value
        return value

    def getInfo(self):
        return self.info

    def update(self, event):

        data = event.event[2]

        try:
            newvalue = data.value

            if newvalue == None:
                newvalue = self.getValue()

            if type(newvalue) == tuple:
                newvalue = list(newvalue)

            self.value = newvalue
            self.emit('update', self.value)
        except AttributeError:
            # No value in data... this is probably a connection error
            pass

    def isConnected(self):
        return self.attribute is not None

    def channelListener(self, *args):
        ev = AttributeEvent(args)
        SardanaChannel._eventReceivers[id(ev)] = saferef.safe_ref(self.update)
        SardanaChannel._eventsQueue.put(ev)
        SardanaChannel._eventsProcessingTimer.send()