# \[Question\] How do I use .readAsync to read tag value

**URL:** <https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008>\
**Category:** Ignition Early Access\
**Created:** [January 21, 2019, 12:10am UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008 "2019-01-21T00:10:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam.Bartlett](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@Sam.Bartlett](https://forum.inductiveautomation.com/u/Sam.Bartlett)\
**Post date:** [January 21, 2019, 12:10am UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/1 "2019-01-21T00:10:44Z")

</div>

Hi all,

Would anybody be able to provide an example on how to use the new system.tag.readAsync, for whatever reason I’m not able to wrap my head around the callback that must be provided in the function.

Thanks

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 21, 2019, 12:24am UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/2 "2019-01-21T00:24:37Z")

</div>

It expects you to provide a callback function that will accept a list of qualified values.

Something like this:

```python
def callback(values):
	print [qv.value for qv in values]
	
system.tag.readAsync(['Tag1', 'Tag2'], callback)

```

---

<div class="post-metadata">

**Author:** ![cwaddoups](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@cwaddoups](https://forum.inductiveautomation.com/u/cwaddoups)\
**Post date:** [March 5, 2019, 3:48pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/3 "2019-03-05T15:48:38Z")

</div>

What exactly is the scope of the callback function? I ran the script in the script console and all the print statements printed in the output console of my designer instead of the script console. I also couldn’t figure out a way to return values to the main of my script, certainly I can use the readBlocking method to do this, I just wanted to verify if this was how readAsync was supposed to function.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 5, 2019, 3:51pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/4 "2019-03-05T15:51:44Z")

</div>

The callback will likely be coming in on another thread. I don't think it's strange that the print out went to the designer's output console rather than the script interpreter.

> [@cwaddoups](#):
>
> I also couldn’t figure out a way to return values to the main of my script,

If you want to "return" the values to your main script then you really just want a blocking call. If you're using the async version you should be writing logic that continues from the point of the callback.

---

<div class="post-metadata">

**Author:** ![cwaddoups](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@cwaddoups](https://forum.inductiveautomation.com/u/cwaddoups)\
**Post date:** [March 5, 2019, 4:00pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/5 "2019-03-05T16:00:22Z")

</div>

Thanks, so that means that essentially we should not plan on trying to write a universal callback method. readAsync should only be used for a specific purpose where the end result is not used locally within the current script? Is there a benefit to utilizing readAsync instead of a separate global script that does the same thing but uses a blocking call?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 5, 2019, 4:11pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/6 "2019-03-05T16:11:06Z")

</div>

`readAsync` could be useful to e.g. make a call to read a tag value and then update the UI later on the callback thread using `invokeLater`, all without blocking the UI thread this script may have been invoked from.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 5, 2019, 4:59pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/7 "2019-03-05T16:59:42Z")

</div>

You can make semi-generic callbacks by creating jython classes that implement the ` __callable__ ` special method, and supply an instance as the callback. Have the ` __init__ ` method save the state you need to carry your logic forward.

---

<div class="post-metadata">

**Author:** ![pstepanenko](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@pstepanenko](https://forum.inductiveautomation.com/u/pstepanenko)\
**Post date:** [April 25, 2019, 2:25pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/8 "2019-04-25T14:25:03Z")

</div>

Kevin, did I understand correctly that system.tag.readAsync() only works in Vision and in Perpspective and doesnt’ work in the gateway scripts and in the script console?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 25, 2019, 2:26pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/9 "2019-04-25T14:26:27Z")

</div>

> [@pstepanenko](#):
>
> Kevin, did I understand correctly that system.tag.readAsync() only works in Vision and in Perpspective and doesnt’ work in the gateway scripts and in the script console?

No, readAsync and readBlocking are available in all scopes - in fact, _all_ tag operations are now asynchronous by default; the readBlocking methods just perform the asynchronous call and wait for the result for you.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [April 25, 2019, 2:34pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/10 "2019-04-25T14:34:46Z")

</div>

Will the **system.tag.readAll()** and **writeAll** functions continue to be supported in version 8 onward or will they be depricated in future versions?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 25, 2019, 2:36pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/11 "2019-04-25T14:36:51Z")

</div>

They are already “deprecated” but we will almost certainly never make them stop working. They’re already bridging to `readBlocking`/`writeBlocking` behind the scenes, but removing a system function outright would unnecessarily break existing projects (which is why `system.tag.getTagValue()` still works, nearly a decade later)

---

<div class="post-metadata">

