08-06-2013 03:50 AM
Hi,
I have begun for a few weeks a quite big VI. Most of the program is included in a big while loop. But I have the feeling that it is uselessly slowing down. So in ordrer to optimize it, I would like the VI to run only when the mouse or the keyboard acts on it. It would release the CPU when I do not use it, without having to close it. I have found on the internet how to use the "wait for" to slow down the loop, but doing this, some parts of the VI that should run in real time also slow down. I think my idea should be more efficient both for the real-time applications and to release the memory.
In consequence, how can I ask the while loop to go to the next iteration only when the button of the mouse is pressed or when a field gets filled by the keyboard? Or is there an alternative to the while loop?
Thanks,
Isaac
Solved! Go to Solution.
08-06-2013 04:03 AM - edited 08-06-2013 04:05 AM
Hi,
You can check this using event structure and monitor the mouse and keyboard activities.
I have modify a simple VI to show this, please check the attachment.
Meanwhile, you can check this example available on ni.com
http://zone.ni.com/devzone/cda/epd/p/id/3924
Regards,
KwokHow Lou
AE NI Singapore
08-06-2013 04:11 AM
Check out the Producer/consumer example/pattern.
It sounds like you want UI items to be handled seprately and waiting for action, while you want some actions running e.g. each 50ms (and possibly other actions when pressing a button). This is what the producer/consumer gives you in a expandable pattern.
If you create a type-def'd enum with states as Init, measure, wait for input, update ui, close. The common prod/con is a queue-based variant, and you can send commands to it from the top event-structure or from itself. You'll start the program with queueing Init, ofc. a Start button will queue Measure and you can e.g. use the timeout to queue Update UI or similar.
/Y
08-07-2013 02:22 AM - edited 08-07-2013 02:23 AM
Hello Isaac,
What do you exactly mean with "some parts of the VI that should run in real time"?
The words "real-time" are quite often used in various contexts.
Providing a bit more background information will allow us to help you with more specific advise.
Seeing your last question I think Yamada's advice might be the solution.
Queued Message Handlers in general are also for sure worth taking a look at.
08-08-2013 02:32 AM
Sorry for having forgotten to mark the topic as resolved, and thank you all for your answers 🙂
By "real-time", I meant interactive: the VI opens a file to analyse, lets the user work on it (the interactive, real-time part), and then prints it once the user has finished his work.
08-09-2013 02:44 AM
Hello Isaac,
Thanks for the feedback!
Then this solution should be perfectly ok.
My mesage about the marking of as solution is just a part of in my general footer. 🙂