12-22-2014 01:53 PM
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?
12-22-2014 01:58 PM - edited 12-22-2014 02:03 PM
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.
12-22-2014 02:00 PM
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.
12-22-2014 02:59 PM
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.
12-22-2014 03:03 PM
Use a Queue. See the Producer/Consumer for a little more information.
12-22-2014 03:15 PM
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.
12-22-2014 09:14 PM
@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?
12-22-2014 09:36 PM
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.
12-22-2014 09:46 PM
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.
12-22-2014 10:21 PM
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.