**Author:** ![pstepanenko](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@pstepanenko](https://forum.inductiveautomation.com/u/pstepanenko)\
**Post date:** [April 25, 2019, 2:52pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/12 "2019-04-25T14:52:46Z")

</div>

Indeed, the function system.tag.readAsync() in the console works. However, for some reason she doesn’t work in my gateway timer script.

This is the script that I use:

```auto
tagPaths = ['[default]test_folder/test_val1','[default]test_folder/test_val2']

def callback(values):
	arr = []
	for qv in values:
		print qv.value
		arr.append(str(qv.value))
	system.tag.write('[default]test_folder/result',str(arr))

system.tag.readAsync(tagPaths, callback)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 25, 2019, 3:09pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/13 "2019-04-25T15:09:22Z")

</div>

Is the error “global name `system` is not defined”? I had to add `import system` _inside the callback function definition_ to get your example to work (due to gateway timer scripts having weird legacy scoping rules), but after doing so, it worked fine.

---

<div class="post-metadata">

**Author:** ![pstepanenko](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@pstepanenko](https://forum.inductiveautomation.com/u/pstepanenko)\
**Post date:** [April 26, 2019, 8:29am UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/14 "2019-04-26T08:29:54Z")

</div>

Thanks so much. It work

---

<div class="post-metadata">

**Author:** ![mitchell-ACS](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mitchell-acs/32/30062_2.png) [@mitchell-ACS](https://forum.inductiveautomation.com/u/mitchell-ACS)\
**Post date:** [May 30, 2019, 7:14pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/15 "2019-05-30T19:14:35Z")

</div>

Am I using this correctly? When I run it in the script console all it will return is ‘None’

```auto
def tag_value(values):
	return [qv.value for qv in values]
def tag_quality(values):
	return [qv.quality for qv in values]
def tag_timestamp(values):
	return [qv.timestamp for qv in values]

tagPath = '[Carefree]Customers/Demo/well_1/Reads/Flow'
print system.tag.readAsync([tagPath],tag_value)
print system.tag.readAsync([tagPath],tag_quality)
print system.tag.readAsync([tagPath],tag_timestamp)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 30, 2019, 7:21pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/16 "2019-05-30T19:21:31Z")

</div>

No, if you wanted to see some results you’d put the print statements in each of those methods.

The way you have it written now expects a synchronous result, so you should just use the synchronous version of the function if that’s what you want.

The async functions don’t return anything, they call some other function with the eventual result.

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [June 25, 2019, 9:42pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/17 "2019-06-25T21:42:52Z")

</div>

> [@Kevin.Herron](#):
>
> so you should just use the synchronous version of the function

What is the synchronous version of the system.tag.readAsync function?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 25, 2019, 9:54pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/18 "2019-06-25T21:54:27Z")

</div>

The new [`system.tag.readBlocking`](https://docs.inductiveautomation.com/display/DOC80/system.tag.readBlocking) or the (legacy) `system.tag.read` are synchronous.

---

<div class="post-metadata">

**Author:** ![JHortenberry](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@JHortenberry](https://forum.inductiveautomation.com/u/JHortenberry)\
**Post date:** [August 27, 2020, 3:01pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/19 "2020-08-27T15:01:21Z")

</div>

So… The question remains unanswered?

When I read a tag, it implies that I need the value to return to the calling context.  
…then, I will use the value to affect the decisions that follow.

def callback(values):

```
 <?? return values ??> #<??Return this list to the calling function ??>

```

tagPaths = [’[default]test\_folder/test\_val1’,’[default]test\_folder/test\_val2’]  
system.tag.readAsync(tagPaths, callback)

values = \< ? Return the values object list from the callback function ? \>

val1 = values[0].value  
val2 = values[1].value

if val1 = True:  
print “Value 1 is True”

if val2 = True:  
print “Value 2 is True”

\<etc…\>

The expected functionality, would be read the values and don’t block other processes, then return all the values to the point of the call (or slightly there after). …similar to the .join operator when utilizing multi-threading / multi-processing.

If the deprecated system.tag.read is ever removed…this will cause issue.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 27, 2020, 3:04pm UTC](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008/20 "2020-08-27T15:04:06Z")

</div>

> [@JHortenberry](#):
>
> So… The question remains unanswered?
> 
> When I read a tag, it implies that I need the value to return to the calling context.  
> …then, I will use the value to affect the decisions that follow.

It was answered, use `system.tag.readBlocking`.

> [@JHortenberry](#):
>
> The expected functionality, would be read the values and don’t block other processes, then return all the values to the point of the call (or slightly there after). …similar to the .join operator when utilizing multi-threading / multi-processing.

That's not how `.join()` works. The thread calling `join()` blocks, just like the thread calling `system.tag.readBlocking` will block.

[Next page](https://forum.inductiveautomation.com/t/question-how-do-i-use-readasync-to-read-tag-value/22008.md?page=2)
