07-21-2015 04:42 AM
Hi All,
I would like to know how will i be able to tackle a seemingly simple issue.
I would want a timer to start immediately, when i type something from my keyboard(or a scanner). All the characters that i type within 1second should be stored, say to a control. And then after 1second the VI should stop its execution.
I think the perfect workaround could be to run the timer in a separate thread, if somethings get typed and using the 'Time has elapsed' property of Elapsed time to stop the execution of VI. But i dont know how to work with thread. Please help !
Note: I get the keypresses using Acquire Input Data.vi
07-21-2015 07:32 AM
I think the Elapsed Time function will do what you want. The idea is to reset it until you get your first key and then stop the loop when the time has elapsed.
07-21-2015 08:01 AM
I think i need to elaborate a bit more. Now when i read my first character, inside a case structure, yeah i will reset it. But the Time has elapsed property won't get set after exactly 1 sec. Only if a type a character after 1sec (say at the 10th sec), will it get set and terminate the execution
Please look into the code attached.
I want the execution to stop exactly after 1 second after i read my first character.
07-21-2015 10:12 AM - edited 07-21-2015 10:29 AM
Do you want any key presses or is it sufficient to look for key down event on the VI? Be careful, using a generic keyboard monitor could be considered malware (e.g. you could capture passwords entered into web pages). Better check with company policies.
Your VI is using 100% CPU when not doing anything. I think you should use key down events. They even include a tick count, so you can easily calculate elapsed time.
I don't understand the subject of this discussion? What does it have to do with "thread"? Also, this seems like a general LabVIEW question and has nothing to do with hardware counter/timers. Maybe you should ask the moderator to move the thread to a better place, such as the LabVIEW forum.
07-21-2015 11:36 AM - edited 07-21-2015 11:37 AM
Oh, you are trying to use a barcode scanner!? You will not get what you want in the manner you are trying.
You really should be using an Event Structure with the Key Down event. From there, you can filter your read data and build up your string. This snippet should be a start for what you want.
It uses the event structure to do everything. I initialize the string to be empty and then wait for a key press. From there, I also set the timeout to be 1 second and do whatever I need to with the character that came in. If the character is an ASCII character, I add it to the string. If the character is the Return or Enter key, I stop the loop. I also stop the loop on a timeout (no activity for 1 second).
07-21-2015 10:55 PM
Actually i resorted to this approach because, as per my requirement, even when the focus is on some other window, when a keypress(either scanner or keyboard) is detected (after i initialize) it should be monitored for 1 second.
Now when i tried to implement the 1 second capturing with the above approach it seems to fail.
Please shed some light onto how i could implement all this.
Thanks in advance.
07-22-2015 11:50 PM
Someone please help me.
What i intend to do is that, i must be able to start an independent timer immediately when i type my first character, the timer must run run for 1 second and upon 1 second it should stop the execution of VI. Meanwhile all the characters typed/scanned during that 1second should be stored in string control (shown in the above attached vi).
In the method that i use in the above attached vi, the time has elapsed property gets set only if i type something after 1 second. Say i type some things till 0.6 second and then i stop typing and only if i resuming typing, say at the 20th second, will the execution stop. I want it to stop at exact 1 second after i type the first character.
Please help..!!