LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop inside a event structure

Dear
 
I have no much concepts on event structure.
 
Let's assume there is a dialog box with Okay and Cancel button.
 
I put the event structure for Okay and Cancel button.
 
In Okay event, there is a while loop for detecting some data continuously.
 
In this case, I want to use Cancel button to stop the while loop during the detection.
 
How can I do to receive signal from the Cancel button?
 
Thank you in advance.
0 Kudos
Message 1 of 5
(7,655 Views)
I'm not sure that the event structure should be used to handle that situation : while the OK event is executing, either the Front panel is locked and new occuring event will be stored until the OK event is completed (so the Cancel button action will not be detected !) or the Front panel is unlocked (see below *) and the Cancel button action will stop the loop, but the Cancel button event case will not be executed, since the event has already been processed in the OK case !
You should probably use a single button to run/stop the loop, as shown in the attachment

* While editing the event case, unmark the "Lock front panel for this event complete" at the bottom. But of course, the code in the cancel case will not run, since the event occured

Message Edité par chilly charly le 03-31-2007 05:27 PM

Chilly Charly    (aka CC)
Message 2 of 5
(7,643 Views)
I suggest you follow a simple rule:

ALWAYS make the event structure code as FAST as possible.

Never put a wait-on-the-user function inside an event handler.

For one thing, the front panel is usually locked while an event is being processed.

For another, it confuses the logic of your program.

Use two threads, running simultaneously. Here's one thought:


Ref = Generate Occurrence

LOOP1:
Repeat  {WHILE loop }
  Wait on Occurrence (Ref, Timeout = 100 mSec)
  if Timed Out
    Read data
    Store data
    Graph data
    Analyze data
until not Timed Out

LOOP 2:   { in parallel with loop 1 }
Repeat  {WHILE loop }
  case EVENT of
  Stop Button:
    Trigger Occurrence (Ref)
  Other button:
    Do something else
until Stopped
The first loop uses the WAIT ON OCCURRENCE as a timer - if the occurrence is actually fired, that's a signal to quit.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 3 of 5
(7,641 Views)
Dear CoastalMaineBird,
 
Thank you very much for my questions (this & DS),
 
Would you please give me your example code for your reply?
 
I need to know how to realize your reply.
 
Thank you again.
0 Kudos
Message 4 of 5
(7,607 Views)
Dear CoastalMaineBird
 
 
Would you please give me your recommendation?
0 Kudos
Message 5 of 5
(7,576 Views)