LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"Break execution" seems not to work in Interactive Window

Solved!
Go to solution

Using, e.g., this simple example

 

#include <ansi_c.h>
static int i = 0;
for ( i = 0;
i < 1000000;
i ++ )
printf ("i: %d\n", i );

 

I am unable to stop program execution in the Interactive Window using the "Terminate Execution" button.

(CVI2017)

0 Kudos
Message 1 of 5
(2,292 Views)
Solution
Accepted by topic author Wolfgang

This looks like a race condition between active windows. Every time you call printf(), the default behavior is to make stdio the active window. In your code snippet, i think this is happening so fast that CVI doesn't actually get the buttonclick because it is no longer the active window.

 

Both of these modifications to your code snippet support my theory:

#include <ansi_c.h>
#include <utility.h>
static int i = 0;
for ( i = 0;
i < 10000;
i ++ ){
printf ("i: %d\n", i );
Delay(.05); //gotta be quick!
}
#include <ansi_c.h>
#include <utility.h>
static int i = 0;
SetStdioWindowOptions(10000,0,0);
for ( i = 0;
i < 10000;
i ++ ){
printf ("i: %d\n", i );
}

You can also use DebugPrintf() instead and the CVI window remains active.

 

I could file a CAR about this, but realistically I don't know how much we can do about it.

  • We could change the default StdioWindowOptions for interactive executions, but this would be undesirable for anyone who doesn't want to click between windows.
  • We could artificially slow down the interactive execution Smiley Sad

I'd rather have the current behavior that either of those.

~Trent

https://www.linkedin.com/in/trentweaver
Message 2 of 5
(2,264 Views)

Thanks Trent! Yes I agree with you, it is the same problem if the code is run from within CVI and thus has nothing to do with the Interactive Window.

But now: why does

 

#include <ansi_c.h>
#include <utility.h>
static int i = 0;
for ( i = 0;
i < 10000;
i ++ ){
DebugPrint ("i: %d\n", i );
}

 

give the build error  

7, 1    error: implicit declaration of function 'DebugPrint'. Make sure that you include the function prototype.

whereas your example works well - both functions Delay and DebugPrintf need utility.h?

0 Kudos
Message 3 of 5
(2,255 Views)

Yes, both of those functions need utility.h. I think that build error is because you're missing the 'f' in DebugPrintf:


@Wolfgang wrote:

 

...

#include <ansi_c.h>
#include <utility.h>
static int i = 0;
for ( i = 0;
i < 10000;
i ++ ){
DebugPrint ("i: %d\n", i );
}

 


 

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 4 of 5
(2,252 Views)

Smiley Embarassed

OK, now problem is solved, thanks again! I guess I will tell students to use DebugPrintf instead of printf to avoid this kind of problem.

0 Kudos
Message 5 of 5
(2,249 Views)