From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

"Wait" function ?

Hello, and thanks for any help you can provide.

 

I want to make a code where the user type a number (like 1, 2, 3 etc) on a numeric control and presses enter, then it turns on a serie of different events depending on the number he typed. That's easy with an events structure with LEDs for demo (cf. my code) but I want the code to wait 1 second between each operation. (By example the user press 1 on the numeric control and presses enter, then it triggers one operation, 1 second after a second operation is triggered, etc.

 

Operation 1 works but I don't understand how you wait x seconds to trigger another operation

 

I tried to do a case structure with a "time elapse" function but it does not work. It does not look elegant to have a case structure with a "time elapsed" function in it every time I want to wait x seconds. Is there a better way ?

 

So in my code, when the user press 1 and enter, it should turn on the LED 1, then after 1 second it should turn on the LED 2

 

0 Kudos
Message 1 of 6
(1,877 Views)

Your big loop cannot iterate unless everything in it has completed. The elapsed time express VI just tells you if the time has elapsed whenever it is called, but it cannot be called repeatedly because the event structure is blocking the loop.

 

We also have the wait function in the timing palette.

 

This is all basic dataflow principles. did you do some of the beginner tutorials listed on the top of the forum?

 

 

See how far you get.

0 Kudos
Message 2 of 6
(1,849 Views)

I don't think you quite understand how Event Structures work, and might not really "get" the Principle of Data Flow, upon which LabVIEW is built.  I'm also not 100% certain I understand what you want to do!

 

Generally, Event Structures run in their own "While" Loops.  Also, it is common practice to put Controls whose Value Changed? property is being tested inside the corresponding Event Case (this is particularly true for the rectangular "Latching" Boolean Controls).

 

Since you are running LabVIEW 2020, check out the Stall Data Flow VI in the Timing Palette.  This is a nice way to put a "1000 msec delay" (= 1 sec) on any wire.  Combining the ideas of these two paragraphs together, here's a Snippet with a (very) simple Event Loop (there's a Stop Event, but there aren't (yet) events for the Numeric to take on 2 or 3, and no provision for turning off any booleans, exercise for the reader ...).

Simple Event Loop.png

 

Bob Schor

  

 

 

0 Kudos
Message 3 of 6
(1,843 Views)

Thanks so much ! Yeah I am a bit a newbie I am sorry for that,

 

I never used Event Structure. I want to do a code that can run for ever, where the user types a number and press "enter", and every time he does this, it triggers the related operation.

 

What is wrong with a While Loop running for ever, and a event structures made of different cases for each event (corresponding to each number the user type) ?

 

 

0 Kudos
Message 4 of 6
(1,773 Views)

I will try like this, thanks

0 Kudos
Message 5 of 6
(1,765 Views)

@Oxbow8 wrote:

I never used Event Structure. I want to do a code that can run for ever, where the user types a number and press "enter", and every time he does this, it triggers the related operation.

 

What is wrong with a While Loop running for ever, and a event structures made of different cases for each event (corresponding to each number the user type) ?

 

 


A while loop will run forever (or until stopped), but if there is an event structure, the event structure dictates the iterations.

 

Can we go back to the original and define your problem and try to understand what you are trying to do. 

 

Does each entered number trigger a "series of events" or only one specific event? How does the result depend ion the entered number? Does the entered number dictate how many times the LED should turn on (at 1Hz)? What is an "Operation"?

There is no LED names "LED 2". What should happen if the user enters a second number before the 1 second has elapsed?

 

Also: You need an event for the stop button. Your numeric input should probably be an integer, unless you allow entering fractional values (equal comparisons are dangerous with DBL!) Never delete the labels of controls, you can hide it on the front panel if needed, but labels should always show in the diagram. Look at your event structure! Imagine you have 20 unlabeled controls and 20 events with ["":value change], all triggered by something different!. The terminal belongs inside the event, else it gets read before the event fires and the wire will have a stale value.

 

Attached is a quick code skeleton that probably does not do what you want, but might give you some ideas.

0 Kudos
Message 6 of 6
(1,754 Views)