LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Array elements via Property Nodes

LV 2013, Win7

 

Starting from a control reference, I need to traverse a data structure of arbitrary complexity, in order to produce a list of NAMEs and VALUEs (variant) for each element.

 

Simple control tyoes are easy:

 

I get the NAME (label) and append to the prefix I started with, and then get the VALUE, which is already a variant.

Append those to the array:

Convert 1.PNG

 

 

 

-----

 

If the thing is a CLUSTER, then it's not difficult either.

I simply cast the reference to a CLUSTER ref, get the controls from it, and recursively call myself for each one:

 

Convert 2.PNG

 

-----

 

However, if the thing is an ARRAY, then I'm stumped.

 

I know that if I ask for the VALUE of an array, I get a single VARIANT, which contains all the elements values.

 

But that's not acceptable for my purpose (assigning a PROPERTY in a TDMS file).

 

I know that there is really only one element in an array (as far as properties go).

 

But I need to build a name, and a variant value, for every element in the array.

 

And the element might be a boolean or a cluster, so I need to recurse using a reference to the individual element.

 

I tried setting the INDEX VALS property before accessing the ARR ELEM property, but...

1--- That changes the on-screen view, which I don't like, and

2--- it doesn't work.

 

When I set the INDEX to 0, and use the ARR ELEM to get the VALUE, I get the value of the last element (#2).

After that, I get 0.

 

 

Convert 3.PNG

 

 

So how can I get a reference to a given element, so that if I recurse, I get the values from that one element?

 

How can I figure out how many elements are in the array ? (remember that I don't know what type of array it is) ?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 7
(5,310 Views)

I would assume that you need to iterate through the elements of the array from the variant you get from the array itself, using something like the OpenG variant VIs or the vi.lib variant VIs (should be in vi.lib\utility\variantdatatype, altough I don't know if you could get the data from those as you want). I would suggest looking at the OpenG variant config VIs or the MGI R/W anything VIs and see how they they do it. IIRC, the OpenG VIs do this by writing the array size as part of the array name, then basically writing array0=x, array1=y, etc., which I expect is the practical solution for you too.

 

I didn't look closely at this nugget now, but it might also cover the relevant details - http://forums.ni.com/t5/LabVIEW/Nugget-Using-control-references/m-p/570756#M267659


___________________
Try to take over the world!
Message 2 of 7
(5,296 Views)

Thanks, tst

 

I read thru a lot of that.

The built-in \vi.lib\Utility\VariantDataType\GetArrayInfo.vi dosn't seem to work.

It correctly returns the number of dimensions on a 1-D or 2-D array, but always returns their length as 0.

 

The OpenG VArray Size(s) does return the correct length on an array.  Thanks for that tip.

 

I don't see how to make the rest of the OpenG stuff work, though.

 

Yes, I can convert the variant {array of things} into an array of {variant things}, but the result is a variant, and I can't recurse with that to get th labels and values I need.

 

Maybe if I handle the VARIANT type ?

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 7
(5,274 Views)

The OpenG variant config VIs (not the variant VIs, that's a separate lib which is used by it) and the MGI VIs I mentioned both write arbitrary clusters to INI files, and that includes arrays, so you can look at how they do it. I assume it's something along the lines of Variant to Array of VData or something similar, but I'm not too familiar with all the VIs there, because I haven't used them much directly.


___________________
Try to take over the world!
0 Kudos
Message 4 of 7
(5,261 Views)

IIRC, you can do it without using the OpenG tools (which all make a copy of the array data in order to parse the variant - this can be a problem with large arrays).

 

If you set the array control to show only a single element and then set the index, the "Array element" reference will point to the correct cell and you can read out the Value.

 

The problem is that the "ArrayElem" points to ONE OF the visible elements of the array (the last one interacted with by the user), but you can't find out which one.  By forcing the display toa single element, it only has one field to choose from.  Just remember to set the number of visible elements back when you're finished.

0 Kudos
Message 5 of 7
(5,251 Views)

Yes - that seems to work if there's only one element showing.

If that's the case, then setting the INDEX VALUES to the one I want, then getting the ARR ELEM property points to the correct value.

 

I was showing 3 elements in my test and that's why it didn't work.

 

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 7
(5,244 Views)

The array element property refers to the element that most recently had text focus.

Try these.

"If you weren't supposed to push it, it wouldn't be a button."
Download All
0 Kudos
Message 7 of 7
(5,230 Views)