LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

error code -50103. Program crashes after starting task, analog read, and clearing task.

Solved!
Go to solution

I'm having difficulty with this single analog read. The situation is as follows. I have a thread that runs a task. The task is running for continuous acquisition, but occasionally based on

a button push from the GUI I need a single analog read from a single channel. I first stop the first task and then create the next task take the reading and clear and stop it.

This function is also being called via a timer to get a temperature and resistivity reading. The timer calls are interested in the temperature and the button push wants the resistivity.

Its the same function but can be called at two different instances. I put in a thread safe variable to make sure that it waits for each other before reading again. It doesnt crash right away,

it crashes randomely at approximately the 6th or 7th instance of the analog read.

 

My first guess after reading the LABVIEW forum on ni.com is that it doesnt like when I start and clear the task over and over. Here is the fucntion being called with some handshaking going on, but the

key area to look at is the analog read. The handshaking stops the task running in the thread momentarily to take the analog read and then starts it again.

 

I'm using CVI v9.0. I'm using the USB 6259 DAQ. The bold area below is where the error occurs.

 

 

 

 

int daq6259ReadCuvette(float64 data[2])
{         
 int32 daqError = 0;    //DAQmx error code
 char errorMsg[ERRORMSGSIZE]; //error message
 int start = 0;     //start time
 int elapsed = 0;    //elapsed time
 float64* cuvetteData;     //data
 int32 numRead = 0;    //number of analog reads
 errorCluster localError={0}; //local error structure to store error info
         //allocate memory for cuvette data
 if((cuvetteData = (float64*)malloc(NUMCUVCHANNELS*sizeof(float64))) == NULL)
 {            //memory allocation failed
  errorEnqueue(1,-1,__LINE__,__FILE__,"Cuvette DAQ Task Memory Allocation Failed");  
  return -1;
 }

 cuvetteReady(1); //set ready flag = 1 to stop daq1 task in daq1 Thread
 start = clock(); //set a start time
 
 while(cuvetteReady(2))   //poll for cuvette handshaking or timeout if wait is > 5000 ms
 {
  if(gMpvsError)
   return -1;
  Sleep(100);     //sleep 1 ms to save processor usage
  //WAIT FOR SYSTEM 1 DAQ LOOP TO STOP
  elapsed = clock() - start;
  if(elapsed >= 5000)   //check for 5 sec timeout while stopping daq1 task
  {
   errorEnqueue(1,-1,__LINE__,__FILE__,"Unable to Stop DAQ Device, Cuvette was not read");
   cuvetteReady(1);  //set ready = 1 signal to restart daq1 task in daq1 Thread
   return -1;    //return -1 as standard error code
  }
 }
 
 //TAKE CUVETTE READING!!
 if((daqError = DAQmxCreateTask("",&gCuvetteTask)) == 0)    //create cuvette read task
 {                 //create voltage channel
  if((daqError = DAQmxCreateAIVoltageChan(gCuvetteTask,cuvChan,"",DAQmx_Val_RSE,
   MINVOLT,MAXVOLT,DAQmx_Val_Volts,NULL)) == 0)
  {                //DAQmx analog read
   if((daqError = DAQmxReadAnalogF64(gCuvetteTask,1,10,DAQmx_Val_GroupByScanNumber,
    cuvetteData,1*NUMCUVCHANNELS,&numRead,NULL)) == 0)
   {
    if((daqError = stop6259DaqTask(&gCuvetteTask)) != 0)
    {
     DAQmxGetErrorString(daqError, errorMsg, 256);
     errorEnqueue(2, daqError, __LINE__, __FILE__, errorMsg);
    }
    if((daqError = DAQmxClearTask(gCuvetteTask)) != 0)
    {
     DAQmxGetErrorString(daqError, errorMsg, 256);
     errorEnqueue(2, daqError, __LINE__, __FILE__, errorMsg);
    }
   }
  }
 }
 //set ready = 1 signal to restart daq1 task in daq1 thread. This will exit the while loop
 //in threadManagement waiting for the cuvette task to read the cuvette.
 cuvetteReady(1);
 
 if(daqError != 0)     //check for DAQmx Error
 {
  DAQmxGetErrorString(daqError,errorMsg,256);
  errorEnqueue(1,daqError,__LINE__,__FILE__,errorMsg);
  return error;
 }
 
 if(numRead > 0)       //set data values from cuvette read
 {     
  data[0] = cuvetteData[0];   //resistivity value
  data[1] = cuvetteData[1];   //temperature value
 }

 return 0;        //no errors operation completed
}

 

 

It has been crashing at the same point over and over. Essentially in order to reproduce this scenario You need a thread running with a task running continuously, then you want to stop it and

start a new task with a single analog read.

Monil Morar
Control System Engineer
Secure Drilling Services (SDS)
Weatherford │ 16430 Park Ten Place │ Suite 200 │ Houston │ Texas │ 77084
0 Kudos
Message 1 of 3
(3,820 Views)
Solution
Accepted by mdmorar

Could you run through this list of 7 possible causes (from KnowledgeBase) and see if any of those are causing it?

 

 

0 Kudos
Message 2 of 3
(3,815 Views)

Yea I think it might be one of these. Probably the last one. I'm going to try to implement it differently.

Thanks for your help.

 

Monil Morar
Control System Engineer
Secure Drilling Services (SDS)
Weatherford │ 16430 Park Ten Place │ Suite 200 │ Houston │ Texas │ 77084
0 Kudos
Message 3 of 3
(3,806 Views)