Access array tag elements with readBlocking

I realize this is an old thread, reviving due to system.tag.read function being depreciated. If utilizing the system.tag.readBlocking function (where a list of tag paths returns a list of qualified values), the return when reading an array from the database is somewhat different.
The below .read() returns an array of values matching the tag array:

tagArr = system.tag.read(tagPath).value
for i in range(len(tagArr)):
    print "[%i]=%s" % (i, tagArr[i])

Whereas the below (failed) attempt using .readBlocking() appears to return the definition of the array tag, which contains a single element resembling a concatenation of all tag element values:

tagArr = system.tag.readBlocking(tagPath)
for i in range(len(tagArr)):
    print "\n[%i]=%s" % (i, tagArr[i].value)

Can the code above be modified to match functionality of the .read() function (return a single array of qualified values)? Or, must each element in the array be read individually and appended to a local array variable, perhaps within a for loop?

Clearly I’m struggling through some fundamentals here. I recognized that the readBlocking() is returning the entire tag to the only element [0]. When I moved the values of [0] to another holding tag, I was able to proceed using readBlocking().

tagArr = system.tag.readBlocking(tagPath)
tagArr0 = tagArr[0].value
for i in range(len(tagArr0)):
    print "[%i]=%s" % (i, tagArr0[i])

system.tag.readBlocking returns a list of values, always, regardless of how many paths you give it at the start. That’s by design. Unfortunately, a complexity of array tags is that reading a single one also gives you a list of values, so when you do a read of an array tag you get a “2D” structure like this:

[
    [value1, value2, value3],
]

Note that if you were to read another, non-array tag the structure might be more clear:

[
    [value1, value2, value3],
    anotherTagValue,
]

One thing you could is flatten the list, if you know you’re only reading one array tag. Another thing you could do is extract the first element, as you’re doing in your second post.

A small point of syntax for you; you don’t need range(len(datastructure)) very often in Python/Ignition; usually you can directly iterate collections, i.e.:

tagValues = system.tag.readBlocking(tagPath)
arrayTag = tagValues[0].value
for value in arrayTag:
	print value, type(value)
1 Like