home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 4 Drivers
/
04-Drivers.zip
/
wcrd092.zip
/
WATCH.C
< prev
next >
Wrap
Text File
|
1996-07-08
|
3KB
|
81 lines
/********************************************/
/* WATCH.C 8 Jul 1996 Juergen Dittmer */
/* Sample program for Watchdog DD */
/********************************************/
#define INCL_DOSDEVICES /* Device values */
#define INCL_DOSPROCESS
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/* Returnvalues from Watchdog */
typedef struct _IODATAPKT {
ULONG ulTimer; /* Timeoutcounter */
} IODATAPKT;
main(int argc, char *argv[])
{
HFILE DevHandle; /* Device handle specifies the device */
ULONG Category = 0x91; /* Device category for IOCtl */
ULONG Function = 0x01; /* Device function for IOCtl */
ULONG delay = 10; /* Delay in seconds between IOCtl's */
ULONG ulAction = 0; /* For DosOpen */
IODATAPKT IOData; /* Watchdog returnvalues */
APIRET rc; /* Return code for API's */
if (argc == 2) delay = atoi (argv[1]); /* Get command line value */
printf ("DosDevIOCtl Cat:%x Func:%x\n\n", Category, Function);
/* First we have to open the device driver. */
/* This process will be registered at the watchdog */
/* and must send periodic IOCtl's to the driver. */
rc = DosOpen("WATCHDG$", &DevHandle,
&ulAction, 0,
FILE_NORMAL,
FILE_OPEN,
OPEN_SHARE_DENYNONE | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_ACCESS_READWRITE,
0L);
if (rc != 0)
{
/* An error has occured during open, show the return code */
printf("DosOpen error: return code = %ld\n", rc);
return;
}
printf ("Time interval = %d seconds. Press space for return\n", delay);
/* Send periodic IOCtl's to the driver until a key is pressed */
/* The watchdog passes back values in the IOData struct */
while (!kbhit()) {
printf ("Send IOCtl, ");
rc = DosDevIOCtl(DevHandle, Category, Function, NULL,
NULL, NULL, &IOData,
sizeof (IOData), NULL);
if (rc != 0)
{
/* An error has occured during IOCtl, show the return code */
printf ("DosDevIOCtl error: return code = %ld\n", rc);
return;
} else {
/* OK, show the watchdog's counter */
printf ("Watchdogcounter: %d Seconds\n", IOData.ulTimer);
}
DosSleep (delay * 1000);
} /* endwhile */
/* A key has been pressed, terminate the programm. */
/* DosClose deregisters the process */
rc = DosClose (DevHandle);
}