LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop not looping

I have a semi large vi where a significant portion of it is a while loop.  For some reason the while loop is not looping and I can't find the "stuck" point.  Does anything look obviously wrong to you guys?

0 Kudos
Message 1 of 7
(4,558 Views)

Besides having a block diagram which is way too big?

 

Yes. The inner while loop which contains an event structure will not complete until the full stop button is pressed. Until that while loop stops, the outer loop cannot finish its first iteration.

 

Probably other problems but this one is enough.

 

Lynn

0 Kudos
Message 2 of 7
(4,555 Views)

The source of your problem is your event structure. Your inner loop will not exit the first iteration until you press the stop button.

 

With that said you really nee to think about cleaning your code up. The general rule of thumb is that a block diagram should fit on a single screen. You should also learn how to use data flow better. You can eliminate all of your sequence structures by using data flow.

  • You generally should use two event structures in a single VI to handle your UI events. Use a single event structure. You may also consider using the producer/consumer design pattern to separate your processing code from your UI. Your code will be structured better, easier to maintain and be more flexible.
  • Don't be afraid to use subVIs. It leads to more modular code and better reuse. Quite a bit of your DAQ code can be written as subVIs and reused rather than having copies of the same code littered throughout your block diagram/
  • Please don't run wires from right to left. The general practice is to run them left to right. It makes following your code very difficult when wires are running backwards.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 7
(4,551 Views)

Oh.  The the inner while loop is the one that is not running.  The outer while loop with the "full stop" button is supposed to function that way.  Also, I was really worried about the "way too big" issue, but I'm not really sure how to make it smaller.  The event structure was an attempt to make the giant thing less demanding on the computer. 

0 Kudos
Message 4 of 7
(4,549 Views)

Thanks Mark!  It looks like I'm going to need some massive cleaning.  Would it be okay to remove the event structure and just have the vi poll the front panel?

0 Kudos
Message 5 of 7
(4,547 Views)

The even structure was introduced to eliminate the need for polling! The point is that data flow may require the event structure to be in a parallel loop rather than an inner loop.

 

Lynn

0 Kudos
Message 6 of 7
(4,531 Views)

@DrinkitUp wrote:

Thanks Mark!  It looks like I'm going to need some massive cleaning.  Would it be okay to remove the event structure and just have the vi poll the front panel?


I generally avoid polling loops especially for UI related things. Take a look at the producer/consumer examples that ship with LabVIEW. Better methods for stopping parallel tasks are to use queues, notifiers or user events. Which one you use depends on your particular situation. You may also want to consider having separate parallel loops for your data collection activities. Not sure if you would need a separate loop for each device or if some can share the same loop but as written your execution will be gated by the slowest device. This is because for a loop iteration to complete all the code inside of it must execute to completion. So if your data collection can or should run at different frequencies you will not be able to do that with everything in a single loop.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 7 of 7
(4,528 Views)