LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structures and Do /While Loops

I have an Event Structure inside a Do/While Loop.  One of the buttons in the event is STOP which stops the do while.  The Stop Button itself is inside the event as suggested in the help.  My problem is when I hit the stop button everything inside the Do/While runs 1 more time.  Other than than the code works perfectly.  is this normal behavior for a Do/While ..Event Structure??

0 Kudos
Message 1 of 11
(3,902 Views)

That's not standard behaviour. It sounds like a race condition or you're reading the value in a bad place. Do you have the Stop control in the Stop:Value Change-event?

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 11
(3,896 Views)

All my buttons for each event are in their corresponding event structure and all are set to value change.  Any troubleshooting suggestions??  Can you TS a race condition?? 

0 Kudos
Message 3 of 11
(3,894 Views)

It might help if you could show us a snapshot of your block diagram.

 

In summary though, can you confirm your Stop button handling architecture looks something like this:

event.png

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 4 of 11
(3,889 Views)

 

The attached file is the code in a nutshell.  I know it can sometimes be diffcult to TS w/o the actual code.  Prob is I wrote it in LV2011 on the Lab PC and I have LV2010 at my desk.  I don't have internet access in the Lab..of course.

If I hit the OK button 2x's it "does something...does something...build array" then again a second time.  The build array is added to with each click of a button in the event structure.  If the user hits the STOP it dumps the 2x's worth of data out to excel..except I get 3 rows of data rather than 2...as if the inner loop ran one more time.

Anyways. the only thing that caught my eye is the fact that I don't have a sequence structure around the "build data here" portion of the code.  Would that affect how the STOP inside the do while loop is handled??

 

 

 

 

 

0 Kudos
Message 5 of 11
(3,881 Views)

Mark,


According to your code, and ignoring the fact that the outer while loop is pointless (it can only run once, so why have it?), I can see that due flat sequence structure is forcing the "Do Something" elements to occur after the event structure. Therefore, when the Stop button is pressed, the event structure completes with some True values for the while loop conditional terminals, and then the subsequent frames of the sequence will execute (although from this code it would make no difference to the output array size).

 

If you need the code to exit without performing more work when the user presses Stop, put the Event structure in the last frame of the flat sequence structure.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 6 of 11
(3,877 Views)

Thanks..I'll give that a shot.

0 Kudos
Message 7 of 11
(3,859 Views)

Here's another option.

 

Check out the Producer/Consumer design pattern.

 

Attached is a modified version of the "Producer/Consumer Design Pattern (Events)" template vi (LV2010).

 

It's fairly easy to modify for your specific needs.

 

steve

 

 

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 8 of 11
(3,813 Views)

i agree with Thoric...

removing the event from your sequence structure will help i feel...

LV 8.0, 8.6, 2011,2012,2013 WinXP
0 Kudos
Message 9 of 11
(3,804 Views)

Thanks for taking the time to do that..  I started to look at consumer/producer..Someone had mention queuing.

0 Kudos
Message 10 of 11
(3,784 Views)