LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Updating data outside a foor loop

I hope someone can help me with the following problem. I collect data into an array with a for loop. The data is visualized in an intensity graph. All this works fine. I would like to update the graph line by line as the for loop runs. I managed this too but only if the graphing is done in the same VI as the for loop. This I would like to avoid as the program is already rather complex and it is difficult to keep track of all the things. I therefore made the for loop data acquisition into a subVI but now the updating doesn't seem to work. My question is, is it possible to update data outside a for loop when the loop and the data are in different VIs.

Klas
Message 1 of 10
(3,991 Views)
Hi Klas,

If you pass a reference of your intensity graph to you sub-vi, you can then update you graph within your for loop as required.

Regards
Ray Farmer
Regards
Ray Farmer
Message 2 of 10
(3,987 Views)
I'm relatively and I'm not familiar how to do this. Is there some example or tutorial available on this? I'm using LabView 7 on WinXP.

Klas
0 Kudos
Message 3 of 10
(3,965 Views)
Another approach (often multiple ways to solve a problem exist) is to use parallel loops. Put the data acquisition into one loop and the display into the other. If no data dependency exists between the loops and both have a wait function inside, they will effectively execute in parallel. The data can be passed from the DAQ loop to the GUI loop via queues or functional globals.

One reason that your graph does not update with the subVI may be that the subVI is running continuously and the data does not become available until it completes.

One of the features of LV which seems to baffle new users is the dataflow paradigm. This simply means that the order of execution of any node in the diagram is not specified by its position in the diagram but by whether all of its inputs have data available.

Lynn
0 Kudos
Message 4 of 10
(3,936 Views)
Hello,

If you want to try the first approach, take a look at the attached example.
Launch the GUI vi, the generate will then generate data and it will be displayed in the other one.

Hope it helps,
Paulo
0 Kudos
Message 5 of 10
(3,925 Views)
Hi,

Thanks for the example. Unfortunately my version of LabView (7.0) doesn't seem to be able to open it. Is it made with a newer version?

Klas
0 Kudos
Message 6 of 10
(3,917 Views)
You could also pass data between the vis using queues. Do a search for queue in the NI example finder for basics on using queues.
0 Kudos
Message 7 of 10
(3,915 Views)
Hi,

Here it is in version 7.0.

Hope it helps,
Paulo
Message 8 of 10
(3,913 Views)
Thanks a lot! Great help. I got my problem solved but now that I have learned about using references I started to wonder whether I can use the same approach to control subVIs. For example, would it be possible (and the correct approach) to stop loops running in subVIs this way?

Klas
0 Kudos
Message 9 of 10
(3,888 Views)
Hi

It is a good way, doing it like that.
There are also other ways. And the easiest one, that people tend to use imediately are the global variables.
If you can, avoid using them - when you use them a lot, sooner or later you end up in having problems (it is very difficult to control the data flow of your program like that). A good way of doing it is using the so called LV2 globals.
It is called like that beacause it was introduced in version 2 of LabVIEW- it consists of a subvi with a while loop with a non-initialised shift register. Because it is in this situation, it keeps the value of the last time it ran and even has the advantage that you can even place some code in the variable like this (like a case structure to read and write the value). The biggest advantage is that you can control the flow of the program - beacause the vi cannot run concurrentely.
Take a look at the following example:

Hope it helps,
Paulo
0 Kudos
Message 10 of 10
(3,865 Views)