11-17-2009 11:24 AM
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.
Solved! Go to Solution.
11-17-2009 12:27 PM
Could you run through this list of 7 possible causes (from KnowledgeBase) and see if any of those are causing it?
11-17-2009 01:19 PM
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.