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.