Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Digital I/O - Problem with reserving tasks

Hello,
     I am trying to make a simple vi that will allow the user to configure a NI 9401 (in real time) as digital inputs, outputs, or a combination of the two by using a pull-down menu.  I would then like to be able to toggle the outputs or monitor the inputs.  I am using a NI cDAQ-9172 and LabVIEW 8.0.  I have the "all output" case working correctly, but as soon as I change cases, I get an Error -201133.  I get the same error whenever I change the case from what it was when the system was powered up.  It seems as if the error occurs on random I/O lines.  The error suggests using a DAQmx Control Task, and I have done that, but I am not very familiar with them.  I believe the error is coming from the order in which I  implement the DAQmx functions.  I'm not sure whether or not I should be using Start/Clear Tasks along with the Control Task.  How about Start/Stop Task?  I am not turning on the entire port with one DAQmx Write function because I want to use the same approach for the case where I will make lines 0-3 input and 4-7 outpus, or vice versa.
 
Could someone please take a look at my screen shot and tell me what it is I'm doing wrong?  I am very new to LabVIEW, and I know I'm not using the most efficient approach to this, but I think it should still work.
Download All
0 Kudos
Message 1 of 9
(4,948 Views)
Hi eramsey82,

Before we start digging into the details, would you mind sharing a bit more about your intended application? Specifically, why would you like to change the direction of the lines on the fly?

Thanks for the screenshots you provided, it looks like you may want to change your architecture for what you want to do, but it would help to see the other cases since their contents may help explain why you're getting this error. Can you write a VI for each kind of configuration you want and run them one at a time independently? Having each kind of configuration you want working separately will make combining them together into a single VI easier.

If you'd like more information about  the DAQmx Control Task VI, there is a detailed description of it in the LabVIEW Help file: VI and Function Reference » Measurement I/O VIs and Functions » DAQmx - Data Acquisition VIs and Functions » DAQmx Advanced Task Options VIs and Functions.
Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 2 of 9
(4,901 Views)
I eventually will be making thie vi into a .exe to be used in our lab, so being able to change the port configuration while the program is running would be very useful.  If you think I would be better off somehow stopping and restarting the program when the configuration is changed, I would like to hear your ideas.  I cannot simply hit the "Stop" button, change cases, and then restart the program.  I still get errors.
 
