Monitoring code execution

When you suspect a block of code of not executing while it should, you can create a boolean variable that becomes true only if this code executes.

 

Example 1

Let’s say you have the following code snippet in which you expect the block of code in the third IF statement to execute.

if(condition 1)
{
    ...
    if(condition 2)
         {
        ...
        if(condition 3)
        {
            // code expected to execute
        }
        ...
    }
    ...
}

To test the correct execution of this block, simply create a variable called “executed” that you initialize at false. Set it to true inside the block of code to test. Finally watch its final value in a Digital Data:

  • If the final value is true, the code was executed
  • If the final value is false, the code was not executed
bool executed = false; // initialize to false

if(condition 1)
{
    ...
    if(condition 2)
         {
        ...
        if(condition 3)
        {
            executed = true; // set to true

                             // code expected to execute
        }
        ...
    }
    ...
}

// monitor variable in HITIPanel
HC_writeDigitalData(0, executed); // Digital Data 0

 

Example 2

Refer to this example : Watching variables and values.

 

Was this article helpful?
0 out of 0 found this helpful