LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop running only when mouse or keybord are active

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(3,212 Views)
Solution
Accepted by topic author isaac.fr

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.

keydown.PNG

 

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

Applications Engineer | National Instruments
Singapore (65) 6226 5886 | Malaysia (60) 3 7948 2000 | Thailand (66) 2 298 4800
Philippines (63) 2 659 1722 | Vietnam (84) 28 3911 3150 | Indonesia (62) 21 2783 2355
Message 2 of 6
(3,208 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 6
(3,202 Views)

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.

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 4 of 6
(3,155 Views)

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.

0 Kudos
Message 5 of 6
(3,126 Views)

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. 🙂

 

 

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 6 of 6
(3,101 Views)