Discussion:
Why this while loop can be stopped in the event strucure?
(too old to reply)
wbcat
2008-08-13 17:10:08 UTC
Permalink
Normally, you can not stop while loop inside a event structure. But the vi attached here can do it...If you create a new vi: drag a new event structure but copy the while loop from the vi attached, you won't be able to stop the loop. Can anyone tell what's going on? Thanks


Stop-While-in-Event.vi:
http://forums.ni.com/ni/attachments/ni/170/349050/1/Stop-While-in-Event.vi
altenbach
2008-08-13 17:10:09 UTC
Permalink
By default, event structure lock the front panel until the event completes. Here this option is uchecked in the event configuration, allowing reading of the cancel button. It is still not a good idea to trap event structures with an inner loop.
wbcat
2008-08-13 18:40:07 UTC
Permalink
Thank you, altenbach!  I read your article before:smileyhappy:More questons:If I use your idea, set up the timeout case as in the new vi attached, the problem is, when you run another case (for example, if you press 'others' button), the outside loop will run once, I do not want that happen. How can I modify it?
wbcat
2008-08-13 18:40:07 UTC
Permalink
Sorry, forgot to attach the file...


Stop-While-in-Event02.vi:
http://forums.ni.com/ni/attachments/ni/170/349084/1/Stop-While-in-Event02.vi
MikeS81
2008-08-13 18:40:08 UTC
Permalink
Hi wbcat,do you mean the only loop you have in your code? Without this loop you can execute only one event. You need the loop to run your program. Why don´t you want the loop running? If you need a counter for some special events, then create a shift register and add one in your specified event. Hope it helps.Mike 
altenbach
2008-08-13 19:10:05 UTC
Permalink
Well, the outer loop MUST run in order to service the event. No way around that. Your VI has several problems:- The timeout is zero by default, meaning the outer loop spins like crazy for the timeout case until one of the buttons is pressed.
- There is no reason at all to use a FP indicator and value properties. This is very inefficient. All you need is a shift register, initialized with -1.
- Again, if you want something that only increments in some of the cases, use a shift register with an indicator and add a +1 in some of the event cases.
altenbach
2008-08-13 19:10:06 UTC
Permalink
I no longer have LabVIEW 7.1, but here's a quick draft. Use similar code for the otehr cases, e.g. add a &quot;+1&quot; to the timout case, etc.&nbsp;<img src="Loading Image..." border="0" width="396" height="254"> Message Edited by altenbach on 08-13-2008 11:46 AM


timeouter.PNG:
http://forums.ni.com/ni/attachments/ni/170/349093/1/timeouter.PNG
wbcat
2008-08-13 19:10:07 UTC
Permalink
Thanks, altenbach!&gt;&gt;The timeout is zero by defaultyou are right. But if you set the default as -1, it works
altenbach
2008-08-13 19:10:07 UTC
Permalink
wbcat wrote:
Thanks, altenbach!&gt;&gt;The timeout is zero by defaultyou are right. But if you set the default as -1, it works
Yes, but is still very clumsy code. Don't abuse front panel objects as &quot;variables&quot;.
wbcat
2008-08-13 19:10:09 UTC
Permalink
I&nbsp;agree,&nbsp;altenbach&nbsp;by the way, thank MikeS81 for your concern&nbsp;More questions for your guys:the&nbsp;real code inside the loop is a single laser pulse, while the &quot;others&quot; are different laser setups, like voltage, etc...I plan to&nbsp; set every single setup and then&nbsp;run the laser pulse loop to check how the laser&nbsp;works.But I hate laser fires without control: when I set &quot;others&quot;, it will fire once. I donot like that&nbsp;
MikeS81
2008-08-13 19:10:11 UTC
Permalink
wbcat wrote:
..But I hate laser fires without control: when I set &quot;others&quot;, it will fire once. I donot like that
Hi wbcat,i don&acute;t understand it. Do you mean because the loop runs ones? Where do you want to fire the event. Only the selected event runs.Mike&nbsp;
altenbach
2008-08-13 19:10:11 UTC
Permalink
If you fire the laser inside the correct event, it will not fire if other events are triggered.
wbcat
2008-08-13 19:40:06 UTC
Permalink
&nbsp;altenbach ,I can put the code for one single fire inside a event, it will not be triggered. &nbsp;the problem is, you want it fire continuously, that is why I need the while loop. otherwise, you can not check how good it is working. I can use a for loop, but it is not that convenient
altenbach
2008-08-13 19:40:09 UTC
Permalink
wbcat wrote:
&nbsp;I can put the code for one single fire inside a event, it will not be triggered. &nbsp;the problem is, you want it fire continuously, that is why I need the while loop. otherwise, you can not check how good it is working. I can use a for loop, but it is not that convenient
&nbsp;&nbsp;Then, I don't uderstand what the problem is if the laser should fire continuously anyway. ;)&nbsp;What if you put&nbsp;the laser&nbsp;in the timeout case?
wbcat
2008-08-13 20:10:08 UTC
Permalink
altenbach,I am a moron:smileysurprised:by the way, why you donot like the solution, uncheck 'the front panel lock' of the event case
altenbach
2008-08-13 20:10:09 UTC
Permalink
wbcat wrote:
by the way, why you donot like the solution, uncheck 'the front panel lock' of the event case
Because what good is an event structure if it cannot react to events at all time, e.g. during the time the code is running the inner loop?&nbsp;There is a danger that you accumulate an infinite number of events in the event queue. Imagine you have an event for a certain button press, but the code is running the inner while loop. Every time you press that button, it will get queued up, because the event structure is not ready for it yet.
wbcat
2008-08-13 20:10:11 UTC
Permalink
altenbach,I see..Thanks a lot&nbsp;

Loading...