I call the ChangeDetection feature of the NI USB-6525 with the following C code in a C++ program:
DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"Dev1/port1/line0","",DAQmx_Val_ChanPerLine)); DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle,"Dev1/port1/line0","Dev1/port1/line0",DAQmx_Val_FiniteSamps,1)); DAQmxErrChk (DAQmxRegisterSignalEvent(taskHandle,DAQmx_Val_ChangeDetectionEvent,0,ChangeDetectionCallback,NULL)); DAQmxErrChk (DAQmxGetTaskNumChans(taskHandle,&numLines)); DAQmxErrChk (DAQmxStartTask(taskHandle));
As far as I understand, this creates a separate thread that sets the USB-6525 into ChangeDetection mode. When the device detects a signal change, the C++ program calls a function (called ChangeDetectionCallback() in this case), which runs in its own thread (or perhaps the same thread, but in any case not the thread used to call the above code). That's explained here and is due to the "0" argument in DAQmxRegisterSignalEvent().
What I'd like to know is: while this thread is running (either the one created by one of the above functions or the one that ChangeDetectionCallback() runs in), is it ok to exit the program? Could there potentially be any problems resulting from unfreed resources, for example? Are there any steps I should take to ensure everything exits properly, like making sure to always call DAQmxStopTask() and DAQmxClearTask() before exiting the program?