02-03-2022 04:18 PM
What is the best way to implement a Wait on MacOS (wait times 1s to several minutes)? My standard way of doing this is with an implementation that uses the millisecond timer in a while loop along with an abort reference and a 100mS standard wait to not overload the CPU in the loop. This works great but except for one major issue which might be MacOS only. When the computer/screen goes to sleep it seems that the execution slows down and my wait times becomes longer. I changed the millisecond timer to the get time in seconds but that did not solve it. How do you implement Wait features in your code that works even if the computer goes to sleep? My measurements can span for hours and it is very likely the computer goes to sleep one way or another during this time. But I don't want this to affect the execution as it is important that my wait times are regular and not impacted by the sleep state of the computer... Any input is welcome!
Solved! Go to Solution.
02-03-2022 04:49 PM - edited 02-03-2022 04:51 PM
Disable sleep mode!
You don't know how many problems Windows computers cause when they go to sleep or power management kicks in and does something like turns off a USB device.
Honestly I have been moving away from "wait loops" like you described and now try to do something even if it's just querying all the instruments for errors between checking to see if the time has elapsed.
02-03-2022 04:53 PM
@RTSLVU wrote:
Disable sleep mode!
You don't know how many problems Windows computers cause when they go to sleep or power management kicks in and does something like turns off a USB device.
Honestly I have been moving away from "wait loops" like you described and now try to do something even if it's just querying all the instruments for errors between checking to see if the time has elapsed.
Just for clarity, RTSLVU was relating what happens when Windows PCs go into a similar power mode to describe what is probably happening to your Mac.
02-03-2022 04:56 PM
@billko wrote:
@RTSLVU wrote:
Disable sleep mode!
You don't know how many problems Windows computers cause when they go to sleep or power management kicks in and does something like turns off a USB device.
Honestly I have been moving away from "wait loops" like you described and now try to do something even if it's just querying all the instruments for errors between checking to see if the time has elapsed.
Just for clarity, RTSLVU was relating what happens when Windows PCs go into a similar power mode to describe what is probably happening to your Mac.
Right, I guess I was not clear on that, but disabling ALL power management is one of the first things I do now on a computer that is going to be running any automated tests because if issues like the OP is having with their MAC.
02-03-2022 05:30 PM
First, I would spec a Windows OS. Barring that option I would raise the vi priority or, better, use a timed loop to raise the priority and spawn a dedicated execution system. Name the timed loop and you can even stop it with a simple stop timed loop without recoding all that yourself.
02-03-2022 05:32 PM
Hi,
Great inputs and I agree with you completely. In MacOS you have a setting called Energy Saver. I have tried many settings with it and I can't seem to figure out how to fully disable it... That is why I included Mac in the title to this question as it relates to my code running on MacOS. On my PCs I have not had this issue ever as it seems more straight forward in Windows to get around it. Any Mac users on here that uses Wait features in the code? In my case my wait time went from 30 seconds when the computer was active to around 1 minute when it was asleep. I tried some 10 different combinations in the Energy Saver and no combination fixed it. I have added the Screen Saver screen (with the default settings) in MacOS below for reference if anyone is curious. Thanks again!
02-03-2022 05:48 PM
I'm very confused by the screen-shot you showed for your Mac that you don't want to "sleep".
Doesn't that make more senses if you want LabVIEW to keep a timer going?
Bob Schor
02-04-2022 03:22 AM
@Mikael_Garcia wrote:
What is the best way to implement a Wait on MacOS (wait times 1s to several minutes)? My standard way of doing this is with an implementation that uses the millisecond timer in a while loop along with an abort reference and a 100mS standard wait to not overload the CPU in the loop. This works great but except for one major issue which might be MacOS only. When the computer/screen goes to sleep it seems that the execution slows down and my wait times becomes longer. I changed the millisecond timer to the get time in seconds but that did not solve it. How do you implement Wait features in your code that works even if the computer goes to sleep? My measurements can span for hours and it is very likely the computer goes to sleep one way or another during this time. But I don't want this to affect the execution as it is important that my wait times are regular and not impacted by the sleep state of the computer... Any input is welcome!
I would change from Wait(ms) to e.g. GetDateTime and see if it's done.
02-04-2022 08:00 AM
All good inputs. Thanks! The one that speaks volume is "First, I would spec a Windows OS"... it seems I am one of a very few number of Mac users on here. I also use Windows but in this project I was going to deploy a Mac. Seems a bit tricky.
Just to clarify, the settings I showed in the image are the Mac defaults. As mentioned, I tried 10 or so different combinations with no luck. As suggested here, I also tried to set the top VI's priority to the highest (time-critical). Still no luck. I will try and run some more experiments and if I am lucky I will find a solution that works. If any Mac users are on here and have tests that span for hours in combination with timers and I am all ears for any tricks you can share! Thanks!
02-04-2022 11:52 AM - edited 02-04-2022 11:59 AM
Do try the named timed loop. At the very least the finished late node will give you some awareness about when the timing is suspect.
You could also try slipping over to the hi resolution timer. That operates on a different kernel driver and may have more stability.
Take a gander over the links in this Community Nugget