Example #1
0
    def macroStatusReceived(self, s, t, v):
        if v is None or self._running_macros is None:
            return
        if t not in CHANGE_EVT_TYPES: return

        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        v = map(str, v.value)
        if not len(v[1]):
            return
        format = v[0]
        codec = CodecFactory().getCodec(format)

        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        v[1] = str(v[1])
        fmt, data = codec.decode(v)
        for macro_status in data:
            id = macro_status.get('id')
            macro = self._running_macros.get(id)
            self._last_running_macro = self._running_macro = macro
            # if we don't have the ID it's because the macro is running a submacro
            # or another client is connected to the same door (shame on him!) and
            # executing a macro we discard this event
            if macro is not None:
                macro.__dict__.update(macro_status)
        return data
Example #2
0
    def macroStatusReceived(self, s, t, v):
        if v is None or self._running_macros is None:
            return
        if t not in CHANGE_EVT_TYPES:
            return

        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        v = map(str, v.value)
        if not len(v[1]):
            return
        format = v[0]
        codec = CodecFactory().getCodec(format)

        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        v[1] = str(v[1])
        fmt, data = codec.decode(v)
        for macro_status in data:
            id = macro_status.get('id')
            macro = self._running_macros.get(id)
            self._last_running_macro = self._running_macro = macro
            # if we don't have the ID it's because the macro is running a submacro
            # or another client is connected to the same door (shame on him!) and
            # executing a macro we discard this event
            if macro is not None:
                macro.__dict__.update(macro_status)
        return data
Example #3
0
    def push_event(self, *args, **kwargs):
        '''callback method receiving the event'''
        event_data = args[0]
        if event_data.err:
            self._state_buffer = event_data.errors
            self._tango_macro_executor._done_event.set()

        attr_value = getattr(event_data, 'attr_value')
        if attr_value is None:
            return
        v = attr_value.value
        if not len(v[1]):
            return
        fmt = v[0]
        codec = CodecFactory().getCodec(fmt)

        fmt, data = codec.decode(v)
        for macro_status in data:
            state = macro_status['state']
            exc_stack = macro_status.get('exc_stack')
            if state == 'exception':
                exception_str = ''
                for line in exc_stack:
                    exception_str += line
                self._tango_macro_executor._exception = exception_str
            if state in self.START_STATES:
                # print 'TangoStatusCb.push_event: setting _started_event'
                self._tango_macro_executor._started_event.set()
            elif state in self.DONE_STATES:
                # print 'TangoStatusCb.push_event: setting _done_event %s'
                # %(state)
                self._tango_macro_executor._done_event.set()
            # else:
            #    print 'State %s' %(state)
            self._tango_macro_executor._state_buffer.append(state)
Example #4
0
    def push_event(self, *args, **kwargs):
        '''callback method receiving the event'''
        event_data = args[0]
        if event_data.err:
            self._state_buffer = event_data.errors
            self._tango_macro_executor._done_event.set()
        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        attr_value = event_data.attr_value
        v = map(str, attr_value.value)
        if not len(v[1]):
            return
        fmt = v[0]
        codec = CodecFactory().getCodec(fmt)

        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        v[1] = str(v[1])
        fmt, data = codec.decode(v)
        for macro_status in data:
            state = macro_status['state']
            self._tango_macro_executor._exception = macro_status.get(
                'exc_type')
            if state in self.START_STATES:
                #print 'TangoStatusCb.push_event: setting _started_event'
                self._tango_macro_executor._started_event.set()
            elif state in self.DONE_STATES:
                # print 'TangoStatusCb.push_event: setting _done_event %s'
                # %(state)
                self._tango_macro_executor._done_event.set()
            #else:
            #    print 'State %s' %(state)
            self._tango_macro_executor._state_buffer.append(state)
