FB_PcWatchDog_BAPI 1:
FB_PcWatchDog_BAPI 2:

This functionality is only available on IPCs with the mainboards CBxx63 and Embedded PCs CX51x0, CX20x0, CX20x2, CX20x3 with a BIOS version from 0.44 or higher.

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.


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.


    sNetID         : T_AmsNetID;
    nWatchdogTimeS : UDINT;
    bExecute       : BOOL;
    tTimeout       : TIME;

sNetID: AMS network ID of the device (empty string or local network ID)

nWatchdogTimeS: Watchdog time in seconds, 0 = deactivated, >0 (max. 15300) = activated.

bExecute: The command is executed with a rising edge.

tTimeout: Indicates the time until the internal ADS communication is terminated.


    bEnabled : BOOL;
    bBusy    : BOOL;
    bError   : BOOL;
    nErrorId : UDINT;

bEnabled: TRUE = watchdog activated, FALSE = watchdog deactivated

bBusy: This output remains TRUE until the function block has executed a command.

bError: This output is switched to TRUE as soon as an error occurs during the execution of a command. It is reset to FALSE when a command is executed at the inputs.

nErrorId: 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:

    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);

(* 1st enable, then refresh watchdog every 1s *)
IF fbTimer.Q THEN
        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 *)


Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

IPCs with the mainboards CBxx63 and Embedded PCs CX51x0, CX20x0, CX20x2 with a BIOS version from 0.44 or higher

PLC Lib Tc2_System-Version