LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NICAIU.DLL error on DAQmxRegisterEveryNSamplesEvent

Hi all,

I have prepared a DLL (CVI 8.1) for use in TestStand (3.5) to sample digital inputs triggered on a single port bit (NI6254).
It should run for a given time - I call it monitoring and it's done in the background while TestStand executes
further steps.
It runs quite good, but whenever the DLL shall be unloaded, either forced manually or after sequence is going to be closed,
it blocks the DAQmx system (8.6.1f0) and further runs lead into an error (see below).

Please have a look at the reduced code...

void DllExport __stdcall ReadMonitor_DigIn(...)
{
  ...
  error = DAQ_DigInMonitor("/Dev1/port0/line1");
  ...
}

static int DAQ_DigInMonitor(char *trigger)
{
    int error=0;

    DAQmxErrChk (DAQmxCreateTask(NULL,&Task));
    DAQmxErrChk (DAQmxCreateDIChan(Task, trigger, NULL, DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxCfgChangeDetectionTiming(Task,trigger,NULL,DAQmx_Val_ContSamps,1));
    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(Task,DAQmx_Val_Acquired_Into_Buffer,1,0,SampleCallback,NULL));
    // DAQmxRegisterEveryNSamplesEvent doesn't ever return an error code !
    DAQmxErrChk (DAQmxStartTask(Task));
    return 0;
Error:
    Cleanup();
    return error;
}

int32 CVICALLBACK SampleCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
   return 0;
}


// called from other DllExport functions and from DllMain->DLL_PROCESS_DETACH
static int Cleanup(void)
{
  int error=0;

  if( Task != 0 ) {
    DAQmxErrChk (DAQmxStopTask(Task));
    // useless: DAQmxWaitUntilTaskDone(Task, 10.0);
    // useless: DAQmxTaskControl(Task, DAQmx_Val_Task_Abort);
    // this is a recognized UNREGISTER !
    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(Task,DAQmx_Val_Acquired_Into_Buffer,1,0,NULL,NULL));
    DAQmxErrChk (DAQmxClearTask(Task));
    // useless: DAQmxTaskControl(Task, DAQmx_Val_Task_Unreserve);
    Task = 0;
  }
Error:
  return error;
}

void DllExport __stdcall Clear(void)
{
    ...
    Cleanup();                              // try to stop Tasks softly and release objects
}

Calling ReadMonitor_DigIn(), Waiting, Calling Clear() runs in TestStand without error.
The Task stuff seems to be stopped and cleared in the right way.
The example can be run multiple times in TestStand, as long as the DLL won't be unloaded.
If I do so, the next run results in the error:
    Unable to load NI-DAQmx dynamic link library NICAIU.DLL
    Ensure that NI-DAQmx is installed on your machine.
    -200397; User-defined error code.
on the first step that uses the DAQmx system.
This problem disappears, if I disable the DAQmxRegisterEveryNSamplesEvent function,
although the callback won't ever be called ! It seems, that the Task generated by this function
won't be discarded when clearing the Task.

This kept me going for quite a long time now and I'm totally out of ideas.
I appreciate any kind of help or idea - please help.

Message 1 of 3
(4,880 Views)

Hi,

 

I know this problem was stated quite far back now but it did not receive any answers so I am replying to this thread as I am having  similar problems.

 

I had 8.1.0f1 installed and everything worked fine.

 

Unfortunately I upgraded to 9.0.2f0 and I am expreriencing similar problems with johnbob.

 

I load the NICAIU.dll, then I create an analogue input and output task which I register an event on each task.

This works fine throughout the program but when I stop and clear the tasks and Unload the dll then I cannot reload it again.

the LoadLibrary  function fails thus I presume that the entry point to the dll returns false.

If I do not register an event there does not seem to be any problem at all.

 

I have searched throughout the release notes for new releases after 8.1.0f1 but I could not find anything that might signify what has changed.

 

Thanks for any help.

 

 

 

0 Kudos
Message 2 of 3
(4,248 Views)

Hello -

 

I think that what you are seeing is a known issue and should be resolved in version 9.1 of DAQmx.  The reference ID is 189387 and is referenced in the DAQmx 9.1 Readme.

 

NickB

National Instruments 

0 Kudos
Message 3 of 3
(4,240 Views)