LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best practise for a Wait feature on MacOS?

Solved!
Go to solution

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!

0 Kudos
Message 1 of 16
(1,288 Views)

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 16
(1,279 Views)

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

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 16
(1,272 Views)

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

========================
=== Engineer Ambiguously ===
========================
Message 4 of 16
(1,264 Views)

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.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 16
(1,250 Views)

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!

EnergySaver.png

0 Kudos
Message 6 of 16
(1,248 Views)

I'm very confused by the screen-shot you showed for your Mac that you don't want to "sleep".  

  • Turn Display Off -- Never
  • Prevent computer from sleeping automatically when display off -- Check!
  • Put hard disks to sleep when possible -- Uncheck (especially if "hard disks" are SSDs)
  • Wake for Network Access -- ??
  • Start up automatically after a Power Failure -- ??
  • Enable Power Nap -- Uncheck

Doesn't that make more senses if you want LabVIEW to keep a timer going?

 

Bob Schor

0 Kudos
Message 7 of 16
(1,236 Views)

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

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 16
(1,198 Views)

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!

 

0 Kudos
Message 9 of 16
(1,186 Views)

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


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 16
(1,172 Views)