Using the Watchdog library, you can establish a mechanism between your application and the firmware in order to react to exceptions or problems within your client program execution.
The following steps are necessary:
- Setup the watchdog and specify the timeout in milliseconds as well as the action to be taken when the timeout is reached.
- Start the watchdog.
- Reset the watchdog on a cyclic time basis that is lower than the specified timeout. As soon as you do not reset the watchdog in time, it will execute the action as specified during setup, e.g. stop the PLC or restart the device.
Here is some sample code:
printf("\nWatchdog active! Press any key to block watchdog reset or 'q' to quit.");
bool done = false;
while(!done)
{
Sleep(1000);
switch(state)
{
printf("\nWATCHDOG_DISABLED");
break;
printf("\nWATCHDOG_ENABLED");
break;
printf("\nWATCHDOG_TIMEOUT");
break;
}
if (_kbhit())
{
char key = _getch();
if (key=='q'){
done = true;
}else{
printf("\nBlocking reset of Watchdog.");
Sleep(5000);
}
}
}
- Note
- The WatchdogLib functions trace their debug information mainly into module the MLPI_WATCHDOG_LIB and in addition into the module MLPI_BASE_MODULES. For further information, see also the detailed description of the library TraceLib.