LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reference a array of clusters from another VI

I have an Array of clusters on a VI that is continously running.

 

I have other vi's I that I would like to Get/Set items in those clusters.  I open a dynamic reference to the front panel, get a link to the reference to the Array Control...  Now what would be the best way to itterate that array and set items it the cluster elements?

 

At this point I only have the refnum to the array control.  When I do Get/Set control invoke methods I get variants back but do not know how to typecast, etc...

0 Kudos
Message 1 of 16
(3,680 Views)

Hi Jboden

 

It is pretty simple, you just need to maintain the data type the same between the two VI's. Remember that LabVIEW needs to know the data type of any wire before running, so you need to specify in the modifying VI what data type is expected.

 

I tried to create an example for you to show how this works see attached (LV2011 format)

 

Best Regards

Anders Rohde

Download All
0 Kudos
Message 2 of 16
(3,662 Views)

Thank you Anders I have 2010 and it will not allow me to open your sample.  Any chance you could save in an earlier version for me?

 

Thanks Jay

0 Kudos
Message 3 of 16
(3,658 Views)

Here is version 8.0

 

 

Tim
GHSP
Download All
0 Kudos
Message 4 of 16
(3,653 Views)

Sorry for some reason that was not working but that is ok.  So you are saying unless I have a strict type def on my referencing vi I will not be able to access the foreign cluster?  I thought I could maybe do something with the variants.

0 Kudos
Message 5 of 16
(3,647 Views)

I don't think I understand what you're asking here.  Get Control Value returns a variant.  You must know the type of data that the variant contains in order to do anything useful with it, but it does not need to be a type definition.  Use the Variant to Data function to get the data out of it.  Set Control Value expects a variant input, but the conversion to a variant happens automatically.

 

Are you saying you know the name of the control that you want to modify, but you do not know what type of data it contains other than that it is an array of clusters?

0 Kudos
Message 6 of 16
(3,641 Views)

What I have is an array of clusters that contain standard LV controls (string, numeric, bool).

 

Then I run another VI that I would like to change values in one of those items in one of the clusters in the array.

 

I was hoping to set/get items from the array of clusters just by passing an array index then the name of the cluster item. 

 

Then if I change the cluster that is in the array on my main vi I would not need to change my callilng vi except for the text I pass to it that refers to a control in the clusters.

 

I think I need to always have a version of the main cluster on my calling vi to convert the variant I get from the call to Controls[].Value to convert to Cluster.

0 Kudos
Message 7 of 16
(3,639 Views)

Without knowing anything about your code... have you considered some other sort of messaging architecture instead of directly setting front-panel values?  For example, you might be able to use a queue, notifier, or user event, possibly in conjunction with VI server if necessary, that sends an event to the main program saying "update this array index with this specific value."  That's likely to be more reliable and helps avoid race conditions.  With your proposed setup, you have to set all elements in the array.  What happens if you read the array, modify one element of it, then write it back out at the same time as the user modifies some other element of the array?  The user's changes, or your programmatic ones, may get wiped out depending on the exact timing.

0 Kudos
Message 8 of 16
(3,634 Views)

I am pretty concerned about the race condition.  Because both the main and my referencing vi are updating the entire array.  I think I will persue using the que.  Do you see that as the best way to pass data between two running vis?

 

In my code I have one VI running all of the time monitoring and controlling 3 AC Drives.  From another vi I would just like to change rpm, enable, and other properties which are included in the array off clusters I am using.

0 Kudos
Message 9 of 16
(3,630 Views)

A queue is almost definitely the best way to do this.  I've seen very few uses for Get/Set Control Value while the target VI is running.  It is sometimes used to set the value of a control before launching a VI dynamically - for example, to set the value of a queue reference control to an actual queue, so that after that VI starts it can use that queue for communication.

 

I wonder about your architecture overall.  Is there some reason to make these two separate, independent VIs?  Perhaps one of them should be a subVI of the other?

0 Kudos
Message 10 of 16
(3,621 Views)