From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array element references confusing me

Solved!
Go to solution

So.... I'm trying to play around with references to arrays, specifically references to elements within an array.

It looks like I should be able to just read the value of the array, but because of how I am trying to link LabVIEW & TestStand I am trying to create a utility that will automatically get data back and forth between LV adn TS, where the data types being passed back and forth are completely unknown, and possibly arrays of clusters which have nested arrays of clusters. 

So I am trying to walk the LV data structure and go reference into TestStand and get the right data.  However, I can't seem to be able to use references to point to specific elements of an array -- see example that I would expect both the top and bottom code to work the same, but they don't.

 

Any suggestions on what I am doing wrong to get the top and bottom to work the same?

 

arrayreferences.jpg

 

LV2011 code attached

 

 

0 Kudos
Message 1 of 6
(3,995 Views)

The array element property node gives you a reference to the element that makes up the array.  So if you need to set the properties of a numeric control perhaps to change color, or display format.

 

It is not a way to get or set the value of a particular array element.  To set a particular array element, you need to use Replace Array Subset.  To get the value of a particular array element, you use index array.

 

The indexvalues property node is used to determine what is the first element that is displayed.  It changes the value of the indexer to the upper left of the array.

 

One thing I noticed that I don't know if I knew before was that setting the value property node on the array element reference, will affect the first visible array element.  If you turn on highlight execution and play with the array index while it is running, you'll see the resulting array will be different.

0 Kudos
Message 2 of 6
(3,982 Views)

I can tell you what *is* happening, though I haven't used references enough to know why.

 

1st, in the last for loop you're multiplying the iteration terminal by itself, not building an array.  You will get the values 0, 1,4,9,16 in your 5 iterations.

2nd, your element references are all pointing to the same element.  The 1st loop on the bottom is setting the reference to a certain element, which when it exits is the 5th.  It appears that Index Values relates back to ArrElem.  I bet if you slow down the last loop you'll see the 5th element go through the number set above.


--Using LV8.2, 8.6, 2009, 2012--
0 Kudos
Message 3 of 6
(3,981 Views)
Solution
Accepted by topic author warren_scott

@Ravens Fan wrote:

The array element property node gives you a reference to the element that makes up the array.  So if you need to set the properties of a numeric control perhaps to change color, or display format.

 

It is not a way to get or set the value of a particular array element.  To set a particular array element, you need to use Replace Array Subset.  To get the value of a particular array element, you use index array.

 

The indexvalues property node is used to determine what is the first element that is displayed.  It changes the value of the indexer to the upper left of the array.

 

One thing I noticed that I don't know if I knew before was that setting the value property node on the array element reference, will affect the first visible array element.  If you turn on highlight execution and play with the array index while it is running, you'll see the resulting array will be different.


 

Although it IS possible, you may not want to do it after you see what is required.

 

We can get teh value of an array element that is in a control or indicator provided it it the top left element displayed.

 

This Nugget exploits this fact and demonstated how it can be done. Note: I have not tested that code lately so I do NOT know if NI has broken that behaviour since the writting of that nugget.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 6
(3,972 Views)

Sweet!!!

That nugget is DARN CLOSE to what I am trying to do, and with a few tweaks it should be just dandy.

 

Thanks

0 Kudos
Message 5 of 6
(3,964 Views)

Test it first!

 

It seems few people know how to do that and therefor is NOT part of NI's normal bug testing routine so....

 

Test it First!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 6
(3,958 Views)