Example #5
0
    def push_event(self, *args, **kwargs):
        '''callback method receiving the event'''
        event_data = args[0]
        if event_data.err:
            self._state_buffer = event_data.errors
            self._tango_macro_executor._done_event.set()
        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        attr_value = event_data.attr_value
        v = map(str, attr_value.value)
        if not len(v[1]):
            return
        fmt = v[0]
        codec = CodecFactory().getCodec(fmt)

        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        v[1] = str(v[1])
        fmt, data = codec.decode(v)
        for macro_status in data:
            state = macro_status['state']
            self._tango_macro_executor._exception = macro_status.get(
                'exc_type')
            if state in self.START_STATES:
                #print 'TangoStatusCb.push_event: setting _started_event'
                self._tango_macro_executor._started_event.set()
            elif state in self.DONE_STATES:
                # print 'TangoStatusCb.push_event: setting _done_event %s'
                # %(state)
                self._tango_macro_executor._done_event.set()
            #else:
            #    print 'State %s' %(state)
            self._tango_macro_executor._state_buffer.append(state)
Example #6
0
    def filterData(self, data):
        '''reimplementation to decode data using the DevEncoded codecs'''
        if type(data) == tuple:
            from taurus.core.util.codecs import CodecFactory
            codec = CodecFactory().getCodec(data[0])

            try:
                fmt, decoded_data = codec.decode(data)
            except Exception, e:
                self.info('Decoder error: %s', e.message)
                raise e

            try:
                dtype = decoded_data.dtype
                v = decoded_data
            except:
                # note that this is potentially expensive
                v = numpy.array(decoded_data)
                dtype = v.dtype

            if dtype not in (float, numpy.double, numpy.int32, numpy.uint16,
                             numpy.int16, numpy.uint8, numpy.int8, bool):
                # note: numpy.uint32 was not included because of
                # https://sourceforge.net/p/tauruslib/tickets/33/
                try:
                    self.debug('casting to numpy.int32')
                    v = numpy.int32(v)
                except OverflowError:
                    raise OverflowError(
                        "type %s not supported by guiqwt and cannot be casted to int32" % repr(v.dtype))

            return v
Example #7
0
def macrodata(self, parameter_s=''):
    """macrodata
    
    Returns the data produced by the last macro"""
    door = get_door()
    macro_data = door.read_attribute("RecordData")

    from taurus.core.util.codecs import CodecFactory

    factory = CodecFactory()
    data = factory.decode(macro_data.value)
    return data
Example #8
0
    def _processRecordData(self, data):
        if data is None or data.value is None: return
        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        data = map(str, data.value)

        size = len(data[1])
        if size == 0: return
        format = data[0]
        codec = CodecFactory().getCodec(format)
        data = codec.decode(data)
        return data
Example #9
0
    def _processRecordData(self, data):
        if data is None or data.rvalue is None:
            return
        data = data.rvalue

        size = len(data[1])
        if size == 0:
            return
        format = data[0]
        codec = CodecFactory().getCodec(format)
        data = codec.decode(data)
        return data
Example #10
0
    def _processRecordData(self, data):
        if data is None or data.value is None: return
        # make sure we get it as string since PyTango 7.1.4 returns a buffer
        # object and json.loads doesn't support buffer objects (only str)
        data = map(str, data.value)

        size = len(data[1])
        if size == 0: return
        format = data[0]
        codec = CodecFactory().getCodec(format)
        data = codec.decode(data)
        return data
