LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Preventing system from suspend

Overview

When executing a program it is sometimes needed that the system does not suspend or hibernate blocking your application and leaving connected hardware out of control: in this example a way to avoid this to happen is shown.

Description

Since several of my applications handle endurance tests with unattended testing stations, it is crucial that in no way the device under test is left out of control as it can damage if not continously monitored. A way to do that is to properly configure power options in Control panel but even if we do that, we are not guaranteed that some people may change them at a later time. Till now I was deploying my applications with tons of instructions for the end users explaining how to setup their PCs so that they never suspend or stop executing.


When I came in touch with this document I knew some of my problems could be addressed!

Availability requests as described in this MSDN document can be created when needed and prevent the system to stop while they are in effect (the document can be downloaded via Power Availability Requests link in the page linked)

I developed this example code to show how availability requests can be handled in CVI.

Steps to Implement or Execute Code

The supplied example can be run as-is. You can monitor power requests in execution by running a command prompt window with administrative rights (right-click on the icon and choose "Run as administrator") then executing "powercfg /requests" command: when the request is enabled you'll see "CVI program in execution" request listed under system group. Execute Create request and Enable request functions to enable a system availabilty request: while this is in effect a timer will be shown on the window so that you can monitor whether the system remains active even after suspending time set in control panel is expired. At the same time, a beep will be issued every 10 seconds so that even if the screen goes off you'll know the system is still alive.

To add availability requests to the code you need to:

  1. Add a #define _WIN32_WINNT _WIN32_WINNT_WIN7 line at the top of the source file where instructions will be added
  2. Add #include <windows.h> after the line in step 1
  3. Add code taken from CreateRequest, EnableRequest, DisableRrequest and CloseRequest functions in my code

Requirements

Software

The example program has been developed in CVI 2012SP1; nevertheless, it uses no functions typical of this version so it can be executed with previous versions of CVI too.

Interface to Win32 API needs to be installed in CVI: if it is not installed, run CVI setup again and choose custom install adding this module to your system.

I have tested this application in Full version of CVI, but according to this page, functions used in this example are included even in base version so there should be no problem using these regardless the version of CVI you are using.

Hardware

No hardware is needed to run this example

This is a screenshot of the example program while the availability request is enabled:

Screenshot 2016-04-25 11.02.29.png

Additional notes

This example can be used in conjunction with my previous contribution

Controlling power in laptops or UPS-operated PCs in LabWindows/CVI

Enabling availability requests must be paired with a constant monitoring of PC supply in case of battery operated PC or UPS backed up systems, so that the unit can be properly shut off in case remaining power is low.




Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Contributors