LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Would you Open and Close DAQmx tasks within a function or Globally

Hi Guys,
 
This should start something.
 
The subject is DAQmx Tasks.
 
If you were writing a function that is called many times, say MeasureVolts (double *Value) to obtain a reading from an Analogue Input Channel.
 
Would you.
 
1. open and start the task inside the function, do the measurement and then close the task inside the same function.
or
2. open the task globally and later do the measurement inside the function using the global task then close the task only when the application is closed.
 
I am mostly concerned with the overhead of task generation and closing, what do you guys and girls out there do?? and what is the general opinion?
 
I would appreciate your views.
 
Regards
 
Paul.
 
0 Kudos
Message 1 of 3
(2,517 Views)

I would definitely NOT keep configuring and clearing (I think that's what you mean by open and close) the same task over and over.  I would configure once, read many times in my main app, then stop & clear once.

I typically like to package such data acq into an "Action Engine" that keeps track of its own DAQmx task id so I don't need to sling that task id wire around into multiple parallel loops / vi's.  Attached is a very stripped-down example for Digital Input. 

I would typically do more with error testing and would make the "Action" enum into a typedef custom control, but this gives you the basic idea.  The action engine approach works very nicely when there's a small # of different kinds of input parameters and output info needed to support all the necessary action cases.   When you start needing a large number of differnent kinds of inputs and outputs to support the desired actions, then you start having difficulty with (1) having enough terminals to wire and (2) remembering which inputs and outputs are meaningful for which actions.

-Kevin P.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 3
(2,495 Views)

Hi Kevin,

Yes that sums up my methodology, I am using CVI and posted into LV by mistake however parallels are there and your thoughts are applicable.

The reason that the question came up is that there seems to be a swing to keeping tasks open only for the duration of the task related activities and not for the program run time. I am trying to get a broader understanding of why this is done. The views of other programmers is something I lack working from home as a 'one man band' so to speak.

In the past once I had opened a task be it a file, comms port or a vi session etc I would leave it open for the entire duration of the application. I am now begining to see some advantages to closing and re-opening these tasks, especially with regard to error handling. When I look at the NI samples they seem to echo this method though that could be because they are very small pieces of code.

Anyway, thanks for you considered input which is appreciated. Thats one in support of my existing approach.

Regards

 

Paul.

 

0 Kudos
Message 3 of 3
(2,475 Views)