Example #11
0
    def get(self, cache=False):
        door = self._door
        macro_server = door.macro_server
        env = door.getEnvironment()

        ret = dict(ScanDir=env.get('ScanDir'),
                   DataCompressionRank=env.get('DataCompressionRank', 1),
                   PreScanSnapshot=env.get('PreScanSnapshot', []))
        scan_file = env.get('ScanFile')
        if scan_file is None:
            scan_file = []
        elif isinstance(scan_file, (str, unicode)):
            scan_file = [scan_file]
        ret['ScanFile'] = scan_file
        mnt_grps = macro_server.getElementsOfType("MeasurementGroup")
        mnt_grps_names = [mnt_grp.name for mnt_grp in mnt_grps.values()]
        mnt_grps_full_names = mnt_grps.keys()

        active_mnt_grp = env.get('ActiveMntGrp')
        if active_mnt_grp is None and len(mnt_grps):
            active_mnt_grp = mnt_grps_names[0]
            door.putEnvironment('ActiveMntGrp', active_mnt_grp)

        ret['ActiveMntGrp'] = active_mnt_grp
        ret['MntGrpConfigs'] = mnt_grp_configs = CaselessDict()

        if len(mnt_grps) == 0:
            return ret

        mnt_grp_grps = PyTango.Group("grp")
        # use full names cause we may be using a different Tango database
        mnt_grp_grps.add(mnt_grps_full_names)

        codec = CodecFactory().getCodec('json')
        replies = mnt_grp_grps.read_attribute("configuration")
        for mnt_grp, reply in zip(mnt_grps_names, replies):
            try:
                mnt_grp_configs[mnt_grp] = \
                    codec.decode(('json', reply.get_data().value),
                                 ensure_ascii=True)[1]
            except Exception, e:
                from taurus.core.util.log import warning
                warning('Cannot load Measurement group "%s": %s',
                        repr(mnt_grp), repr(e))
Example #12
0
    def get(self, cache=False):
        door = self._door
        macro_server = door.macro_server
        env = door.getEnvironment()

        ret = dict(ScanDir=env.get('ScanDir'),
                   DataCompressionRank=env.get('DataCompressionRank', 1),
                   PreScanSnapshot=env.get('PreScanSnapshot', []))
        scan_file = env.get('ScanFile')
        if scan_file is None:
            scan_file = []
        elif isinstance(scan_file, (str, unicode)):
            scan_file = [scan_file]
        ret['ScanFile'] = scan_file
        mnt_grps = macro_server.getElementsOfType("MeasurementGroup")
        mnt_grps_names = [mnt_grp.name for mnt_grp in mnt_grps.values()]
        mnt_grps_full_names = mnt_grps.keys()

        active_mnt_grp = env.get('ActiveMntGrp')
        if active_mnt_grp is None and len(mnt_grps):
            active_mnt_grp = mnt_grps_names[0]
            door.putEnvironment('ActiveMntGrp', active_mnt_grp)

        ret['ActiveMntGrp'] = active_mnt_grp
        ret['MntGrpConfigs'] = mnt_grp_configs = CaselessDict()

        if len(mnt_grps) == 0:
            return ret

        mnt_grp_grps = PyTango.Group("grp")
        # use full names cause we may be using a different Tango database
        mnt_grp_grps.add(mnt_grps_full_names)

        codec = CodecFactory().getCodec('json')
        replies = mnt_grp_grps.read_attribute("configuration")
        for mnt_grp, reply in zip(mnt_grps_names, replies):
            try:
                mnt_grp_configs[mnt_grp] = \
                    codec.decode(('json', reply.get_data().value),
                                 ensure_ascii=True)[1]
            except Exception, e:
                from taurus.core.util.log import warning
                warning('Cannot load Measurement group "%s": %s',
                        repr(mnt_grp), repr(e))
Example #13
0
    def macroStatusReceived(self, s, t, v):
        if v is None or self._running_macros is None:
            return
        if t not in CHANGE_EVT_TYPES:
            return

        v = v.value
        if not len(v[1]):
            return
        format = v[0]
        codec = CodecFactory().getCodec(format)

        fmt, data = codec.decode(v)
        for macro_status in data:
            id = macro_status.get('id')
            macro = self._running_macros.get(id)
            self._last_running_macro = self._running_macro = macro
            # if we don't have the ID it's because the macro is running a
            # submacro or another client is connected to the same door (shame
            #  on him!) and executing a macro we discard this event
            if macro is not None:
                macro.__dict__.update(macro_status)
        return data
Example #14
0
 def _fromJSON(self, json_str):
     json_codec = CodecFactory().getCodec('json')
     format, data = json_codec.decode(('json', json_str))
     return data
Example #15
0
 def _fromJSON(self, json_str):
     json_codec = CodecFactory().getCodec('json')
     format, data = json_codec.decode(('json', json_str))
     return data