LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically referencing array elements

Hello to all LV experts!
I am trying to build a general VI that accepts some control's refnum and returns all child references programmatically.
I managed to deal with all the LV objects I wanted except of arrays.
To clarify my intention I've attached an example that extracts child references out of a cluster reference.
 
From an array refnum I managed to get a reference to one of its elements by the 'Array Element' property node, but I did not find a way to programmaticallyspecify the desired index.
What I did manage to do is the attached VI, which can give the impression that it does the work, but clicking any of the array's elements except the first one adds an index distortion which I did not manage to identify programmatically.
 
Any idea how to solve this?
0 Kudos
Message 1 of 21
(6,072 Views)
uups, lost an attachement...
0 Kudos
Message 2 of 21
(6,064 Views)
I can't look at your VI, but in general, even if there is a seperate reference to each element (which I'm not sure there is) there is no real point in getting it, because all array elements (unlike cluster elements) have the exact same properties. You can set the properties for a single element and the value for the entire array.
 
Besides, what do you mean by "child references" and "all the LV objects I wanted"? How many objects (other than tab controls and clusters) have accessible embedded objects?

___________________
Try to take over the world!
0 Kudos
Message 3 of 21
(6,048 Views)

Hi tst and congratulations!!! I am honored to here from you Smiley Happy

I've attached an LV7.0 version of the VI so it might solve your problem in watching it, if if that doesn't do, there in also a bitmap image of its block diagram.

I am only interested in changing/reading the 'Value' and the 'Value (signaling)' properties, which are available seperately for each element of the array (look into the example VI)

By "child refereces" I am refering to refnums of objects in the lower hierarchy of sum contol (like the ones derived from the 'Controls[]' property in relation to a cluster object - as I showed in the bitmat example at the 2nd coresspondance)

The hierarchy objects I am refering to are VIs, Panels, Tabs, Pages, Clusters and of course Arrays...

Mel

 

 

0 Kudos
Message 4 of 21
(6,041 Views)

I see what you're saying, there is something weird when you write to a specific element using the Value property, but I still don't get the point - if you want to get the value of an array element, use Index Array. If you want to set the value of an array element with signaling, use Replace Array Subset and write the entire data back to the array using the array's value property. If you just want to change the value without signaling, use a local variable. Why do you feel that you must do it by manipulating each array element individually by reference?

Also, I couldn't find any Controls[] property for a subpanel (other than that of the VI) and since tabs and pages are basically the same things, it means you basically only have tabs and clusters as containers with internal objects (I consider front panels obvious).


___________________
Try to take over the world!
0 Kudos
Message 5 of 21
(6,038 Views)
Let me explain the implementation it is ment for:
I want to have the capability to read/write into a remote VI's controls, based on a string identifier which holds a "path" to the required control.
This way, I can generate a sort of control->value mapping table which is solely based on strings, therefore the table itself can be written in any simple editor (I use excel), and it is highly robust :
  •  I can add to an existing implementation any new LV application, without compiling anything in my master application - the link is done solely by the Excel table!
  • If I need to change the control structure of some independant  GUI that is already integrated in the system, I don't need to worry about changes in its interface, again - every such issue can be solved by the mapping table. 

I have already implemented such a system and it is working great! as long as I don't need to programmatically interact with array elements on the remote GUI...

 

0 Kudos
Message 6 of 21
(6,035 Views)

How about using the VI class method Set Control Value or its variant sibling?

That's basically what's it there for - to allow you to open a connection to a remote VI and set a control's value by name. It's true that this way you will have to do some more manipulation if you are dealing with an array (read it and write back), which is prone to race conditions, but I don't think writing to a specific element will prevent that either.

Another thing you may want to consider for such applications is dynamic loading of VIs using VI server methods. You can search for "plug ins" or "VI loader" to find some more details on this. Also, I think chapter 17 of the user manual deals with the programmatic control over other VIs.


___________________
Try to take over the world!
0 Kudos
Message 7 of 21
(6,033 Views)
You can't get a reference to SPECIFIC array elements, only to the array itself.  There is a reference "Array element", but there is only one, not one for each element present.

If you write a value to an array element reference the value updated in the array will be the value at the current array index.  So, in order to be able to do what you want, you need the "Array element" reference (The exact same reference can be used for ALL elements) and a reference to the array itself.  Set the index of the array to the required element, and then set the value.  Voila.

Bit of a kludge, but it works.

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 8 of 21
(6,017 Views)
Actually, Shane, it doesn't work and I think that's what malosh was refering to by "index distortion".
 
For example, I created (7.0) an array with 8 elements, where each element corresponded to the index (0..7). Then, I created a property node with IndexVals and ArrElem.Value (in that order). I wired 3 into the index values and a number into the value and what happened was that the index jumped to index 3 and that the number replaced not #3, but #10, which didn't exist up until then.
 
Note that 10 is exactly 7 places off from 3, just like 7 (the original size of the array) was 7 places from 0.
 
From this point on, every number you feed replaces an element that's 7 elements higher. It looks like it remembers the original size of the array and that affects it somehow.
 
However, if you use a smaller control to display the array (less than 8 elements) it will replace the last element visible in the control, even if it isn't 7 places down. I'm guessing you only displayed 1 element in your array, which is why it worked fine.
 
In any case, the system malosh describes sounds interesting, but potentially exposed to race conditions. What happens if you try to change something at the same time the program does?

___________________
Try to take over the world!
0 Kudos
Message 9 of 21
(6,014 Views)
True,  if you draw the array out to display more than one element, things get ugly.  For this reason (and others) I almost always leave the arrays showing only a single element.  Then it works just as I described.

I really wish there WAS a simple way to select a given element of the array.  That would save all this messing about.

Shane.

PS  The element which is written is defined by the element which currently has (or last had) key focus (and the index value for the array of course).  If you set the first array element to have key focus, it should work as advertised.  Try it out.  Is there a way to programatically set key focus to the first element?

Message Edited by shoneill on 08-29-2005 11:43 AM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 10 of 21
(6,010 Views)