From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

NI error -201133; Input and output on the NI9401

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.

0 Kudos
Message 1 of 13
(7,992 Views)

Hello jeffou,

 

Thanks for your posting on National Instruments forum,

 


This error is relating in the following link :

 

http://digital.ni.com/public.nsf/allkb/0495B7D5E2345DF386257730007EFD17?OpenDocument

 

In order to avoid seeing  Error -201133  when configuring the NI 9401 in DAQmx for bidirectional digital input and output, one of the tasks must be reserved before either task is started.

 

In the link, it's a LabVIEW programming code. It must be adapted in Matlab.

 

Thanks

 

 

Brice S.
National Instruments France

Message 2 of 13
(7,960 Views)

Hi Jeffou,

 

I've asked the technical team to respond to give a more definitive answer, but in the meantime, my instinct is that you need to add both channels that you want to synchronize into the same session, rather than using two different sessions.  Data Acquisition Toolbox will attempt to synchronize all channels that you add to a Session.

 

You can see examples of synchronizing channels here:

http://www.mathworks.com/help/daq/examples/#simultaneous-and-synchronized-operations

 

-Rob Purser

-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 3 of 13
(7,952 Views)

If you want to do clocked counter input measurements you need to specify an external clock OR (if available) you can add an analog input channel from another module on the same chassis -- in this case the session shares an internal clock with both modules.

 

The external clock can be generated by a counter output channel in pulse generation mode, as you had session sClck configured. However, ther error you are running into could be due to using channels from the same counter subsystem (on the same module) in two separate sessions.

Can you try using the counter output channel from another module (if available)?

 

s = daq.createSession('ni');

s.addCounterInputChannel('cDAQ1Mod5', 1,'EdgeCount');

s.addClockConnection('External', 'cDAQ1Mod5/PFI2', 'ScanClock');


extClockFreq = 1E+3;
% this should match the frequency of the external clock
s.Rate = extClockFreq;

s.DurationInSeconds = 1;


[data, timestamps] = s.startForeground;

 

 

 

The alternative to using an external clock, as I mentioned, is to have one session with one counter input channel and an analog input channel from another module on the same chassis -- in this case the session shares an internal clock with both modules, so no external clock needs to be provided. Please see the following example:

 

http://www.mathworks.com/help/daq/examples/count-pulses-on-a-digital-signal-using-ni-devices.html

0 Kudos
Message 4 of 13
(7,923 Views)

Thank you brice.

 

Thank you for your answer.

My problem is that I don't know how to convert the labview code to reserve the task (made with the DAQmx ) in matlab code. Indeed, I don't know how to "separate" the input and output and thus reserve one task. I tried to find further code on the internet, but did not find any working solution at this time.

 

In all case, thanks for your help

0 Kudos
Message 5 of 13
(7,873 Views)

Thank you brice.

 

Thank you for your answer.

My problem is that I don't know how to convert the labview code to reserve the task (made with the DAQmx ) in matlab code. Indeed, I don't know how to "separate" the input and output and thus reserve one task. I tried to find further code on the internet, but did not find any working solution at this time.

 

In all case, thanks for your help

0 Kudos
Message 6 of 13
(7,872 Views)

Hi Rob;

 

thanks for your answer. The think is that, when I try to add both channels into the samed session, I still have an error message -201133. And I can only install one module on my DAQ(so, it has to be the NI9401). Moreover, I only have access to the session based interface.

 

0 Kudos
Message 7 of 13
(7,870 Views)

Hello "aeu",

 

thanks for your answer. My problem is that I only can have one module on the DAQ. Thus it has to be the NI9401. 

isn't it possible to habe both clock output and encoder input with a DAQ nad NI9401? 

 

Actually, my objectif is a little more complicated. I would like to record 2 encoders in the same time. This There would be 2 input for the 2 encoders, and one output corresponding to the clock. But I try to deal each problem one another.

 

Else, would it be possible to use the clock of the computer to record both encoder? If so, do you know where I could find exemples of codes to do so?

 

Thanks again for your precious help. 

0 Kudos
Message 8 of 13
(7,866 Views)

Hello Again Brice,

 

As I told you I don't know where to find help to translate the labview  code in session based interface for Matlab.

Moreover, my problem is a little more complicated: I actually have to record 2 encoders on the same time. My idea was to record both encoders using the clock output. Thus I would have to reserve one task for the clock, one task for 1 encoder input and one task for the other encoder input? But how is it possible to reserve one task using the matlab session based interface?

 

Else, my other idea was to record both encoders input (I will still have the problem to reserve each task ) and to use the clock of my computer as an external clock; is it possible?

 

Thanks again for your help.

 

Jeff

0 Kudos
Message 9 of 13
(7,864 Views)

An alternative to clocked (hardware-timed) acquisition would be to read the current counter value with inputSingleScan as needed, but you would have to keep track of the timestamps manually.

 

s = daq.createSession('ni');
s.addCounterInputChannel('cDAQ1Mod5', 0, 'EdgeCount');

 

data = inputSingleScan(s)

 

 

0 Kudos
Message 10 of 13
(7,839 Views)