From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Case stuck unless timeout wired

Hello,

 

Why do event cases get stuck if there is no value wired to the "timeout" case?  In the vi I've attached, if there's a "-1" wired to timeout, or if I remove the timeout, the vi gets stuck, but if I put a value on the timeout, it wroks fine, but get's stuck for the amount of time in the timeout value... if I put in 5000 it get's stuck... I don't understand why the timeout is required sometimes, even if there's nothing in the timeout case....

 

much thanks!

Message 1 of 15
(5,900 Views)

What you see is normal (and intended) behaviour.

Due to data-flow all the code inside the while loop will run at the same pace.

 

If no event happens, the event structure will wait until the timeout passes (forever if disconnected of -1) and then the while loop can 'spin' once more.

 

You can see this by enabling execution highlighting and using a long (10000) timeout.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 15
(5,894 Views)

Fibo,

 

I am not sure exactly what you mean, but no timeout is necessary.  If you want the VI to be able to respond to all control changes in a timely manner you need to have an event for each of the controls (i.e. since there is no event for "stop", another control has to be actuated in order for the FP to actually stop).  Adding a timeout means that the loop will cycle at whatever rate you put in (i.e. once every 5 s if the timeout is 5 s).  I have reattached your VI with all controls handled by events.

 

Hope this helps.  Peace, Matt

0 Kudos
Message 3 of 15
(5,884 Views)

Hi, thanks for the responses

 

Matt,

 

I'm not sure what you mean that no timeout is neccessary because when I delete the timeout case, my vi gets stuck in the event structure... it's like it never leaves, never goes back to the while loop.  But I know I've workedon other VI's where I could delete the timout case and the VI ran fine without it (unfortunately I don't have any of those VI's any more).

 

I couldn't open your vi... I'm runnin LabVIEW 2009 over here

 

thanks for your help.

 

0 Kudos
Message 4 of 15
(5,882 Views)

You say it "never goes back to the while loop". Is that true when one of your events fires? In the other vi's you have seen are you sure that the event structure was not in it's own loop and what you saw executing was in another loop?

=====================
LabVIEW 2012


0 Kudos
Message 5 of 15
(5,873 Views)

An event structure will wait for at least one event to happen.  If you put an event structure inside a while loop, the loop cannot advance to the next iteration (or stop) until at least one event fires.  The Timeout event is there in case no event happens.  If the timeout event fires, the loop can go onto the next iteration, where it will wait for another event, or the loop can be stopped.  Your vi will hang if you don't have a timeout event, or it is not wired to a number >= 0, and no other event happens.  If you have a stop button event, and you code this to stop the loop, then you might not need the timeout event.  Basic thing to remember is that at least one event must happen for the event structure to complete and for the VI to move on.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 15
(5,855 Views)

What you see is normal behavior. To start a new iteration everything that is inside the while loop must execute. As long as the event structure wait for an event to occur the while loop iteration will not be complete. It will resume as soon as you generate an event (it can be a timeout event if you wire a value different from -1 to the timeout terminal).

 

Note that because of the dataflow programming you can't be sure with your code if the case structure is executed before or after the event structure. The same applies for the stop button. You may have to generate an event before the stop button is read.

 

Ben

0 Kudos
Message 7 of 15
(5,846 Views)

 


@tbob wrote:

If you put an event structure inside a while loop, the loop cannot advance to the next iteration (or stop) until at least one event fires.

 


This applies to events that are actually handeled by the event structure.  For instance, in your VI, you can press the stop button as many times as you want and the loop will not iterate because there are no events that are fired that will be handeled by the structure.

 

0 Kudos
Message 8 of 15
(5,844 Views)

hmmm... ok, can anyone tell me why,in the original VI I posted, if I have a -1 value on the timeout my "momentary" button doesn't seem to count as an event, it doesn't trigger the event structure (my momentary button is updating a "value signaling" property value of a control which is linked to the event staructure) but if I put in a value into timeout like 10, then it works fine and the momentary button triggers the event case....

 

thanks

0 Kudos
Message 9 of 15
(5,823 Views)

You didn't define an event for the momentary button. There was no timeout so the case structure doesn't execute. Therefore your value signaling property doesn't happen either. The case structure executes the very first time through the loop but not again until an event happens. Try it - change the value of the momentary button then click on fault. That fires an event and you will see the case structure execute. Turn on execution highlighting.

=====================
LabVIEW 2012


0 Kudos
Message 10 of 15
(5,809 Views)