LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Force the event structure to run once and wait

I need to basically allow the (only) event case to run once with a default value and then wait for any changes of that value on the front panel to run the computation again. I can't think of any way to do this. Any suggestion? Thanks
0 Kudos
Message 1 of 8
(6,106 Views)
Since you are not using the timeout event, add the "timeout event" to your current event case.

Now add a shift register to the while loop surrounding the event structure. Initialize it with "0" and feed it to the timeout terminal of the event case. On the right side, feed a -1 to the shift register.

The event will immediately execute the first time (because of zero timeout!) but the will no longer do so (because if infinite timeout!) and from now on the event will only react to your "value changed" event.

Alternatively, you can also fire a signaling event for your control using the desired default value(LabVIEW 7.0 and later only, I think).

(The attached image shows both methods.)
Message 2 of 8
(6,102 Views)
Thank you so much for your help. I just experimented it with a simple vi and it worked the way I wanted. 🙂 thanks again.
Message 3 of 8
(6,097 Views)
I just realised such method will force the code to execute at least once but if I add a Stop button and add "value change" of this stop button as another event it will execute once again when I want to stop it.

Basically how do I force a simple event structure (with only one event) to runonce, and when stop button is pressed, it will stop without having to run the vi again cos it is redundant process.
0 Kudos
Message 4 of 8
(6,063 Views)
An event structure (as the name suggests) is supposed to run code when a certain event occures. If you only want to run this code and you only want to run it once when the program starts, there's no need for an event structure. Just place it at the beginning of your program. If you want to force it to run force, you can place it in the first frame of a sequence structure and the rest of the code in the other frame. If you do want to run it more than once, you can use a dynamic event to fire it or use Altenbach's suggestion but place a case around the code and run it only when i=0.
Actually, I'm surprised your timeout case runs after your stop case. Is the stop condition for the loop coming out of the event case? If it isn't, it should. use a T\F constant and put one in the stop case with a T. This way, the loop should stop immediatley after running the stop case.

___________________
Try to take over the world!
Message 5 of 8
(6,044 Views)
I wrote a simple vi to better explain my situation.

The vi basically computes additions of 2 numerics. I've given the numerics default values so that when I run the vi, it will compute once with these default values and then wait for any changes in the values. When the values change the event structure will run again to compute the new total. And finally when I am done, the stop button will be able to stop the vi without running the addition of numbers again.

The problem with this vi are:
1. it is forced to run once but since the event structure doees not register the "value change" in the either of the numerics (nor teh stop button) at first run, it won't compute the addition.
2. when the stop button is pressed, the vi will run again which is unecessary since the numeric obviously hasn't change since the last computation after a "value change" in one of the numeric.
Message 6 of 8
(6,036 Views)
I just spotted my mistake. The problem 1 is described was due to a mistake I made in the vi. So please ignore it. Problem 2 still trying to figure a solution. My apologies.
Message 7 of 8
(6,029 Views)
Sorry to have posted so many triple or double posts lately. I should've gone through my problems more thoroughly before I post them. I just solve this problem. The problem wasnt' really any difficult ones cos I just need to create another event for the stop button instead of putting it in the same event as the numerics. And I just recalled why I had such a tough time trying to solve this supposed problem of mine. I actually wanted to pass the result (in this case the addition value) out of the event structure and while loop and I found out this could be done easily with a property node.
Message 8 of 8
(6,027 Views)