Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sun Nov 19, 2017 3:31 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Mar 24, 2010 8:16 am 
Offline
User avatar

Joined: Thu Jan 14, 2010 10:20 am
Posts: 38
This example is a command line utility for performing a soft power-off. It accepts one paramter, in minutes, that specifies how long the device should wait before shutting down. It checks once a minute, and starts counting once it detects the device is in user idle or system idle mode.

This app was primarily used in a situation where the TREQ-DX went into system idle when it detected the truck was powered off via the ignition signal. This is configurable via a registry setting found at [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\TreqPM\Ignition Pin Options]. More details can be found in the DX user guide http://www.qsicorp.com/engfiles/TREQ/TREQ-DX/TREQ-DX_UserGuide.pdf on page 64.

Code:
// ShutOffCE.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "TreqPublic.h"
#include "TreqIoCtl.h"

BOOL enablecounter;
int counter;
int death;
void CertainDeath();
DWORD dwPowerState;
HANDLE hDevice;

int _tmain(int argc, _TCHAR* argv[])
{
   if (argc!=2)
      return -1;
   death=_wtoi(argv[1]);
   if (death<=0)
      return -1;

   enablecounter=false;
    counter=0;

    CertainDeath();

   return 0;
}


void CertainDeath()
{
   while (true)
   {
      Sleep(60000);
            
      hDevice = CreateFile(TEXT("PMD1:"), GENERIC_READ, 0, NULL, OPEN_EXISTING,0, NULL);
            
      // get the current power state
      DeviceIoControl(hDevice, PMD_GET_POWERSTATE, NULL, 0, &dwPowerState,sizeof(dwPowerState), NULL, NULL);

      if ((dwPowerState==POWER_USERIDLE)||(dwPowerState==POWER_SYSTEMIDLE))
      {
         counter++;
         if (counter==death)
         {
            dwPowerState = POWER_OFF;
            DeviceIoControl(hDevice, PMD_SET_POWERSTATE, &dwPowerState,sizeof(dwPowerState), NULL, 0, NULL, NULL);
         }
      }else
         counter=0;
      
      CloseHandle(hDevice);
   }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group