LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does DAQmx Stop Task.vi need to be called before DAQmx Clear Task.vi?

Hello,

 

The documentation of DAQmx Clear Task.vi says "Before clearing, the VI aborts the task, if necessary, and releases any resources the task reserved." Does that mean the end result will be the same, whether or not I call DAQmx Stop Task.vi before clearing a continuous task?

 

I'd like to minimize my VI calls where possible, but want to be sure I won't cause any leaks.

 

 

Thanks.

Certified LabVIEW Developer
0 Kudos
Message 1 of 8
(5,090 Views)

My preference is that I stop a task before clearing it.  But almost every example I have seen just uses the Clear Task.  So I would say that you do not have to call the Stop Task.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(5,068 Views)

As i've understood it, Stop task returns signals/outputs to 0, and Clear task, as it's an Abort, might not.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 8
(5,065 Views)

Hi JKSH,

 

Omitting DAQmx Stop Task.vi will not cause any memory/resource leaks, as long as you still call DAQmx Clear Task.vi. However, calling DAQmx Stop Task.vi is a good idea because omitting it may prevent some errors or warnings from being reported, such as warning 200010, "Finite acquisition or generation has been stopped before the requested number of samples were acquired or generated."

 

In general, DAQmx Stop Task.vi does not return analog/digital output channels to 0. There are a couple exceptions (specifically the NI 4431 and NI 4461 devices, which support the AO.IdleOutputBehavior property), but in most cases, output channels maintain whatever value they had before the task was stopped.

 

Brad

---
Brad Keryan
NI R&D
Message 4 of 8
(5,042 Views)

The DAQmx state transition diagram should be your guide.  If you feel you need to clear a task programatically (I've never needed to but, I haven't done everything) clearing it will expressly unverify all resources the task needs.  This means that nothing is leaked into memory unless there is a bug we can't find (unlikely but, possible.)  So, any other task is free to reserve and commit the resources the cleared task held as long as all the new tasks resources can be verified.

 

Resources are Verified (yup there they are- the task is not insane.  If the Lords of DAQ ask, its possible!)

Resources are Reserved (Nope, the Lords of DAQ may need them, you can't share.)

 

"Abort task" will unreserve all resources a task reserved.  "Clear Task" will unverify those same resources.


"Should be" isn't "Is" -Jay
Message 5 of 8
(5,036 Views)

Thank you for all your replies.

 

It makes sense that Stop doesn't reset an output to 0 -- After I set a digital output to HIGH, I probably want it to stay HIGH without needing the task run forever.

 

The basic things I've learnt from your replies and links are (please correct me if I'm wrong):

  • Abort  Stop
  • Abort unreserves resources; Stop doesn't
  • Clear unreserves and unverifies a task; Stop doesn't
  • Unreserving is sufficient for preventing resource leaks, but not memory leaks
  • Stop before Clear ensures that all errors/warnings are caught (Question: Why does omitting Stop cause some errors/warnings to be lost?)
  • For maximum DAQ efficiency, I should use explicit transitions to minimize verification operations

 

However, my current application is a test system which runs ~50 DAQmx tasks on each unit and (i) mainly performs low-speed generations/acquisitions, and (ii) shares some physical channels between test steps. Thus, (i) extra verifications wouldn't be a bottleneck, and (ii) I'd need to unreserve after each test step.

 

So, I'll just use the high-level VIs instead of explicit transitions to keep my BD clean and simple. My self-contained, reusable test VIs simply follow this pattern:

  1. DAQmx Create Virtual channel.vi
  2. DAQmx Timing.vi
  3. DAQmx Read/Write.vi (auto-start)
  4. (Do parallel- or post-processing, if any)
  5. DAQmx Stop Task.vi
  6. DAQmx Clear Task.vi

 

Next question, since we're now in low-level territory: Is there a difference between:

  • Calling DAQmx Clear Task.vi
  • Aborting + Unverifying a Task, and then letting its wire end (assuming that no branches exist)?
Certified LabVIEW Developer
0 Kudos
Message 6 of 8
(4,960 Views)

Yes we are in low level territory, 


Next question, since we're now in low-level territory: Is there a difference between:

  • Calling DAQmx Clear Task.vi
  • Aborting + Unverifying a Task, and then letting its wire end (assuming that no branches exist)?

 


is not really a good question to ask.  DAQmx (Like VISA) does not really exist "On the wire"  Sure you can put a p-node down and access data members in the class but, the data members really exist in an external storage location.

 

When LabVIEW wants to work with a DAQmx task it sort of peeks into another world and sees if that definition exists.  If it does GREAT, if not you get an error.  management of all that "otherworldly data" takes place in DAQmx land so, its not so much "Letting the wire end" or "Branches" in LabVIEW (Or any other language calling into DAQmx) that determine the lifetime of DAQmx objects "What is the state of the calling application?" is a better frame for the question of "When does DAQmx release buffers?"

 

WHAT this means to the developer: Someone fairly bright took care of all those low level allocations and data management so you don't have to.  If you needed to, you could not get there easilly anyway.  So, "Close the hood, there is nothing to tinker with under there."  But do read the DAQmx help file.

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 8
(4,939 Views)

On a slightly different note, if you create virtual channel, then stop task when done and didn't call clear task at all, does that cause memory leak issues? Aka does this example benchmark code leak memory?

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019MGNSA2&l=en-US

0 Kudos
Message 8 of 8
(3,020 Views)