Beijer Electronics (formerly QSI Corporation)

Quick TREQ-DX example for performing a soft power off
Page 1 of 1

Author:  danieln [ Wed Mar 24, 2010 8:16 am ]
Post subject:  Quick TREQ-DX example for performing a soft power off

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 on page 64.

// 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;
   if (death<=0)
      return -1;



   return 0;

void CertainDeath()
   while (true)
      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))
         if (counter==death)
            dwPowerState = POWER_OFF;
            DeviceIoControl(hDevice, PMD_SET_POWERSTATE, &dwPowerState,sizeof(dwPowerState), NULL, 0, NULL, NULL);

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group