Jump to content

using timer to exit


Recommended Posts

Posted

Hi,

 

I have a task which I'm struggling to complete.

I have a GUI with a 'Cancel' button which causes to GUI to close.

 

I want to add a functionality where the GUI will also be closed if after 30 sec automatically.

 

I thought that the right programming approach is to force a press on 'Cancel' button from within the code.

I used the val(sgnl) property but it didn't work well - it just pressed on the button regardless what was the input T or F to the property.

 

I tried to use an event with some dummy indicator that should operate the event upon value change, but it also didn't work...

 

I implemented the timer inside a for loop, which also might be wrong.

 

anyhow, I'd be happy to get a couple of suggestions how to make it work.

 

thanks

Posted

The easiest way to do this is with the Timeout event in an event structure. The event structure handles the Cancel button (and whatever other buttons), and you set the Timeout for 30 seconds (30,000 msec).

Posted

Hi Ned,

 

thanks for the reply.

Just to add a little more details...

 

how will this event be called? can I attach an event to a timer?

I mean what will invoke this event?

 

also - there are other activities that take place in the GUI - there is also an OK button which under some conditions can also

close the GUI, and if OK is pressed it should restart the timer to 30 sec again.

 

with that additional information, could this solution still hold?

 

thanks

Posted

The easiest way is as ned said, shown in the top image.

 

post-7534-0-93429500-1420628211.png

 

If you can't use a 30-second timeout because you need to handle other things during those 30 seconds, the lower loop will evaluate whether 30 seconds has elapsed every 0.025 seconds.  You'll need to pass the "reset timer' command back into the Timeout event using a Shift Register.

 

Maybe post your VI?

 

Are you really using LabVIEW 2015?

Posted

Hi jcarmody,

 

tx for your reply.

 

I'll try to put a snap of the subVI for a better description.

 

I'll try to use your suggestion and see what comes out of it. 

 

If I didn't mention before, I already have an event that controls the 2 other buttons in the vi. so I think that I can just add another one...

I'll post it here in a few hours.

 

thanks

Posted

If I didn't mention before, I already have an event that controls the 2 other buttons in the vi. so I think that I can just add another one...

It is generally best to have only one event structure in a VI.  It isn't required by any means but having multiple event structures can make understanding the code more difficult, and can make bugs if certain behavior isn't avoided.  Once you code is posted it should be no problem describing the best approach.

Posted

It is generally best to have only one event structure in a VI. [...]

 

Just to be clear, I showed two Event structures just to show the two approaches.  Pick whichever one suits your application, although it sounds like the upper one isn't applicable with the other events you need to handle.

Posted

hi,

 

just wanted to update that the second solution (event with a timer) did the trick. i will need to solve a few other bugs that happened due to the logic change

but the final result seems to be very good.

 

thanks a lot to all who helped

Posted

It's a good idea to set the post as "Answered" and define which post is the answer, so that other users seeing this thread can go directly to the solution  :book:

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.