Know when the computer goes to sleep mode

6 views (last 30 days)
Hello,
I write here today because I would like to know if it is possible, when I launch a function in Matlab, to get the time before the computer goes to sleep mode.
Why? Because I am developing a GUI which communicate with electronic devices (oscilloscope and function generators) and I have a mode "oscilloscope" in my GUI which permits to the user to see the signals he wants (I get the signals from the oscilloscope and refresh with a timer). BUT, I intend the case where the user leave the computer and let the function generators output on "ON" and the oscilloscope in the "NORMAL" mode. And what I wish is to stop the acquisition of the oscilloscope just before the computer goes to sleep and then avoid to let the oscilloscope acquired hours and hours for nothing.
I know that in a previous program on Matlab I used getenv('PROGRAMDATA') to find the folder ProgramData of Windows. But the documentation is not really provided for this function. Maybe I have to continue my research in this direction?
The last information I have is I am using insomnia function (from FileExchange) which permit to avoid the computer goes to sleep, but it is not what I want.
I thank you in advance for all advice you could give me.
Best regards

Accepted Answer

KSSV
KSSV on 17 Jun 2016
Interesting question....I am not an expert. A wild suggestion/ advice. I guess you can control the sleep, wake activities through dos prompt. We can run dos prompt in matlab. The following link might give an insight on how to control sleep through cmd.
  5 Comments
Mathieu
Mathieu on 23 Jun 2016
Edited: Mathieu on 23 Jun 2016
I found the solution I will give you here if some people search for this information too. The interest of this solution permit not to pass through a real command prompt of Windows but just stay in Matlab.
You have to enter the command: !powercfg -query > powerOptions.txt in the command Window to save in a text file all the energy modes of the computer. As you will see, in this file there is a line with (Sleep) in it (at the end of the line) and it is the paragraph which is interseting.
At the the line before the end of this paragraph, you have the Current AC Power Setting Index with an hexadecimal string after.
So, you just have to create a small function to read the file, search for the (Sleep) string, and then the line with the string Index in it, and finally get the hexadecial string in order to convert it into a decimal value (I just have to finish this step personnally).
Thank you for your help Mr Kolokula.
KSSV
KSSV on 24 Jun 2016
Happy for you Mr. Mathieu, you got your solution. Good luck..

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!