LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SubVI array build in main VI

I have a subVI that contains a for loop. Each iteration produces a single data point. I would like to build an array of this data and plot to a graph or chart in the main VI (outside of the subVI). What is the best way to do this?

0 Kudos
Message 1 of 10
(3,682 Views)

Right click the wire where it exits the FOR loop and select "Index results", this will create an array of the points, right click on the wire and create an indicator.

On the subvi front panel you should then connect the connectors in the top right, then feed this connector output into a chart indicator on your main vi and you should be done.

 

This is pretty simple stuff and should have been covered in any tutorials or lessons that you have looked at. Look into the LabView basics to see more about this.

0 Kudos
Message 2 of 10
(3,677 Views)

First, I'll say that this is very basic so make sure you take the time to go through the online training course material.

 

Use the auto-index output of the for-loop to create the array.

Wire the array to an array indicator.

Connect the indicator to a terminal of the subvi.

0 Kudos
Message 3 of 10
(3,675 Views)

Sorry I'm not sure the wording was quite right in my question. The basic setup is a subVI that contains a for loop (which needs to remain in the SubVI) and produces a point every iteration . The goal is to have the main VI plot or build an array of these points as the subvi is iterating, not afterwards. I can build the array and feed it to the main VI via a terminal (this is not the issue) but I can't get the main via to update until the subVI is finished with all of its iterations.  I think a global variable may work but I haven't been able to implement it correctly for my purposes.

0 Kudos
Message 4 of 10
(3,655 Views)

Use a Queue.  See the Producer/Consumer for a little more information.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(3,649 Views)

A global variable is not the way to go here, If you can pass a reference for the chart into the subvi and then use a property node to write the value of the chart you should be able to do what you want. You will have to use another method to build the vi, as you will not be able to pass the array out until the very end if you use an autoindexing tunnel.

Message 6 of 10
(3,640 Views)

@ogk.nz wrote:

A global variable is not the way to go here, If you can pass a reference for the chart into the subvi and then use a property node to write the value of the chart you should be able to do what you want. You will have to use another method to build the vi, as you will not be able to pass the array out until the very end if you use an autoindexing tunnel.


You're right about the global being the wrong way to go here.  Global variables are going to create a mess with timing the two loops to avoid race conditions.

 

But, why would you pass the reference rather than use the queues crossrulz suggested?  Queues are meant to pass data between loops.  Your way works, but it's a lot like building a while loop meant to run a specific number of iterations.  There's already a tool for that.  Why re-invent the wheel?

0 Kudos
Message 7 of 10
(3,606 Views)

From my understanding of the description, there is only a single loop being used to run everything, so in this case using a queuse is not going to help anymore then simply passing the data out as youll be able to enqueue the data but it wont be dequeued until exiting the subvi. If the whole program is going to be redesigned into a producer consumer then that would be preferable but my method is able to be slotted into the existing program without needing to redesign the complete program. 

Message 8 of 10
(3,597 Views)

Well, if we are going into an ideal world, I would have a single loop with nothing but an Event Structure in it.  Its sole purpose is GUI.  I handles button presses, string value changes, etc.  Any changes would be communicated to whoever needs it via a queue, notifier, or global variable (totally dependent on the nature of the data).  But I would also use a User Event to send data to that loop to update the GUI as well.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 10
(3,588 Views)

Hi Joseph - 

 

One option would be to update the graph/chart after each iteration of the subVI, using shift registers and a FOR or WHILE loop in the main.

 

The shift registers will keep the last array of data sent to the front panel. This array will then get updated with each new data point and then sent to the graph/chart. See attached screenshot.

 

Note: my example dosen't include the array 'update'. This'll depend on how you wire up your subVI.

0 Kudos
Message 10 of 10
(3,576 Views)