More clear manual document is needed for readAsync and readBlocking

I am not new to Ignition but I wanted to explain readAsync vs readBlocking to someone but I could not find any documents to compare readAsync and readBlocking or even any documents to explain each of them in a better way, not in the way currently explained. The manual needs to be updated to better show this.

For example, the picture below shows readAsync information but it says it will return “Nothing”. What does that mean?

It means void haha.

The idea of readAsync it to call a function after a Asynchronous read, while readBlocking return a QualifiedValue and the script actually waits a result from a tag.

1 Like

So read has been replaced by readAsync, right? read had 3 qualified values that you could address. we can use something like the script below for readAsync, too, right?

system.tag.readAsync([tagPath],tag_value)
system.tag.readAsync([tagPath],tag_quality)
system.tag.readAsync([tagPath],tag_timestamp)

system.tag.read() translates to system.tag.readBlocking(). The only difference is now readBlocking() takes a list of tag paths to read and returns a list of qualified tag values which makes the old readAll obsolete.

1 Like

I have never used the old read like that, this was the way

qv = system.tag.read(tagPath)
value = qv.value
quality = qv.quality
timeStamp = qv.timestamp

now is better to do

qv = system.tag.readBlocking([tagPath])[0]
value = qv.value
quality =qv.quality
timeStamp = qv.timestamp
1 Like

No, the old read() returned a qualified value. No reason to read it 3 times.

qTag = system.tag.read('tagPath')
value = qTag.value
quality =qTag.quality
tstamp = qTag.timestamp
3 Likes

@jespinmartin1 is correct.
Consider the following script:

def my_callback(asyncReturn):
    import system
    values = "".join([tag.value for tag in asyncReturn])
    system.util.getLogger("CALLBACK").info("Values: {0}.".format(values))

tag_paths = ["tagOne", "tagTwo"]
results = system.tag.readAsync([tagPaths], my_callback)
system.util.getLogger("MY_FUNC").info("Results: {0}.".format(results))

Note that results will always evaluate as None, and so the MY_FUNC logging will always display Results: ., whereas the CALLBACK logging will actually contain relevant values. When you see something like “Returns: Nothing”, you can think of it as essentially returning None.

2 Likes

Sorry, yes you’re right. Just correct it

2 Likes

Ew, no don’t do that. That’s three reads when you can do it all with one.

tag_qv = system.tag.read([tagPath])[0]
value = tag_qv.value
quality = tag_qv.quality
t_stamp = tqg_qv.timestamp

UPDATE: what @dkhayes117 said. Everyone keeps replying while I’m typing… :frowning_face:

3 Likes

Yes sorry haha, just realized :grimacing:

Now it makes more sense to me! Thanks for the clarification.
Also why do we always use [0] at the end of readBlocking?To return the first tag in the index?

Yes, that indexing is assuming you just want the singular (first) tag, as if you had supplied a tagPaths list which contained only one entry:

my_tag_value = system.tag.readblocking(["singleTag"])[0].value
1 Like

Awsome! Thank you, everyone!
@dkhayes117 @jespinmartin1 @dkhayes117

2 Likes

That’s for the case where you’re reading just one tag.
If you’re reading several tags (readBlocking([tag1, tag2, tag3...])) you’ll probably want to loop over the returned list:

tags = system.tag.readBlocking(paths)
for tag in tags:
    if tag.quality == "Good":
        print tag.value
1 Like