Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

"The specified resource is reserved" when using DAQmxRegisterEveryNSamplesEvent

Hi:

 

I am using DAQmxRegisterEveryNSamplesEvent to trigger several analog acquisition tasks, using the internal output of a counter. for this, I loop on several channels, create tasks, and try to start them.

 

By the time I reach the 2 channel, I get the following error message upon calling DAQmxStartTask:

 

NI Platform Services: The specified resource is reserved. The operation could not be completed as specified.

 

I have tried using different counter ouputs for the different channels, but the same error happens. also, I am sure that I am not trying to acquire from the same analog channel. I think DAQmxRegisterEveryNSamplesEvent cannot be called multiple times, even if using different task handlers...

 

Or am I wrong? Could somebody please provide some insights on this issue?

 

Here is the code I use:

 

for(size_t i = 0; i < m_AnalogChannelList.size(); i++)
{
   m_AnalogChannelList[i].taskHandle = 0;

   float64 minVal = m_AnalogChannelList[i].minVal;
   float64 maxVal = m_AnalogChannelList[i].maxVal;

   char ctrName[] = "/Dev1/Ctr0InternalOutput";

   DAQmxErrChk(DAQmxCreateTask("",&(m_AnalogChannelList[i].taskHandle)));
   DAQmxErrChk(DAQmxCreateAIVoltageChan(m_AnalogChannelList[i].taskHandle,m_AnalogChannelList[i].channelName.data(),"",m_AnalogChannelList[i].terminalConfig,minVal,maxVal,DAQmx_Val_Volts,NULL));
   DAQmxErrChk(DAQmxCfgSampClkTiming(m_AnalogChannelList[i].taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,2));
   DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(m_AnalogChannelList[i].taskHandle,ctrName,DAQmx_Val_Rising));
   DAQmxErrChk(DAQmxSetStartTrigRetriggerable(m_AnalogChannelList[i].taskHandle,1));
   DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(m_AnalogChannelList[i].taskHandle,DAQmx_Val_Acquired_Into_Buffer,2,0,&EveryNCallback, &(m_AnalogChannelList[i])));
   DAQmxErrChk(DAQmxStartTask(m_AnalogChannelList[i].taskHandle));
} // for

 

 

0 Kudos
Message 1 of 2
(7,585 Views)

Generally we see this error when the DAQmx task is either not cleared or stopped in a previous iteration of the code. So, say you ran the code above it would not throw that error the first time, but because you don't ever stop or clear the task those resources will remain reserved until you restart your computer. This could also happen if you abort the code before the task is cleared or stopped. Try restarting your computer and make sure you clear/stop every DAQmx task before your program finishes and see if that solves your issue. 

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 2 of 2
(7,582 Views)