LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Application crash during DAQmx loop

Hello,

 

I have a small program that basically polls 8 analog inputs from a USB-6008 DAQ box. I am just looking for the value to fall below 2v. The program will keep looping until the state of the on/off switch is toggled.

 

The problem I am having is this: When this program is executed on my machine, it works fine. Once I compile and install it onto a secondary machine, it runs fine for about 10 minutes then just locks up and no longer processes the input to the DAQ. Am I doing something fundamentally wrong in my loop? Should I approach this polling in a completely different way? I am having issues attaching my C file, so here is a condensed version of the loop. The full loop just does the same thing 8 times to check all 8 inputs.

 

Thank you in advance,

Kraig

 

int CVICALLBACK START (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
	{
		case EVENT_COMMIT:

			StartTime = Timer();
			double FailTime = 0;
			CreateDAQTaskInProject (&myTask);
	
	    			/* variables/counters */
				int i = 0;
				int panel1count = 0;
				int panel1flag = 0;
				int CurrentState = 0;
				GetCtrlVal(panelHandle,PANEL_STARTBUTTON,&CurrentState);
				while(CurrentState == 1){
					GetCtrlVal(panelHandle,PANEL_STARTBUTTON,&CurrentState);
					ProcessSystemEvents();
					DAQmxReadAnalogF64(myTask, -1, 10, DAQmx_Val_GroupByChannel,read_array,arraysize,&samplesperchannelread,NULL);
					for(i = 0;i<100;i++){
						if(read_array[i] < 2){
							if(panel1flag == 0){
								panel1count++;
								if (panel1count == 2){
									FailTime = Timer() - StartTime;
									SetCtrlVal(panelHandle,PANEL_PANEL1TIME,FailTime);	
								}
							}
							i=100;
							panel1flag = 1;
							SetCtrlVal(panelHandle,PANEL_PANEL1,panel1count);
						}
						else{
							panel1flag = 0;
						}
					}
					
	           	}
			
			break;
	}
	return 0;
}

 

 

0 Kudos
Message 1 of 2
(2,726 Views)

If I were you, I would do the polling operation in a completely seperate thread.

Unwritten rules that I generally follow says that "callbacks should exit as soon as possible".

 

Other than that, you need a way to debug your code. You have to see at which point it is stuck.

For this purpose, you may sprinkle printf statements over your code.

 

This helps you understand what your code is doing at any moment. You can also print data values, function returns etc.

If you find out where it is failing, it is more likely that you will find a solution from the forum.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 2
(2,723 Views)