LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you manage subVIs with while loops?

I have a LED system worked out as a stand alone VI, but can not integrate it into a higher module. The top level gets stuck waiting on the internal while loops and I cannot run the Top VI properly.

I read some threads about dynamic events, but have no experience with these and am having trouble figuring it out on my own.

Please look at my attached VI (which is the sub-VI in question) and see if it can be recoded without the while loops. Or, if you could show me how to use dynamic events, that would be helpful too.

Thank You.
0 Kudos
Message 1 of 7
(3,630 Views)
What I've done in the past is to have a SubVI that will run in its own WHILE loop, look at a global "Stop" button. This subVI will run outside the main VI's while loop.

When you press "Stop", it'll need to update the global, and thus closing both VIs. I hope that answers your question.

Shan Pin




@Synap wrote:
I have a LED system worked out as a stand alone VI, but can not integrate it into a higher module. The top level gets stuck waiting on the internal while loops and I cannot run the Top VI properly.

I read some threads about dynamic events, but have no experience with these and am having trouble figuring it out on my own.

Please look at my attached VI (which is the sub-VI in question) and see if it can be recoded without the while loops. Or, if you could show me how to use dynamic events, that would be helpful too.

Thank You.


0 Kudos
Message 2 of 7
(3,611 Views)
What version of LabVIEW are you using? If you have access to the event structure that could solve several of your problems. The first loop has no time delay so it will take 100% of your CPU usage. The same is true for your second loop. Your third loop has a 1ms delay, you will need to make that number 1000 to get 1 second delay. An event structure takes care of the polling of the "now" button. Once it is pressed you can execute that code. As far as the dynamic events, those are used in a consumer/producer approach. You basically have two while loops, the dynamic events let you pass infomation from the consumer to the producer. There are some examples of this in LV 7.1. If you open the NI example finder it is under Building User Interfaces->Acquiring User Input->General->Dynamically register for events.vi.
I hope this helps.
0 Kudos
Message 3 of 7
(3,609 Views)
Here is a modification of your VI which will do what I think you were trying to do. It uses a state machine architecture.

Lynn
0 Kudos
Message 4 of 7
(3,582 Views)
Lynn,

Your state machine approach is definately what I orginally had in mind, and I learned how to code state machines better. Thanks! Unfortunatley, I still have the problem of the while loop assuming all control of the upper VI when it is run as a sub VI. Any way to have this run independantly of what is running above it?


I tried experimenting with events, and got something REALLY close to what I want. Check out my new attachment. If anyone can tell me how to have the yellow dot NOT timeout, and still have the green dot timeout, this would be the perfect solution.

I apreciate the effort from everyone who has replied to my original post.
0 Kudos
Message 5 of 7
(3,569 Views)
Check the previous state of "True"'s (yellow'w) visibility. If it was visible before, leave it visible in the Timeout event. Feed the boolean to a shift register in the surrounding while loop.
0 Kudos
Message 6 of 7
(3,553 Views)
It is not clear what you mean by running independently from the the calling VI. If you want independence, the loops must be in parallel, meaning that no data dependency exists between the loops. The user interface (UI) loop runs in one loop. The "calculating" process runs in another loop. Use queues to pass data and commands between the loops without creating dependency. When I say "loop", these sould be loops or subVIs with or without loops. Dependence/independence applies to nodes, which may or may not include a while loop or for loop.

Lynn
0 Kudos
Message 7 of 7
(3,534 Views)