I have included the screen shot from my other case.  So far, I have only done these two cases because I keep running into problems.  I did find out, however, that if I leave the case as whatever it was when the 9172 was powered up, the vi works - meaning I can have either all inputs or all outputs.  The problem occurs when I try to change between the two cases.  When I "Highlight Execution" I am able to switch between cases with no problem (it didn't used to be this way, I must have solved one of my problems), but when I run the vi normally, I now get an error with my Start Task:
 
Measurements: Device cannot be configured for input or output because lines and/or terminals on this device are in use by another task or route. This operation requires temporarily reserving all lines and terminals for communication, which interferes with the other task or route.
 
I am almost certain it is the order in which I use the Start, Stop, Clear, Control Task DAQmx's, but I could be wrong.  The help doesn't help me understand the order to implement these vi's.  I thought it could be a timing issue, so I have played with putting a millisecond delay vi outside the case, but inside the 'while' loop.  I even tried waiting a full second.  This did not help either.
 
Any guidance would be greatly appreciated.
0 Kudos
Message 3 of 9
(4,881 Views)
 

Hi eramsey82,

I can understand how the help hasn't been that helpful for you. The documentation for DAQmx is split between the LabVIEW Help file and the DAQmx Help file. The LabVIEW Help file briefly explains how to use the DAQmx VIs and property nodes, describing their inputs, outputs, and typical use cases. The DAQmx Help file goes into much more detail about the theory of using the driver and gives a lot more information about how the hardware responds to commands.

The information that would be most helpful for you is in the DAQmx Help file under a book called "Task State Model" [1]. This book explains the different states that the hardware has, what they mean, and how you can programmatically transition between them.

Looking at your block diagrams, it appears that you're trying to assign line direction individually. The 9401 only supports input/output direction at a nibble resolution [2]: the lines can only be set in groups of 4. You can write to individual lines in each group, but you can't have lines 0 and 1 input, 3 through 5 output, and 6 and 7 input. The four possible configurations are all input, all output, 0-3 input and 4-7 output, and 0-3 output and 4-7 input.

Before progressing further, my recommendation is to simplify your cases by grouping the virtual channels in the largest group possible. So for all input or all output, create one task that groups all of the lines together. If you want to address individual lines, you'll want to set the 'line grouping' input of the Create Virtual Channel VI to 'one channel for each line'.

In addition, you should probably consider using a different program architecture. The templates for User Interface Event Handler or Standard State Machine [3] would both be good places to start. Think about breaking the changes you need to make into smaller steps: have a case for resetting the hardware, another for configuring it, another for running it, another for clearing the resources, and so on.

[1] NI-DAQmx Help
NI-DAQmx Key Concepts » Tasks in NI-DAQmx » Task State Model

[2] NI 9401 Product Page
https://www.ni.com/en-us/shop/model/ni-9401.html

[3] LabVIEW Templates
File » New... and then From Template » Frameworks » Design Patterns

 
Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 4 of 9
(4,862 Views)
Ok, I followed your direction and tried controlling the port in groups of 4 or 8.  Once again, everything works fine until I try changing to one of my nibble-wise cases.  I have tested each case individually, and they all work.  The error occurs when changing to or from the nibble-wise cases.  I understand what the error is saying:
 
Measurements: Device cannot be configured for input or output because lines and/or terminals on this device are in use by another task or route. This operation requires temporarily reserving all lines and terminals for communication, which interferes with the other task or route.
 
But, once again, the help doesn't really tell me anything.  I understand that I need to reserve the lines, but I have tried putting Daqmx Control Task vi's (reserve) before and after the Start Task, as well as before and after the Clear Task (unreserve) and I get the same error.  I read through all the State Machine info and I understand what it is saying, but it does not tell me how to implement the ideas.  Also, it leads the reader to believe that the DAQmx Start and Stop Tasks actually transition the state according to the task, which (as I understand it) would eliminate the need for a Control Task vi. 
 
If someone could please explain to me where I need to insert the Control Task's or give me any other direction, I would really appreciate it.
 
Once again, I have included screen shots of each case.  I have also included my actual vi in case I haven't explained my problem clearly enough.
Download All
0 Kudos
Message 5 of 9
(4,819 Views)
Here are the rest of my files
0 Kudos
Message 6 of 9
(4,818 Views)
Hi eramsey82,

Thanks for digging into the documentation and streamlining your code. I was able to intermittently reproduce the same error message with it. Now that the lines are being addressed as nibbles, it points out the race conditions more clearly.

LabVIEW is making parallel calls to the driver when it reaches DAQmx Start Task. Looking at the task model, calling DAQmx Start Task verifies, reserves, and commits hardware resources before running the task. If the second DAQmx Start Task is called while the first is still executing, the driver will try to simultaneously access the hardware resources to configure the lines. The error is generated when the committed and running task is using resources that the second one requires for its own configuration.

After I added a flat sequence in both of your split I/O cases to reserve the resources in order before starting the tasks, I couldn't get the error message. Please try it out and let me know if you have any other problems.
Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 7 of 9
(4,784 Views)

Wow.  Thanks a lot.  I figured there was some sort of timing issue, but I never would have figured it out on my own.  I didn't even know about flat sequences.

 

Once again, thanks.

 

Eric

0 Kudos
Message 8 of 9
(4,768 Views)

Hey Everybody,

 

Here's a great resource for the bidirectional nibble configuration of an NI 9401 with DAQmx.

 

KnowledgeBase: Why Do I Get Error 201133 When Trying To Perform Bidirectional DI/O with My NI 9401 i...

 

Be sure to check out the community examples linked in the KB.  I hope this helps!

 

- Greg J

0 Kudos
Message 9 of 9
(4,294 Views)