LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulation & Control with local variables

Solved!
Go to solution

Why can I use a local variable in a simulation loop, but not in a simulation sub-VI?

0 Kudos
Message 1 of 6
(3,089 Views)
Because local variables are "local", meaning they only have context "locally" within the VI that they are in.
0 Kudos
Message 2 of 6
(3,081 Views)

So does that mean that local variables don't function in any sub-VI?  Even if they're not used outside of the sub-VI?

 

Also, if local variables are disabled for simulation sub-VIs is the only alternative to use a shared or global variable?

 

Thanks for shedding some light on this.

0 Kudos
Message 3 of 6
(3,066 Views)
Solution
Accepted by topic author pastelesss

The only local variables that will work in a subVI are the ones that refer to controls or indicators that are in the subVI.  If you need to pass data between different subVI's, then you have a few choices.

 

1.  Shared variables, like you said.

2.  Global variables, like you said.

3.  Pass the data in or out through the connector pane of the subVI.

4.  Functional Global Variables/Action engines.

5.  Queues

6.  References to the controls in the main VI so that they are used with property nodes in the subVI

0 Kudos
Message 4 of 6
(3,057 Views)

A little backstory which I should have given when I asked the question. 

 

I have a simulation of an engine and I want to enable/disable the engine clutch.  Since there are conditions on changing the clutch state I was using local variables when I developed the engine simulation in a simulation loop.  After I had fixed the bugs I tried to transfer the contents of the simulation loop into a simulation subVI for use in my main project.  I was unable to transfer the simulator because I had local variables in the engine simulation.

 

I think I understand that I can't use a local variable in a simulation subVI because there's no front panel due to the way a subVI is called.  

 

Thank you for the help in understanding this better.

 

 

0 Kudos
Message 5 of 6
(3,050 Views)

 Hi pasteless , 
Did you find alternative to replicate the variable ( use parameter value without  wiring throughout the vi)  in simulated sub vi ??thanks 

0 Kudos
Message 6 of 6
(2,482 Views)