Spetz Posted October 25, 2015 Report Share Posted October 25, 2015 Hello all, i'm just starting out so any help is appreciated. Two question "1" is general and "2" is specific. 1. When an event structure is in a while loop the while loop only iterates when the event occurs. What is the reasoning behind this and why can't a single while loop contain other code that gets polled or executed with every iteration? 2. I'm having issues with the attached code. Two main issues that i don't quite understand. I'm trying to have make a code that will do several things on the front panel at particular time intervals. I would like it to throw up a message to the user and also enable and disable some controls. While all of this is happening i will be collecting data and doing some PID control on the some IOs. The full code is not attached but basically my plan is this. One loop for PID and DAQ functions. Loop 2 for event structures such as messaging and enabling and disabling controls etc.... Loop 3 for timing of the user input. What i'm having trouble with is loop 2 and 3 which is what's in the attached in the simplified form. a. When button1 is pressed and action is set to "switch until released" my message 1 appears twice. This makes sense as the button switches from F to T to F. How do i get the even to trigger only one time on the press of the button if i want the button to be momentary? I can get this to work when i switch the action to "latch" which makes sense because it changes state once per click?!?! Also when i connect an LED to that button the LED never goes off once it's turned on, whats the explanation here? b. The biggest mystery to me is the timing in Loop 3. I'm using the "time has elapsed" output of the elapsed time VI to trigger the event and pop up message 2. If this was working correctly i suspect that the message would pop-up twice as this goes from F to T to F. But the event is triggered continually and i'm not sure why? Based on the indicator it should only trigger once every 10seconds not every loop iteration. Also there is an element of question "a" here when this is working correctly how do I trigger only one event based on the FTF output of elapsed time? What is the proper way of programming this and what am i doing wrong/missing? Appreciate any help or guidance. Event_timer.vi Quote Link to comment
drjdpowell Posted October 25, 2015 Report Share Posted October 25, 2015 Re 1) The Event Structure has a Timeout, which you can set to zero if you want. Re 2a) Use a Case Structure to do things only on True. Re 2b) the “Value Changed†event is somewhat misnamed as it really is a “new value†event; there is no filtering out of where the new value is the same as the old value. The Event has the old value as well as new value so you could do this yourself, but a far better solution would be using a case structure and only trigger an event on True. Quote Link to comment
JKSH Posted October 25, 2015 Report Share Posted October 25, 2015 (edited) 1. When an event structure is in a while loop the while loop only iterates when the event occurs. What is the reasoning behind this That's the defining feature of an Event Loop: The loop only iterates when there's an event to handle. When there are no events of interest, the loop sleeps to conserve CPU cycles. why can't a single while loop contain other code that gets polled or executed with every iteration? As drdjpowell explained, you can. Just input a loop period into the event structure's Timeout terminal. (Note: This means you won't have an Event Loop, but a hybrid event + polling loop instead.) Edited October 25, 2015 by JKSH Quote Link to comment
Spetz Posted October 25, 2015 Author Report Share Posted October 25, 2015 Re 1) The Event Structure has a Timeout, which you can set to zero if you want. Re 2a) Use a Case Structure to do things only on True. Re 2b) the “Value Changed†event is somewhat misnamed as it really is a “new value†event; there is no filtering out of where the new value is the same as the old value. The Event has the old value as well as new value so you could do this yourself, but a far better solution would be using a case structure and only trigger an event on True. Hi Thanks for the reply. I'm not sure i understand your point 2a. completely. Where does the case structure go? Does that end up inside event loop and inside the event case to actually trigger the message? Quote Link to comment
drjdpowell Posted October 25, 2015 Report Share Posted October 25, 2015 Hi Thanks for the reply. I'm not sure i understand your point 2a. completely. Where does the case structure go? Does that end up inside event loop and inside the event case to actually trigger the message? Yes, inside the event case. Show your dialog only on events where the button goes True. Quote Link to comment
Spetz Posted October 25, 2015 Author Report Share Posted October 25, 2015 Ok great thanks this does seem to work. However i see the event loop is still iterating so doesn't this negate the point of the event loop and the computing benefits of not polling that loop every time? Is there a better way to achieve what i'm trying to do? Is there documentation on how to use the old and new value? Quote Link to comment
MikaelH Posted October 25, 2015 Report Share Posted October 25, 2015 Even if you wire False to a Value Signal Property Node, it will still cause a value Change event. Quote Link to comment
Spetz Posted October 25, 2015 Author Report Share Posted October 25, 2015 Ok got it. So in this particular case does it make sense to use events vs just using a case structure in the timing loop? Is there any benefits? Quote Link to comment
austinman Posted October 26, 2015 Report Share Posted October 26, 2015 Hi Spetz, Have you taken a look at some of the tutorials on YouTube? If not do a search on "labview event structure" and you will find a number of tutorials that discuss how the event structure works. I think you may find those helpful. Quote Link to comment
venugopal Posted October 31, 2015 Report Share Posted October 31, 2015 Hi spetz, i have modified your vi as per your requirement check it out Event_timer.vi Quote Link to comment
Spetz Posted November 12, 2015 Author Report Share Posted November 12, 2015 Hi spetz, i have modified your vi as per your requirement check it out Not sure this works quite right. Why does the "button 1" only work one time? Quote Link to comment
OlivierL Posted November 12, 2015 Report Share Posted November 12, 2015 Your question is actually interesting here. I had to think about it but in the end. it has to do with LabVIEW Locking the Front Panel. As soon as you press a button, LabVIEW now has 2 events in its Queue and since both events "Lock panel" and each processing is delayed by 500ms. the button becomes unresponsive because LabVIEW no longer accepts any more events. To understand this better, try unchecking the option in the "Edit Events" of "Timer has Elapsed". Look at the VI attached for another implementation that is closer to what we normally do here and is cleaner in my opinion. Not sure if it meets your requirements though. Hope this helps you. Event_timer.vi Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.