LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx property node not returning error when it should

Solved!
Go to solution

Overview:

 

I'm making a configuration dialog where the user can select which available tasks (from MAX) and channels he/she wants to use for configuration. I display them in a tree control with a different color row background for the items depending if they are used, unused, or the device is not connected.

 

Issue:

 

In the attached snippet you can see I get all available tasks and channels. If my device to which the task is tied is not connected to my PC at program startup and I press refresh I get an error. Good, this is what I want. However, if my device is not connected at program startup and then I plug it in and press refresh, it still errors out. Same goes for the other way -- if I have the device connected at startup then unplug it and press refresh, there is no error. This is a pain because I would like the user to be able to plug in their device if they have forgotten to, then press refresh and have everything update accordingly. However, it seems this is not possible unless they stop and restart the program.

 

Do these DAQmx property nodes only search for a specific tasks device and channels at startup rather than at runtime? Can anyone think of a work around? Furthermore, can anyone reproduce this so I can verify it's not just "programmer error" Smiley Very Happy

 

I am just using a USB-6009 for testing.

 

0 Kudos
Message 1 of 7
(3,031 Views)

Hi Greg,

 

I think the caching effect you're seeing is due to LabVIEW auto-creating DAQmx task objects when you pass task names to the DAQmx Task property node. Try using NI Spy to see when tasks are auto-created. You can manage task lifetime more precisely by calling DAQmx Create Task and DAQmx Clear Task instead of letting LabVIEW auto-create tasks.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 7
(3,015 Views)

Thanks, Brad. What I am trying to do is discover all of the tasks in MAX. Will using DAQmx Create Task allow me to do this? Are you suggesting getting all available tasks then using create task to see if the hardware is available, rather than depending on a property node to error out? A small example of what you're suggesting would be helpful. Thanks!

0 Kudos
Message 3 of 7
(2,998 Views)

A simple start task, then clear task will error out if the device isn't there. Plugging the device in and pressing refresh then shows no error. I believe this is a sufficient work around for now.

0 Kudos
Message 4 of 7
(2,994 Views)
Solution
Accepted by topic author GregFreeman

Hi Greg,

 

A DAQmx Task I/O control can represent one of three things:

  1. A DAQmx task object. This is a collection of data structures representing the task, channels, and task state. It lives in the LabVIEW process (or whatever process is calling into the DAQmx API).
  2. The name of a persisted DAQmx task stored in MAX. This is just a string, but it corresponds to settings stored in the MAX database.
  3. A string that does not correspond to either #1 or #2.

The DAQmx System >> Tasks property returns names of persisted DAQmx tasks (#2). When you wire one of these names to another DAQmx VI or property node, LabVIEW automatically creates a DAQmx task object (#1) with the same name and settings. For anything more than a simple "I/O control wired to DAQmx Read" VI, this is an important and subtle distinction.

 

Let's watch task auto-creation happen using NI Spy:

 

6009 Auto Create.png

 

The line that says DAQAutoCreateSessionWithLVContext("My6009Task",...) is when "My6009Task" gets converted from the name of a persisted DAQmx task (#2) to an actual DAQmx task object (#1). If you click refresh again, you won't see LabVIEW auto-create "My6009Task" again, because the task has already been auto-created. Instead, LabVIEW continues to use "My6009Task" directly:

 

6009 Second Refresh.png

 

As a result, your program only creates tasks at startup, then it reuses the same tasks for subsequent refreshes.

 

My suggestion was to explicitly create and destroy tasks, so that the task lifetime is under your control, not LabVIEW's. Here's how to do that, using DAQmx Create Task and DAQmx Clear Task:

 

Update Tasks 2.png

 

(I also replaced the event structure because it didn't work inside a VI snippet, but making a snippet added broken wires anyway. Just delete the "Panel" control and broken wires, or copy the relevant code into your original VI.)

 

Creating the task checks whether the device is present, but if you want to go further and check whether the device is usable, you can temporarily reserve it:

 

Update Tasks 3.png

 

This will fail if another program or VI has the device's AI resources reserved. Calling DAQmx Start would implicitly reserve the device's AI resources, but it would also start acquiring data, which is not necessary here.

 

Brad

 

---
Brad Keryan
NI R&D
Message 5 of 7
(2,984 Views)

Looks like we were on the same page! Thanks very much.

0 Kudos
Message 6 of 7
(2,973 Views)

Hi Brad,

 

I'm experiencing a variant of the opposite of this problem.  I want to get a list of the channels in a task whether or not the device is present.  When the device isn't present, the property node errors and I get an empty array even though all the channels show up under the task in MAX.  Is there another way of getting the channel names even if the device isn't present?

 

Thanks,

 

Robert

Robert Mortensen
CLA, CLED, LabVIEW Champion, Principal Systems Engineer, Testeract
0 Kudos
Message 7 of 7
(2,906 Views)