01-14-2020 03:47 PM
Hello everyone,
I am using ni daqmx on a project where I need to use several CO tasks. Due to the fact that I need to update the parameters of those CO tasks and I don't want to clear and recreate the tasks so I chose to use DAQmxTaskControl with DAQmx_Val_Task_Unreserve action. However, it does not work. I didn't get any error for those taskcontrol codes but the resources are still reserved by the tasks and not available for reuse. The platform I implemented the daqmx is Matlab. May I know the reason why those resources are not released after DAQTaskControl(task_handle1, DAQmx_Val_Task_Unreserve) is used?
01-14-2020 04:33 PM
More details please?
I'm pretty sure you need to at least *stop* the task before unreserving would have any effect. I'd expect an error (or at least a warning) from trying to unreserve a task that's still in run state.
The sequence Stop-->Unreserve-->Reconfig-->Restart should be faster than Stop-->Clear-->Recreate-->Reconfig-->Restart. However, depending on the extent of the Reconfig, it may well be in the same order of magnitude.
Exactly what params are you looking to change and why? Some CO params are available to change while the task continues running.
-Kevin P
01-14-2020 05:06 PM
I stopped the task before unreserving resources but still got the same issue. I know CO task can be reconfigured through property modification, but it is convenient to have this function working.
The code sample in matlab:
clear
clc
close all
DAQResetDevice('PXI1Slot3');
task_handle = DAQCreateTask('0');
DAQCreateCOPulseChanFreq(task_handle, '/PXI1Slot3/ctr1', 0, 10000, 0.5);
DAQSetRefClkSrc(task_handle , '/PXI1Slot3/PXIe_Clk100');
DAQCfgImplicitTimingFiniSamps(task_handle, 1);
task_handle1 = DAQCreateTask('2');
for i=1:2
DAQCreateCOPulseChanFreq(task_handle1, '/PXI1Slot3/ctr0', 0, 100000, 0.5);
DAQSetRefClkSrc(task_handle1, '/PXI1Slot3/PXIe_Clk100');
DAQCfgImplicitTimingFiniSamps(task_handle1, 2000);
DAQCfgDigEdgeStartTrig(task_handle1,'/PXI1Slot3/Ctr1InternalOutput',DAQmx_Val_Rising);
DAQStartTask(task_handle1);
DAQStartTask(task_handle);
DAQWaitUntilTaskDone(task_handle1,-1);
DAQStopTask(task_handle);
DAQStopTask(task_handle1);
DAQTaskControl(task_handle1, DAQmx_Val_Task_Unreserve);
pause(3);
end
DAQClearTask(task_handle);
DAQClearTask(task_handle1);
01-15-2020 05:30 AM
No definite answer, but here are a few reactions to what I see. (Note: I'm a LabVIEW guy, and don't know details of any of the text API's. I can generally follow, but don't know the meaning of specific constants in the function parameters.)
1. I don't understand what the "unreserve" is meant to accomplish here. You seem to be setting up the exact same config and task run conditions repeatedly inside your loop.
You can get the same behavior with only the Starts, Wait, Stops, and Pause inside the loop. The other config stuff can be done before the loop.
2. FYI, it isn't usually necessary to explicitly set up the Reference Clock in a PXI system, most devices sync to the PXI backplane clock by default.
3. Based on the DAQmx Task State Model (be sure to follow all the links at the bottom for more complete info), the fact you did no explicit state transitions *before* starting the task suggests that the task will implicitly return to the "unverified" state when you call DAQmx Stop.
Does this sound weird and complicated? No prob, I'd agree it's far from obvious. I just happen to have been doing DAQ with NI devices since before Y2K so I've accumulated knowledge about some stuff hidden away in the dusty corners.
So in general terms, what are you hoping to accomplish with the explicit "Unreserve"? I don't see anything in the posted code that'd make it helpful. And there may be another way to accomplish your intentions.
-Kevin P
01-15-2020 03:57 PM
Thanks a lot for the link to Task State Model. I think I know the issue of my code. I was hoping to release (remove) the resources from the task. But it seems impossible.