FB_PcWatchDog_BAPI
This functionality is only available on IPCs and Embedded PCs with a BIOS version which supports the BIOS-API. |
The function block FB_PcWatchdog_BAPI activates a hardware watchdog on the PC. The watchdog is activated via bExecute = TRUE and the watchdog time. The watchdog time can range between 1 and 15300 seconds (255 minutes). The watchdog is activated via bEnable = TRUE and nWatchdogTimeS >=1 s.
Once the watchdog has been activated, the function block must be called cyclically at shorter intervals than nWatchdogTimeS, since the PC restarts automatically when nWatchdogTimeS has elapsed. The watchdog can therefore be used to automatically reboot systems, which have entered an infinite loop or where the PLC has become stuck.
Notice | |
PC reboot The watchdog must be deactivated before breakpoints are used, before a PLC reset or an overall reset, before a TwinCAT stop, before switching to Config mode or before the configuration is activated, because otherwise the PC would reboot immediately once nWatchdogTimeS has elapsed. |
Inputs
VAR_INPUT
sNetID : T_AmsNetID;
nWatchdogTimeS : UDINT;
bExecute : BOOL;
tTimeout : TIME;
END_VAR
Name | Type | Description |
---|---|---|
sNetID | T_AmsNetID | AMS network ID of the device (empty string or local network ID) |
nWatchdogTimeS | UDINT | Watchdog time in seconds, 0 = deactivated, >0 (max. 15300) = activated. |
bExecute | BOOL | The command is executed with a rising edge. The input must be reset as soon as the function block is no longer active ( |
tTimeout | TIME | Indicates the time until the internal ADS communication is terminated. |
Outputs
VAR_OUTPUT
bEnabled : BOOL;
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
END_VAR
Name | Type | Description |
---|---|---|
bEnabled | BOOL | TRUE = watchdog activated, FALSE = watchdog deactivated |
bBusy | BOOL | This output remains TRUE until the function block has executed a command. |
bError | BOOL | This output is switched to TRUE as soon as an error occurs during the execution of a command. The command-specific error code is contained in nErrId. Is reset to FALSE by the execution of a command at the inputs. |
nErrId | UDINT | ADS error code or command-specific error code of the last executed command. Is reset to 0 by the execution of a command at the inputs. |
Sample of calling the function block in ST:
PROGRAM MAIN
VAR
fbWatchdog : FB_PcWatchdog_BAPI;
nWatchdogTimeS : UDINT := 10; (* 10s *)
bEnabled : BOOL; (* TRUE: watchdog is activated *)
bError : BOOL;
nErrID : UDINT;
fbTimer : TON := (IN := TRUE, PT := T#0S);
END_VAR
fbTimer();
(* 1st enable, then refresh watchdog every 1s *)
IF fbTimer.Q THEN
fbWatchdog(
sNetID := '',
nWatchdogTimeS := nWatchdogTimeS,
bExecute := TRUE,
tTimeout := T#5S,
);
IF NOT fbWatchdog.bBusy THEN
bEnabled := fbWatchdog.bEnabled;
bError := fbWatchdog.bError;
nErrID := fbWatchdog.nErrID;
fbWatchdog(bExecute := FALSE);
(* restart timer*)
fbTimer(IN := FALSE);
fbTimer(IN := TRUE, PT := T#1S); (* refresh watchdog every s *)
END_IF
END_IF
Requirements
Development environment | Target platform | PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 | IPCs and Embedded PCs with a BIOS version which supports the BIOS-API. | PLC Lib Tc2_System-Version |