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.