Debug - Krystian-L-Lis/Stage GitHub Wiki

#Guide #Debug

Overview

The TwinCAT environment lacks a proper console. ADSLOGSTR and other similar functions are supposed to act like one, but the messages may arrive unordered and cannot carry additional information apart from what ADS allows. NewDebug is a tool that provides this functionality. The concept is very simple. Any function block that implements I_Debug interface, or other interfaces that extend it, can be sent to the debug buffer together with accompanying message. This can then be viewed through the IDE, just as you view any PLC variable, to what exactly send a debug message and in what order. This interface does not provide any additional functionality. This is far cheaper than storing a name reflection for each function block that require debug capabilities.

  • DebugMsg - a function that allows sending messages to the buffer.
  • DebugInfo - a function block that allows viewing the content of the debug buffers.
    • DebugInfo._msg - DebugMsg buffer.
    • DebugInfo._lastMsgIdx - the last entry in DebugInfo._msg..

Both buffers are ring buffers, meaning that when they are full, they will wrap to the first position.

Example:

PROGRAM Main
VAR
	signal: Signal;
	entity: EntityStart;
	tag: Tag;
	boolArg: BoolArg;
	mode: DebugMode := Panic;
	
	bInit: BOOL := TRUE;

	dbgInfo: DebugInfo;
END_VAR

IF bInit THEN
	DebugMsg(signal, mode, 'Any FB...');
	DebugMsg(tag, mode, '...that implements "I_Debug"...');
	DebugMsg(boolArg, mode, '...can be sent...');
	DebugMsg(entity, mode, '...to debug buffer.');

	// Check IDE.
	// Now "dbgInfo" should contain 4 entries
	// with a message and corresponding contexts.

	bInit := FALSE;
END_IF

Note: Use Param.DEBUGMSG_CAP and Param.DEBUGSTR_CAP to set how many messages can be stored in the corresponding ring buffers. For instructions on modifying library parameters, refer to Beckhoff Infosys.

Warning: The examples and use cases provided are for illustrative purposes and may require adaptation to your specific application.


< Previous | Home | Next >

⚠️ **GitHub.com Fallback** ⚠️