Jump to content

Event structure and timing


Spetz

Recommended Posts

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

Link to comment

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.

Link to comment

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 by JKSH
Link to comment

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?

Link to comment

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.

Link to comment

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?

Link to comment
  • 2 weeks later...

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.

 

 

post-12461-0-20965500-1447356965.png

Event_timer.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.