setTrace()
Changes the trace level of the current thread.
Synopsis
int setTrace(int traceLevel);
Parameters
Parameter | Description |
---|---|
traceLevel | Required trace level |
Return value
Always NO_TRACE
Errors
Invalid/incorrect argument
Description
setTrace() facilitates debugging in the CTRL by changing the trace level of the current thread. Comments and declarations do not generate an output. At the beginning of each output, the information about the script ID, thread ID, thread start function, the module and the panel path are returned.
If a manager was started with -dbg 29, the trace level EXECUTION_TRACE is automatically set on the execution of a control script. This is interesting for the user interface in particular, as not every script must be edited to set the trace level.
There are 3 constants:
Constants | Meaning |
---|---|
NO_TRACE | No tracing |
VERIFY_TRACE | Output of the line number and every statement that is executed |
EXECUTION_TRACE | Output of the line number and the statement with evaluated variables |
Example
-
1.) Source code:
main()
{
int oldTraceState; // Var. decl.: no trace output
int i;
oldTraceState=setTrace(VERIFY_TRACE); // Switch on trace
// --------------
i = 1; // Line no. 9
while(i++ < 3)
DebugN(i);
} // Trace is automatically switched off
-
a.) Output with VERIFY_TRACE:
WCCOAui1:--------------------------------------------------------------------- WCCOAui1:ScriptId: 4, ThreadId: 0, Thread Startfunction: main WCCOAui1: Module: _QuickTest_ WCCOAui1: Panel: C:\WinCC_OA_Proj\Test_040112\panels\setTrace.pnl [] WCCOAui1: Object: 0 named: "PUSH_BUTTON1" of type: PUSH_BUTTON WCCOAui1: Script: Clicked WCCOAui1: Line: 5 WCCOAui1: 5 oldTraceState = setTrace(1); WCCOAui1: 7 i = 1; WCCOAui1: 8 while ((i++ < 3)) WCCOAui1: 9 DebugN(i) WCCOAui1:[2] WCCOAui1: 8 while ((i++ < 3)) WCCOAui1: 9 DebugN(i) WCCOAui1:[3] WCCOAui1: 8 while ((i++ < 3)) WCCOAui1: 10 } |
-
b.) Output with EXECUTION_TRACE:
WCCOAui1:--------------------------------------------------------------------- WCCOAui1:ScriptId: 4, ThreadId: 0, Thread Startfunction: main WCCOAui1: Module: _QuickTest_ WCCOAui1: Panel: C:\WinCC_OA_Proj\Test_040112\panels\setTrace.pnl [] WCCOAui1: Object: 0 named: "PUSH_BUTTON1" of type: PUSH_BUTTON WCCOAui1: Script: Clicked WCCOAui1: Line: 5 WCCOAui1: 5 oldTraceState = setTrace(2); WCCOAui1: 7 i = 1; WCCOAui1: 8 while ((2++ < 3)) WCCOAui1: 9 DebugN(2) WCCOAui1:[2] WCCOAui1: 8 while ((3++ < 3)) WCCOAui1: 9 DebugN(3) WCCOAui1:[3] WCCOAui1: 8 while ((4++ < 3)) WCCOAui1: 10 } |
2.) Source code with loop with block:
main()
{
int oldTraceState; // Var. decl.: no trace output
int i;
oldTraceState = setTrace(EXECUTION_TRACE); // Switch on
trace
// --------------
i = 1; // Line no. 9
while(i <= 2)
{
i++;
}
DebugN(i);
} // Trace is automatically switched off
-
a.) Output with VERIFY_TRACE:
WCCOAui1:--------------------------------------------------------------------- WCCOAui1:ScriptId: 4, ThreadId: 0, Thread Startfunction: main WCCOAui1: Module: _QuickTest_ WCCOAui1: Panel: C:\WinCC_OA_Proj\Test_040112\panels\setTrace.pnl [] WCCOAui1: Object: 0 named: "PUSH_BUTTON1" of type: PUSH_BUTTON WCCOAui1: Script: Clicked WCCOAui1: Line: 5 WCCOAui1: 5 oldTraceState = setTrace(1); WCCOAui1: 7 i = 1; WCCOAui1: 8 while ((i <= 2)) WCCOAui1: 10 { WCCOAui1: 10 i++; WCCOAui1: 11 } WCCOAui1: 8 while ((i <= 2)) WCCOAui1: 10 { WCCOAui1: 10 i++; WCCOAui1: 11 } WCCOAui1: 8 while ((i <= 2)) WCCOAui1: 12 DebugN(i) WCCOAui1:[3] WCCOAui1: 13 } |
-
b.) Output with EXECUTION_TRACE:
WCCOAui1:--------------------------------------------------------------------- WCCOAui1:ScriptId: 4, ThreadId: 0, Thread Startfunction: main WCCOAui1: Module: _QuickTest_ WCCOAui1: Panel: C:\WinCC_OA_Proj\Test_040112\panels\setTrace.pnl [] WCCOAui1: Object: 0 named: "PUSH_BUTTON1" of type: PUSH_BUTTON WCCOAui1: Script: Clicked WCCOAui1: Line: 5 WCCOAui1: 5 oldTraceState = setTrace(2); WCCOAui1: 7 i = 1; WCCOAui1: 8 while ((1 <= 2)) WCCOAui1: 10 { WCCOAui1: 10 1++; WCCOAui1: 11 } WCCOAui1: 8 while ((2 <= 2)) WCCOAui1: 10 { WCCOAui1: 10 2++; WCCOAui1: 11 } WCCOAui1: 8 while ((3 <= 2)) WCCOAui1: 12 DebugN(3) WCCOAui1:[3] WCCOAui1: 13 } |
-
3.) Function call
main()
{
int i = 2;
int a;
int oldTraceState; // Var. decl.: no trace output
oldTraceState=setTrace(VERIFY_TRACE); // Switch on trace
a = fkt2(i); // // Line no. 8
fkt(a); // // Line no. 7
DebugN(i); // // Line no. 11
}
// --------------
int fkt(int a)
{ // // Line no. 17
a = a * a;
DebugN("fkt", a);
return(a);
}
// --------------
int fkt2(int i)
{ // // Line no. 28
i = i + i;
DebugN("fkt2", i);
return(i);
}
-
a.) Output with VERIFY_TRACE:
WCCOAui1:--------------------------------------------------------------------- WCCOAui1:ScriptId: 4, ThreadId: 0, Thread Startfunction: main WCCOAui1: Module: _QuickTest_ WCCOAui1: Panel: C:\WinCC_OA_Proj\Test_040112\panels\setTrace.pnl [] WCCOAui1: Object: 1 named: "PUSH_BUTTON2" of type: PUSH_BUTTON WCCOAui1: Script: Clicked WCCOAui1: Line: 7 WCCOAui1: 7 oldTraceState = setTrace(1); WCCOAui1: 29 { WCCOAui1: 29 i = (i + i); WCCOAui1: 30 DebugN("fkt2",i) WCCOAui1:["fkt2"][2] WCCOAui1: 31 return i; WCCOAui1: 32 } WCCOAui1: 8 a = fkt2(i); WCCOAui1: 9 fkt(a) WCCOAui1: 19 { WCCOAui1: 19 a = (a * a); WCCOAui1: 20 DebugN("fkt",a) WCCOAui1:["fkt"][4] WCCOAui1: 22 return a; WCCOAui1: 23 } WCCOAui1: 11 DebugN(i) WCCOAui1:[1] WCCOAui1: 12 } |
-
b.) Output with EXECUTION_TRACE:
WCCOAui1:--------------------------------------------------------------------- WCCOAui1:ScriptId: 4, ThreadId: 0, Thread Startfunction: main WCCOAui1: Module: _QuickTest_ WCCOAui1: Panel: C:\WinCC_OA_Proj\Test_040112\panels\setTrace.pnl [] WCCOAui1: Object: 1 named: "PUSH_BUTTON2" of type: PUSH_BUTTON WCCOAui1: Script: Clicked WCCOAui1: Line: 7 WCCOAui1: 7 oldTraceState = setTrace(2); WCCOAui1: 29 { WCCOAui1: 29 i = (1 + 1); WCCOAui1: 30 DebugN("fkt2",2) WCCOAui1:["fkt2"][2] WCCOAui1: 31 return 2; WCCOAui1: 32 } WCCOAui1: 8 a = fkt2(1); WCCOAui1: 9 fkt(2) WCCOAui1: 19 { WCCOAui1: 19 a = (2 * 2); WCCOAui1: 20 DebugN("fkt",4) WCCOAui1:["fkt"][4] WCCOAui1: 22 return 4; WCCOAui1: 23 } WCCOAui1: 11 DebugN(1) WCCOAui1:[1] WCCOAui1: 12 } |
Assignment
Miscellaneous functions
Availability
UI, CTRL