Tag readAsync callback return with tag paths

Is there a way to get the corresponding tag path to return with the value in a callback function called from readAsync?

I need to modify each tag value...for many values.

( I know there are other ways ... I was trying to get the Async method to work.)

def callback(items):

for item in items:
        #print item.tagPath
        # -- need to modify each tag value --
        print item.value

tagPaths =

tagPaths.append('[default]Tag1')
tagPaths.append('[default]Tag2')
tagPaths.append(' ... ')

system.tag.readAsync(tagPaths, callback)

NOTE: dir(item)
['BAD', 'CONFIG_ERROR', 'DISABLED', 'EXPRESSION_EVAL_ERROR', 'INITIAL_VALUE', 'NOT_CONNECTED', 'NOT_FOUND', 'REFERENCE_NOT_FOUND', 'STALE', 'TRANSFORM_ERROR', 'TYPE_CONVERSION', 'UNKNOWN', 'UNSUPPORTED', 'class', 'copy', 'deepcopy', 'delattr', 'doc', 'ensure_finalizer', 'eq', 'format', 'getattribute', 'hash', 'init', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'str', 'subclasshook', 'unicode', 'class', 'clone', 'derive', 'equals', 'fromObject', 'getClass', 'getQuality', 'getTimestamp', 'getValue', 'hashCode', 'notify', 'notifyAll', 'quality', 'setQuality', 'setTimestamp', 'setValue', 'timestamp', 'toString', 'unwrap', 'updateTimestamp', 'value', 'valueOf', 'wait']

Just pass them in yourself.

def callback(paths, items):
   # ...

tagPaths = []
# ...

system.tag.readAsync(tagPaths, lambda items: callback(tagPaths, items))

note that "items" is a poor name for what is a list of QualifiedValue objects.

1 Like

If find it easiest to just use the closure a def produces if you use a def anyways:

tagPaths = [....]


def callback(qvList):
	for tagPath, qv in zip(tagPaths, qvList):
		# Do whatever

system.tag.readAsync(tagPaths, callback)
1 Like

@JHortenberry: Please see Wiki - how to post code on this forum. Your indentation and formatting is messed up.

An equally good solution...

Thanks Guys!