LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving variables

As part of a bigger LabVIEW project, I am making a subVI which is periodically called by the rest of the program. 
How do I make it so that the value of certain varaibles within this subVI can be saved when the VI ends so that I can recover these values (for example a counter) when the subVI is called the next time.
The counter will enable the subVI to know which iteation it is in - how many times it has been called previously.
0 Kudos
Message 1 of 4
(2,565 Views)
There are a couple of ways of doing this.
 
If this is a sub-VI where you will only count the number of times it has been called during the operation of your main VI, then you want a sub-VI that is a functional global variable.  You put the entire sub-VI in a while loop that has a True wired to its conditional stop terminal.  Thus it only executes once when it is called.  You create a shift register that is uninitialized, and increment it by one within the loop.  As long as the sub-VI remains in memory, it keeps track of the value in the shift register.
 
The second way would be to store the values of interest in a file.  Then you break up the sub-VI into 3 steps (a flat sequence structure can help guarantee the execution order.)  In the first step, you read the data file and write the values to the controls or indicators of interest.  In the second step, you do the main work of the VI, perhaps even incrementing the counter by one.  In the third step, you write the values of the controls or indicators back out to the data file.  You would use this structure if you were interested in maintaining the data between runs of the main program as well.
0 Kudos
Message 2 of 4
(2,560 Views)
Here is a practice VI of what I think you are saying.

Do you mean that the subVI "IS" a global variable or the output and inputs to it are global variables ???

In my attempt, the while loop looses the value in the shift register after it is terminated.

I think it may be missing something
Download All
0 Kudos
Message 3 of 4
(2,553 Views)
No.  The subVI is the functional global variable.  It will keep track of how many times it has been called.  It is stored in the shift register.  Because nothing initializes the shift register, it has the default value of zero the first time the VI is called, and once it has been run, maintains the value placed in it from from the previous call.
 
Saved in LV 8.2.
Download All
0 Kudos
Message 4 of 4
(2,546 Views)