NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Member
jboden
Posts: 17
0 Kudos

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...

Active Participant
A.Rohde
Posts: 503
0 Kudos

Re: Reference a array of clusters from another VI

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

Member
jboden
Posts: 17
0 Kudos

Re: Reference a array of clusters from another VI

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

Trusted Enthusiast
aeastet
Posts: 2,199
0 Kudos

Re: Reference a array of clusters from another VI

Here is version 8.0

 

 

Tim
Johnson Controls
Holland Michigan
Member
jboden
Posts: 17
0 Kudos

Re: Reference a array of clusters from another VI

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.

Trusted Enthusiast
nathand
Posts: 3,881
0 Kudos

Re: Reference a array of clusters from another VI

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?

Member
jboden
Posts: 17
0 Kudos

Re: Reference a array of clusters from another VI

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.

Trusted Enthusiast
nathand
Posts: 3,881
0 Kudos

Re: Reference a array of clusters from another VI

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.

Member
jboden
Posts: 17
0 Kudos

Re: Reference a array of clusters from another VI

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.

Trusted Enthusiast
nathand
Posts: 3,881
0 Kudos

Re: Reference a array of clusters from another VI

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?