Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxLoadTask returns -200089

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);
 
0 Kudos
Message 1 of 2
(3,725 Views)
Hello D_Ss,

The DAQmx_Sys_DevNames attribute that is read from the DAQmxGetSystemInfoAttribute function returns an array that contains the names of all tasks saved on the system.  This means that it is only returning a list of all static tasks that are saved in Measurement & Automation Explorer (MAX).  The task that you are creating in your program is local to that application, and it will not be returned in the list. 

If you want to abort any and all tasks associated with a particular device, you can use the
DAQmxResetDevice function at the start of your program.  This will release any resources that were reserved by these tasks. 

Hope this helps!

Best regards,
0 Kudos
Message 2 of 2
(3,713 Views)