LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does a subVI retain output (indicator) values between multiple calls?

Solved!
Go to solution

Go back to the original question:

"

This is probably a silly question. But in the back of my mind, I had always assumed this, but I would like confirmation:

 

A subVI will always retain output/indicator values in memory after each call, until LabVIEW is closed.

 

Is this correct?"

 

 

It never asked how the data in the indicator was being accessed.  Mine code wasn't to demonstrate a race condition, it was just to show that the value that existed on output indicator still existed in memory the next time the subVI is called.  The indicator that is being tested in mine is Output Indicator.  The "output before new value" is just a way to show what value was in the output indicator before it got overwritten again.

 

Christian, your VI is changing it up and testing the "in case structure" side of things and is making "outgoing before new value" the indicator you are testing.  It is demonstrating the dangers of having an indicator in a case structure, and is the more important takeaway out of this whole conversation.  But the original question was about is value is still in memory in a indicator after the call.  Mine proves it is.  Though the answer is kind of meaningless because nobody should be using an indicator as a memory storage location.  You've answered the question that the value does not exist in memory after the 2nd call, IF the indicator terminal is not executed, only then does it get reset to default.

 

See below where I show a combination of the question that I see being asked, and also the more important concept you are demonstrating.  It shows that the outgoing value's terminal is retained between calls.  The outgoing value of 10 still exists when the subVI is called again.  But if the terminal is not executed, then that terminal's value is reset to default upon exit.

 

Capture3

 

 

 

 

 

0 Kudos
Message 11 of 16
(1,014 Views)
Solution
Accepted by topic author abvenk

So to wrap up with an answer to the original question:

 

"A subVI will always retain output/indicator values in memory after each call, until LabVIEW is closed.

 

Is this correct?"

The answer would be yes/no, it depends.   Yes, unless the terminal is in a case that does not execute, in that situation the value is lost AFTER that instance of the subVI exits and where it is returned to its default value.

0 Kudos
Message 12 of 16
(1,010 Views)

Wow, thank you all for a good discussion and all the different perspectives.

 

Sorry I can't post my original code. But basically, my subVI is a nested Case structure with a string input that feeds the outermost Case structure. And my indicator is the output that is outside the outermost Case structure. So I have to have a value for every case, including one to handle an empty string input. 

 

So if I call this subVI in a VI that supplies the string input, the subVI executes a specific case and puts a value in the indicator. But if I call this subVI in a VI that doesn't supply a string input, I was hoping to use the indicator value from the previous call. I realized that's not possible, because the indicator gets re-written with the value corresponding to the empty string input case. 

 

So now, I just made my subVI into an FGV with Read/Write option, so I can access the value written when there is a string input supplied. 

 

Maybe there is a situation where the indicator value of the subVI can be reused again even after the second call. 

 

@altenbach: Thanks for pointing out the option to "Clear indicators when called". 

 

0 Kudos
Message 13 of 16
(985 Views)

If you don't want to update a value to an indicator from its previous call, the proper thing to do is use a shift register or a feedback node to retain that value.  Put the indicator terminal outside the case structures.  Feed the new value out in the situations where you do want to,  use the value from the feedback node for those cases that you don't want to change the value.

0 Kudos
Message 14 of 16
(979 Views)

@RavensFan wrote:

So to wrap up with an answer to the original question:

 

"A subVI will always retain output/indicator values in memory after each call, until LabVIEW is closed.

 

Is this correct?"

The answer would be yes/no, it depends.   Yes, unless the terminal is in a case that does not execute, in that situation the value is lost AFTER that instance of the subVI exits and where it is returned to its default value.


AND

 

The sub-VI is not set as "sub-routine"

 

AND

The VI instance on the diagram is NOT marked as "skip If Busy".

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 15 of 16
(977 Views)

@Ben wrote:

@RavensFan wrote:

So to wrap up with an answer to the original question:

 

"A subVI will always retain output/indicator values in memory after each call, until LabVIEW is closed.

 

Is this correct?"

The answer would be yes/no, it depends.   Yes, unless the terminal is in a case that does not execute, in that situation the value is lost AFTER that instance of the subVI exits and where it is returned to its default value.


AND

 

The sub-VI is not set as "sub-routine"

 

AND

The VI instance on the diagram is NOT marked as "skip If Busy".

 

Ben


Or inlined,  and I think that data logging can do some other things that aren't obvious (but, who really plays with that?)


"Should be" isn't "Is" -Jay
0 Kudos
Message 16 of 16
(968 Views)