LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

what is good programming practice in CVI for test loops?

I am writing a test program in CVI 7.1 wherein the test takes ~ 15 minutes to run and wherein I would like to change 2 different test parameters and run the test again. I would like to know if the following is considered good programming practice and what is the optimal Delay. Also, are there any recommendations for good books (or app notes) on how best to architect a Windows style program. Here's my first guess how to do the program:
I have variables A and B which I need to vary.

void RunTestLoop(int A, int B)
{
for( a=0; a < A; a++)
{
Set_A(a);
for (b=0; b {
Set_B(b);
Run_Test();
while(!TestComplete) // is it ok to just stay in this loop, waiting for the other event driven
{ // stuff to complete?
ProcessSystemEvents();
Delay(0.5); // is this Delay ok?
} // end while(!TestComplete)
} // end for (b=0; b } // end for( a=0; a < A; a++)
}
Thanks in advance
0 Kudos
Message 1 of 6
(3,391 Views)
Rather than using Delay(0.5) I would use something like this..

Timer_Delay(0.5);

void Timer_Delay(float time)
{
double timer;

timer = Timer();
do
{
ProcessSystemEvents();
}while((Timer() - timer) < time);
}
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
Message 2 of 6
(3,385 Views)
thanks Sheetal, but what is the benefit of doing it with the timer function?
And how about the rest of the code. Is the general concept in line with good programming practice?
0 Kudos
Message 3 of 6
(3,378 Views)
Timer_Delay will not "halt" your current thread.
here is how I have been doing for years.

void test(void)
{
int total_loop = 50; //optional
int pass = 0;
int fail = 0;


do
{
wait_till_start_signal_is_received(); //this may always return "go"

do
{
result = test_1();
if(result != PASS)
{
break;
}

test_2();
if(result != PASS)
{
break;
}

test_n();
if(result != PASS)
{
break;
}
}while(0);

if(result == PASS)
{
pass++;
}
else
{
fail++;
}

loop++;
ProcessSystemEvents();
}while(exit_program == 0 && loop < total_loop); //"&& loop < total_loop" is optional

}
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 4 of 6
(3,374 Views)
> I would like to know if the following is considered good programming practice

No real comment on the functionality of the function call, but as good programming practice goes I would use more descriptive variable names. Ideally the names should mirror what thier actual purpose is. Reading your sniplet (a, A, _A) is very confusing to look at. If the variables a loop call it a loop (ie OutterLoop, Counter, etc). You will find in the long run it will save both time and trouble. Especially if you get it running and a half year down the road you need to come back and make modifications or if someone else gets hired later and needs to modify the code you wrote. If you dont document functions well or use descriptive names for your variables youll come back to your code later and not be able to read it or tell what its doing...
0 Kudos
Message 5 of 6
(3,336 Views)
thanks Maelstrom.
I was just trying to show a quick example of what I needed to do, not write code.
But my my experience has been mostly with in line programs, so I am looking for some good advice
on how to properly architect event driven programs.
0 Kudos
Message 6 of 6
(3,333 Views)