Hi I am running from interactive execution.
If my program crashes at POINT A labeled below (I terminate exectution before the DAQmxClearTask (taskhandle) is run) then I cannot run again. I added code at POINT B which was to see if there is a "system" task with my name already and that never returns anything. I also added code at POINT C which was to get the handle of my "task" and then to clear it. This never returns a handle to "task" even though at POINT D it complains that task "task" already exists and gives error code -200089 from then on.
How do I unload this task?
Thanks
#include <ansi_c.h>
#include <NIDAQmx.h>
static int32 err;
static TaskHandle taskhandle=0;
static int size;
static int actual_size;
static double array[60000];
static int i;
static int j;
static int start;
static int end;
#include <utility.h>
static int number_of_channels=0;
static double average[10];
static double deliberate_offset;
static char *taskarray,*devicearray;
static int device_available;
static char dummy[100];
device_available = 0;
err = DAQmxGetSystemInfoAttribute (DAQmx_Sys_DevNames, dummy, 0);
if(err>0)
{
devicearray = calloc(err,sizeof(char));
err = DAQmxGetSystemInfoAttribute (DAQmx_Sys_DevNames, devicearray, err);
if(strstr(devicearray,"Dev1") != NULL) device_available = 1;
free(devicearray);
}
err = DAQmxGetSystemInfoAttribute (DAQmx_Sys_Tasks, dummy, 99);
//POINT B
//RETURNS 0 so there is no tasks
if(err>0)
{
taskarray = calloc(err,sizeof(char));
err = DAQmxGetSystemInfoAttribute (DAQmx_Sys_Tasks, taskarray, err);
if(strstr(taskarray,"task") != NULL)
{
err = DAQmxLoadTask ("task", &taskhandle);
err = DAQmxClearTask (taskhandle);
}
free(taskarray);
}
//POINT C
//RETURNS 0 for handle and does not work
err = DAQmxLoadTask ("task", &taskhandle);
err = DAQmxClearTask (taskhandle);
deliberate_offset = 0.00;
number_of_channels=0;
size =1000;
//POINT D
err = DAQmxCreateTask ("task", &taskhandle);
err = DAQmxCreateAIVoltageChan (taskhandle, "Dev1/ai0", "", DAQmx_Val_RSE, -10,10, DAQmx_Val_Volts, "");
number_of_channels++;
err = DAQmxCreateAIVoltageChan (taskhandle, "Dev1/ai1", "", DAQmx_Val_RSE, -10,10, DAQmx_Val_Volts, "");
number_of_channels++;
err = DAQmxCreateAIVoltageChan (taskhandle, "Dev1/ai2", "", DAQmx_Val_RSE, -10,10, DAQmx_Val_Volts, "");
number_of_channels++;
err = DAQmxReadAnalogF64 (taskhandle, size, 1.0, DAQmx_Val_GroupByChannel, array, size*3, &actual_size,NULL);
start = 0;
end = size;
for(j=0;j<number_of_channels;j++)
{
average[j] = 0.0;
for(i=start; i<end; i++)
{
average[j] += array[i];
}
average[j] = average[j] / size;
start += size;
end = start+size;
printf("%f\n",average[j]);
}
printf("\n");
//POINT A
DAQmxClearTask (taskhandle);