//
// Demo code for iSMM DIO & WDT access
//
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "iSMMDLL.h"
int main(int argc, char **argv)
{
HANDLE hIsmm;
unsigned short wDioConfig, wDioData;
BOOL bTaskComplete = FALSE;
hIsmm = ISMM_Open();
if (hIsmm == INVALID_HANDLE_VALUE)
{
printf("Can not open iSMM device\n");
return -1;
}
if ( DIO_GetConfig(hIsmm, &wDioConfig) )
{
printf("Number of DIO input bits: %d, output bits: %d\n", wDioConfig & 0xff, wDioConfig >> 8);
// Get DIO input
DIO_GetInput(hIsmm, &wDioData);
printf("Read DIO input=0x%04x\n", wDioData);
// output some data to DIO
wDioData = 0x05;
DIO_SetOutput(hIsmm, wDioData);
printf("Write DIO with 0x%04x\n", wDioData);
}
else
printf("No DIO support\n");
// set watchdog timeout to 10 seconds
WDT_SetTimeout(hIsmm, 10, WDT_TIMEOPT_SECOND);
// starting watchdog timer
if ( WDT_Start(hIsmm, TRUE) )
{
while(1)
{
// perform your task here
// :
if (bTaskComplete)
break;
// restart timer
WDT_Restart(hIsmm);
}
// stop watchdog timer before exit
WDT_Start(hIsmm, FALSE);
}
else
printf("Fail to start WDT\n");
ISMM_Close(hIsmm);
return 0;
}