How can I record in the same time the position of 1 optical encoders with DAQ: error -201133

1 view (last 30 days)
Former user of Matlab, it is the first time I try to work with the DAQ and national instrument. My device is a NI9401.
I want to record the position of 1 optical encoders. For this , the encoder is connected to counter in the 9401.
Here is how I proceed: 1/ I open a new DAQ session
2/ I add a counter channel, in order to make a clock (because, as I understood, to do a startForeground I have to configure a clock which will be associated with my data recording, am I right?
3/ I add a counter channel in order to have the data corresponding to the position of the encoder. But at this time I have the error message about the session reserved.
here is the code
//first I do the clock
ClockFreq=100;
sClk=daq.createSession('ni');
sClk.addCounterOutputChannel('cDAQ1Mod5',0,'PulseGeneration');
clkTerminal=sClk.Channels(1).Terminal;
sClk.Channels(1).Frequency=ClockFreq;
sClk.IsContinuous=true;
sClk.startBackground
//then I configure the data input
s=daq.createSession('ni')
s.addCounterInputChannel('cDAQ1Mod5'),1,'Edgecount')
At this time I have the NI error -201133 message
Devices cannot be configured for input or output because lines and/or terminals on this device are in use by antoher task or route. This operation requires temporarily reserving all lines and terminals for communication, which interferes with the other task or route.
If possible, use DAQmx Control task to reserve all tasks that use this device before committing any tasks that use this device. Otherwise, uncommit or unreserve the other task or disconnect the other route before attempting to configure the device for input or output.
device : cDAQ1Mod5
Digital Port:0
Lines:3
Thus, my question is : 1/how can I configure both output clock and input counter in NI9401 directly using Matlab?
Thanks for your help.

Answers (2)

Richard Mathie
Richard Mathie on 6 Jun 2014
I have much she same problem, I think the issue is internal to the Matlab DAQ toolbox API. It is not playing nice reserving the hardware before setting the direction of each nibble of the input/output for the 9401.
Have you found any progress on this?

Richard Mathie
Richard Mathie on 9 Jun 2014
I think that there is a problem with Matlab not reserving the hardware
we need Matlabs class to call something like
daq.ni.NIDAQmx.DAQmxTaskControl(s.TaskHandle,daq.ni.NIDAQmx.DAQmx_Val_Task_Reserve);
before executing the daq. Though as it is this dost work as every thing is hidden in the session class. Perhaps we need a helper class or modify the ChannelGroup prepare function.
Untill this is resolved with mathworks, I will have to do this part in python.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!