Warm Resetting and Restarting a Wago PLC via the Reset PB at the Visualization screen

I am using a 750-8111, Codesys 3.5 and need to do a warm reset and have the PLC to restart automatically via a reset push button in a visualization screen.

I have tried Systems events, “StopDone”, but after the PLC restarts, the K-bus icon comes back faulty, and do not recognized none of the installed IO modules. The error says “no driver for devices”, and IO doesn’t work in the code. After cycling the power, the PLC is back to normal.

Here is the current routine I am using to restart the PLC:

// Trigger logic
IF GVL_1.xSFCReset THEN
GVL_1.xSFCReset := FALSE; // Clear trigger
xResetTriggered := TRUE; // Set internal flag for reboot
fbTimer(IN := FALSE); // Reset timer initially
END_IF;

// Wait 1 second before triggering reboot to ensure graceful shutdown
IF xResetTriggered THEN
fbTimer(IN := TRUE, PT := T#10S);
pApp := AppGetCurrent(ADR(hProcess));
IF fbTimer.Q THEN
// Execute Linux reboot command safely
hProcess := SysProcessExecuteCommand2(
pszCommand := (Command),
pszStdOut := (StdOut),
udiStdOutLen := 1024,
pResult := ADR(Result)
);
fbTimer(IN := FALSE);
xResetTriggered := FALSE; // Clear flag to avoid loops
END_IF;
END_IF;

//============ Previous Code ==================================//
I also tried the one below, and gave the the same K-bus error

IF GVL_1.xSFCReset THEN
GVL_1.xSFCReset := FALSE; // Immediately clear trigger

// Obtain pointer to the current application
pApp := AppGetCurrent(ADR(Result));

IF pApp <> 0 THEN
    AppReset(pApp, 16#0001);            // Warm reset the PLC(16#0001), stops app       
END_IF;

END_IF;

Thank you for your assistance

Hello,
Personally I’m using a different approach:
First I’ve declared this event:
image
Which call this function:

FUNCTION FuSystemResetDone : DWORD
VAR_IN_OUT
	{attribute 'analysis' := '-33'}
	EventPrm: CmpApp.EVTPARAM_CmpAppReset;
	{attribute 'analysis' := '+33'}
END_VAR
VAR
END_VAR
-----------------------------------------------------------------------------
GVL_SYSTEM.oWagoAppCtrl.AttachToApplication(''); // attach to own application
IF GVL_SYSTEM.oWagoAppCtrl.xIsAttached THEN
	GVL_SYSTEM.oWagoAppCtrl.StartApplication();
END_IF;

The Reset itself is done by this program:

PROGRAM prgSystemReset
VAR
	_xInitialized				: BOOL;
		_sAppName				: STRING;
END_VAR
---------------------------------------------------------------------------------
GVL_SYSTEM.oWagoAppCtrl(); // cyclic operation for updating outputs

IF NOT(_xInitialized) THEN
	GVL_SYSTEM.oWagoAppCtrl.AttachToApplication(''); // attach to own application
	IF GVL_SYSTEM.oWagoAppCtrl.xIsAttached THEN
		_xInitialized := TRUE;
	END_IF;
ELSE
	_sAppName := GVL_SYSTEM.oWagoAppCtrl.getAppName(); // find out your own name
	IF GVL_SYSTEM.xReset THEN
		IF GVL_SYSTEM.xFactory_Reset_Cold THEN
			GVL_SYSTEM.oWagoAppCtrl.ResetApplicationCold();
		ELSE
			GVL_SYSTEM.oWagoAppCtrl.ResetApplicationWarm();
		END_IF;
	END_IF;
END_IF;

Edit: Add the GVL_SYSTEM list

{attribute 'qualified_only'}
VAR_GLOBAL
	oWagoAppCtrl				: WagoAppControl.FbWagoApplicationControl;
	xReset						: BOOL;
	xFactory_Reset_Cold			: BOOL;
END_VAR

Merci Christophe. Tu vas toujours au-delà.

No problem, I’ve taken some time to have it work on my side and I would rather share what I know instead of having someone else loosing time on this :slight_smile:

1 Like