LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wake up PC

Is there a function to programmatically wake up my PC? 

 

Or one to wake-up on LAN?  

 

I have found the sleep - 

https://msdn.microsoft.com/en-us/library/windows/desktop/aa373201(v=vs.85).aspx

 

I would like to control when my PC switches on and off, either from power off or sleep mode. 

 

 

Many thanks

Graham 

0 Kudos
Message 1 of 9
(3,768 Views)

On the web there are a lot of Wake On Lan utilities, some are free.

While I never tested any of them, some seem to offer scheduling. Other can be used from command line, so it's easy to implement your own scheduling pattern either by your application or by OS services.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 9
(3,746 Views)

I was interested in the two ways of switching the PC on and off automatically. From power off, which as you say requires an external magic Ethernet packet. It would be useful to have LabVIEW code to do this over a network because that could become a remote control for a home PC at work.

 

The other simpler way is to keep the PC powered on and use the sleep mode. The Windows task scheduler can do this, and there is a sleep function in LabVIEW, but I haven't seen a wake-up function. 

 

 

0 Kudos
Message 3 of 9
(3,689 Views)

@grahamwebb wrote:

I was interested in the two ways of switching the PC on and off automatically. From power off, which as you say requires an external magic Ethernet packet. It would be useful to have LabVIEW code to do this over a network because that could become a remote control for a home PC at work.

This is most likely not an option to do natively in LabVIEW. These wakeup packages are typically low level ethernet packages that require a raw ethernet socket to put together. LabVIEW only has UDP and TCP functionality which is a full network layer higher than IP and two layers higher than raw sockets. The best bet is to use one of the many command line tools that support this and call them from LabVIEW with System Exec. The funny way would be to incorporate a WinPCap interface and use that to create your magic frame, but unless you have lots and lots of time to tinker this is definitely not the way to go. A native interface to the WinSock library (or BSDsock library on Linux) to access raw sockets is also not an ideal solution since on all modern OSes raw sockets are only available to privileged processes.

 

The other simpler way is to keep the PC powered on and use the sleep mode. The Windows task scheduler can do this, and there is a sleep function in LabVIEW, but I haven't seen a wake-up function. 


I'm not sure how you imagine this to work. In order for a LabVIEW program to run on a computer the CPU has to be active. A PC in sleep mode is not active. If you mean accessing the functionality to set a sleep interval after which the BIOS will wakeup automatically then your best bet is again to find a command line tool that allows this and call it with System Exec.

 

Most likely you will run into troubles with hardware specific functionality for this. There isn't exactly a real standard on how to implement sleep and wakeup operations in BIOS if a motherboard even supports such a functionality (many don't or at least not without serious bugs).

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 9
(3,682 Views)

Thanks Rolf, there is a lot there for me to investigate. 

 

My hope that it is possible to wake up a PC from sleep simply came from the existence of these functions: https://forums.ni.com/t5/Example-Programs/Sleep-Shutdown-Restart-and-Lock-Windows-programmatically/t...

 

And knowing that the Windows task scheduler can do it. I guess I am unrealistically expecting that LabVIEW can be active during sleep mode. 

0 Kudos
Message 5 of 9
(3,669 Views)

Well, after a search I found that it may possible to accomplish the task using a Waitable Timer object, see here for documentation. If the last parameter is true and the hardware allows for this functionality, the PC will be put in an active state when the timer expires.

An example C# code is given here.

It doesn't seem to be an easy task, though. The application must create a dedicated thread that waits for the timer to go to a signaled state.

I guess it would need to create a specific DLL for creating the waiting thread and possibly cancel the thread if the calling application must be closed before the timer expires.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 9
(3,661 Views)

Here would be one place to start your search.  I don't think you can "Wake" a modern PC without hacking into a Real Mode exe previously installed and set up to reside under the OS.

 

I may be wrong.  It wouldn't surprise me if I am.  

 

It might be better just cure the computer's narcolepsy and prevent it from going to sleep whenever you think it might be useful to have it running

 

EDIT: go figure.....You just need hardware!


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 9
(3,652 Views)

@grahamwebb wrote:

 

And knowing that the Windows task scheduler can do it. I guess I am unrealistically expecting that LabVIEW can be active during sleep mode. 


Have you tried leveraging the windows task scheduler to schedule a wakeup task from within LabVIEW before putting the PC to sleep?

0 Kudos
Message 8 of 9
(3,635 Views)

That's an interesting idea. I haven't tried, but I will look at Schtasks - 

 

https://forums.ni.com/t5/LabVIEW/windows-task-scheduler/td-p/148060

 

 

0 Kudos
Message 9 of 9
(3,629 Views)