LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Digital Input and Output

Solved!
Go to solution

Hello,

 

I am attempting to write a simple LabVIEW application that uses DAQmx for digital input and output.  I am using a cDAQ chassis with a NI-9401 digital I/O module.  I have two classes in my code that will interact with the I/O device: one which performs edge detection on an input pin and one which sets an output pin.  These actions will not occur at the same time however I would like to configure/initialize both "tasks" at the same time and perform "cleanup" at the same time.

 

I am currently creating a new DAQmx task in the Initialize method of my classes and assigning it to a member variable to use later in the class.  However, when I attempt to call the DAQmx write function after the wait for an edge Read function has run, I get the following error "Device cannot be configured for input or output because lines and/or terminals on this device are in use by another task or route."

 

I am confused because I create both tasks initially before doing any input or output so they should already be configured.  I don't fully understand the idea of "tasks" which is probably part of the problem.  All I need to do is simple I/O.

 

Thanks for the help!

0 Kudos
Message 1 of 5
(5,602 Views)

You can configure the tasks simultaneously and cleanup the tasks simultaneously but you cannot run them simultaneously.  This is device specific.  Some support it and some don't.  If your device doesn't support it (which it obviously doesn't) you must wait for the read task to complete before calling the write function and vice versa.  There is a function called "DAQmx Is Task Done" that might be useful for you.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 5
(5,598 Views)

That makes sense, but I am still confused because I am not attempting to perform a read and write at the same time in my code, I only have the tasks both created at the same time.

 

I have the following code in a "Wait For Sync" method in one of my classes:image.png

 The "Initialize" method for this class is:image.png

 

And this is the code in my other class which sets a digital output:

image.png

The "Initialize" method for this class looks like:

 

image.png

 

These methods are called within a synchronous state machine and are never called at the same time in parallel so I don't understand why they would conflict unless I am setting something up incorrectly.

0 Kudos
Message 3 of 5
(5,556 Views)
Solution
Accepted by topic author patrick.wright

You probably need to stop the task after doing the read and write.

Message 4 of 5
(5,550 Views)

Yep, that was the magic solution!  I just added a "Stop Task" VI in the member functions after performing the read and write.image.png

 

image.png

 Thank you!

0 Kudos
Message 5 of 5
(5,544 Views)