Codesys 3.5 - Program exception

Hi all,

strange question - but does anyone know how to make a program that will create an exception and stop the PLC?
I’ve encountered this and would like to recreate this to be able to test some communication settings.

Hello bjornidar,

you will find various options in the following video.

2 Likes

I use a division by zero.
var = 1 / 0;

2 Likes

You can use this to create your own exception and stop the PLC:

Variable declaration:

// Add CmpApp.library, SysExcept.library and SysTypes2_Itf as newest.
VAR
	_pApp	: POINTER TO CmpApp.APPLICATION;
	_result	: SysTypes.RTS_IEC_RESULT;
END_VAR

Code:

_pApp := AppGetCurrent(pResult:=_result);
IF _pApp <> 0 THEN
	// Modify the RtsExceptions.[xxx] to match what exception your want to throw.
	AppGenerateException(pApp:=_pApp, ulException:=RtsExceptions.RTSEXCPT_ARRAYBOUNDS);
END_IF

Thanks for all the feedback!
I’ve now been able to address the issues I had when the PLC went to exception.

Now to the root cause of this investigation, has anyone any experience with a similar exception like the one below?
Which seems to have happened at the same time as a user logged out of the Visu.

Oct 28 19:23:08 localhost codesys3: IECVisualization DEBUG Visu_PRG: Creating Client for Extern-ID: 2085154864
Oct 28 19:23:08 localhost codesys3: IECVisualization DEBUG Visu_PRG: Creating Client successful for Extern-ID: 2085154864 Returned IEC-ID: 0
Oct 28 19:24:00 localhost codesys3: CmpUserMgr DEBUG Login (4)
Oct 28 19:24:00 localhost codesys3: CmpDevice DEBUG Device Login from 0002 successful
Oct 28 19:24:00 localhost codesys3: CmpUserMgr DEBUG Login (4)
Oct 28 19:24:00 localhost codesys3: CmpDevice DEBUG Device Login from 0002 successful
Oct 28 19:24:00 localhost codesys3: IECVisualization DEBUG Visu_PRG: Creating Client for Extern-ID: 2171002870
Oct 28 19:24:00 localhost codesys3: IECVisualization DEBUG Visu_PRG: Creating Client successful for Extern-ID: 2171002870 Returned IEC-ID: 2
Oct 28 19:26:53 localhost codesys3: IECVisualization DEBUG VisuFbFrameBase.SetInputPositionData: The element id for the input position cannot be determined
Oct 28 19:26:57 localhost codesys3[879]: Last message 'IECVisualization DEB' repeated 1 times, suppressed by syslog-ng on EC752-23C001-PLC.localdomain.lan
Oct 28 21:28:33 localhost codesys3: CmpUserMgr DEBUG Logout (3)
Oct 28 21:28:33 localhost codesys3: CmpUserMgr DEBUG Logout (2)
Oct 28 21:28:33 localhost codesys3: IECVisualization DEBUG Visu_PRG: Successfully Removed Client with IEC-ID: 0, Extern-ID: 2085154864
Oct 28 21:28:33 localhost codesys3: SysExcept EXCEPTION runtime received SIGABRT - system may be in an inconsistent state

**** We recommend a reboot of the controller now! ****
Oct 28 21:28:33 localhost codesys3: TscWagoStatusProvider DEBUG Controller State Changed RUN -> EXCEPTION
Oct 28 21:28:33 localhost codesys3: CmpIecTask EXCEPTION *EXCEPTION* [<excpt>NonContinuable</excpt>] occurred: App=[<app>Application</app>], Task=[<task>VISU_TASK</task>]
Oct 28 21:28:33 localhost codesys3: CmpIecTask EXCEPTION *EXCEPTION POSITION*: IP=<ip>0x(nil)</ip> (no IEC context could be retrieved)
Oct 28 21:28:40 localhost codesys3: CmpUserMgr DEBUG Logout (1)
Oct 28 22:20:46 localhost codesys3: CmpApp DEBUG App [Application] Start successful
Oct 28 22:20:52 localhost codesys3: CmpApp DEBUG App [Application] Start successful
Oct 28 22:21:00 localhost codesys3[879]: Last message 'CmpApp DEBUG App [Ap' repeated 1 times, suppressed by syslog-ng on EC752-23C001-PLC.localdomain.lan
Oct 28 22:21:27 localhost codesys3: CmpApp DEBUG App [Application] Logout successful
type or paste code here

I think this is more for the Technical Support at WAGO.

1 Like