09-25-2020 10:31 PM
Hello all. I am relatively new to labview and have been trying to come up with a way to have my object continually get status while my for loop executes and then terminate when the for loop is complete. I tried putting it in a while loop outside the for loop but there is no criteria that I can think of linking its completion with the completion of the for loop. Also, there is no status that the object calls that I can use to terminate the while loop. It needs to stop when the for loop is finished. Any help would be much appreciated and a snip example would be even better. I have tried so many different ideas but with no success.
Solved! Go to Solution.
09-25-2020 10:43 PM
Instead of all these greedy loops ( do you really need to update that indicator millions of times per second or check millions of times per second if a timer has elapsed?), think about a good architecture. (e.g. a state machine. Most likely you can eliminate all that duplicate code.
What does the program do?
Unfortunately you only attached a truncated picture, so we cannot really give more specific advice. Typically people get better help if they attach an actual VI.
09-25-2020 10:45 PM - edited 09-25-2020 10:47 PM
Look up Notifiers in the LabVIEW example finder.
Your Elapsed Time Express VI in the inner while loop should really have a small wait. Right not it is burning a CPU core at 100% for 5 seconds polling that status of a timer. A wait function of 5000 milliseconds (in a sequence frame or using the new Wait.vim) would do the same thing and not burn the CPU.
09-25-2020 11:07 PM
I will look up notifies and see if I can implement it successfully. Thank you for the tip, hopefully they're some good example online. The elapsed time does need to be at least 5 seconds because the object I called before the wait time takes a bunch to time to process in the system I am working with and I need to check status after at least 5 seconds has elapsed. Is there another wait time method that uses less of the CPU..?
09-25-2020 11:17 PM
Yes. The Wait (msec) function in the time palette. Replace the while loop with a sequence frame, and put the wait function in it.
09-26-2020 12:20 AM
Thank you for the response. I will change it.
09-27-2020 12:44 AM
It was suggested by someone in the community to look into notifiers if I wanted to stop a while loop after a for loop finishes its iterations. I have tried a bunch of combinations of logic that simply do not make sense nor work. I have attached a vi but it is just a shell (it is just a place holder, I know it cannot work as shown). Is there a straight forward non trivial way to accomplish this utilizing notifiers?
09-27-2020 05:09 AM - edited 09-27-2020 05:16 AM
You need a timeout on the Wait on Notification, even a value of 0, so it can execute.
The Release Notifier belongs after the while Loop.
You need to enable Automatic Error Handling on your VI (VI Properties >> Execution)
Because your Master Loop kills the notifier right after it ends, the slave loop doesn't see it. Because you didn't have automatic error handling turned on, you didn't see an error message about the notifier reference going bad. It's like you shot the messenger immediately after giving him the message to send.
09-27-2020 09:17 AM
Ha! You brought new meaning to the old phrase, "don't shoot the messenger". I like it!
-Kevin P
09-27-2020
12:16 PM
- last edited on
12-16-2024
01:35 PM
by
Content Cleaner
(With a username of Jeff k, make sure you are not getting confused with this guy :D)
Can you place your construct in the overall context of the entire program? This entire thing still seems way too convoluted. Why would you need to send a notification with every iteration of the FOR loop? Shouldn't' you while loop stop when the notification is NOT "Loop 1"? One notification after the FOR loop would be sufficient.
It would even be sufficient to never send any notification and use the killing of the notification to stop the while loop.
I stand by my statement that there are probably much better ways to do whatever you need to do. Once we know the overall architecture, we can probably offer suggestions.