LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Examples for good programming practice with multiple DAQmx tasks

I'm writing a program to continuously log data from 8 counters, 8 encoders, and 8 voltages. The proof of concept VI with a single counter was simple and elegant, but scaling up to all signals resulted in a wiring mess. I've been working through the Labview Core courses, and am currently on Core 3. I still haven't come across a discussion on how to work with multiple DAQmx tasks without making a mess of the block diagram. Can anyone point me in the right direction?

 

Also, say I have a state machine that has a configure, idle, and logging states. I need to set the initial values of the encoders during configuration, and keep up with their changes while in the idle state so I have appropriate starting values when entering the logging state. Can anyone point to an example that shows how this might be accomplished?

 

Thanks

0 Kudos
Message 1 of 12
(7,484 Views)

Ah, one of those.....

 

OK you've been up to Core III and not been really introduced to modular code concepts.  First go back to the LabVIEW forum  hit top kudoed posts, select "All time"  you'll read a very nice nugget from Ben.  There is a reason its the top kudoed post of all time.

 

DAQmx tasks work great on the USR or FBN of a functional global (Action engine or Resource Module)  No other vi really needs access to that data so why pass it around in callers that can't (or shouldn't) use the information anyway?  It will only cause you a "Wiring nightmare"  Just to give a simple example the attachment is a "Resource Module" for a DAQmx Digital Out task.  you can safely ignore the type defd enum I did not attach.

 

Next get yourself a copy of "A Software engineering approach to LabVIEW"-  It's an eye opener! and Swatts can pass over the royalty check since I promote it so darn much.


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 12
(7,449 Views)

Jeff·Þ·Bohrer wrote:First go back to the LabVIEW forum  hit top kudoed posts, select "All time"  you'll read a very nice nugget from Ben.  There is a reason its the top kudoed post of all time.

It is so useful of a post, I keep a shortcut of it in my Macros:Action Engine


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 3 of 12
(7,416 Views)

I'm very familiar with AE's/Functional Globals - but I have struggled in the past with handling multiple DAQmx tasks - particularly when you're using multiple devices and using different types of measurements which require seperate tasks/handling (e.g. such as thermocouples which require extra compensation).

 

I'm not even sure I know whare the requirements are for needing multiple tasks - I know you can need multiple tasks for a single device if the type of measurement is different but can you share an Analogue Input task amongst multiple devices?

 

I think in hindsight (and without too much thought now) it looks like a good case for Object Oriented LabVIEW - with a base DAQmx class (initialise, configure, start, acquire, stop, close etc.) and then child classes for each type of measurement (with one task associated with each - and private data unique to that specific class). You then hold an array of objects (one for each task) and iterate through each one with dynamic despatch to get the data.

 

I don't know your particular experience level of using LabVIEW (and as such, OO may not be appropriate) - but as a wider discussion of 'best practice' it seems like an appropriate method I would use going forward.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 4 of 12
(7,397 Views)

Ben's famous Action Engine Nugget is always a good read. http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/m-p/503801

Ah, forgot about the macro.... go figure

 

And yes, an LVOOP approach would be better. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 12
(7,380 Views)

Thank you all for providing some direction. I've ordered the book, am reading the recommended thread, and will work through the rest of Core 3, the OO course, and the Advanced Architectures course at ni.learn.com over the break.

0 Kudos
Message 6 of 12
(7,368 Views)
I think you only need 3 tasks, just group the channels together, it'll madke it easier.
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 12
(7,356 Views)

I can group my analog signals into a single task, but I have not been able to group counter tasks into a single task. And I thought I read documentation saying this was not possible with counters. Am I mistaken?

0 Kudos
Message 8 of 12
(7,349 Views)

This is true, you can't group the counters into a single task.

 

Extending your single counter proof of concept VI to multiple channels shouldn't have to create a wiring mess though--you could use some for loops for example (I didn't wire the inputs, but you get the idea):

 

MultipleCounterTasks.png

 

The AI channels can likely be combined into a single task (you didn't mention your hardware).

 

 

If it's a larger scale applicaiton, I would probably consider going the LVOOP route and wrapping up the DAQmx into a class with a more generic parent interface (but I guess that depends on your application requirements).

 

 

Best Regards,

John Passiak
0 Kudos
Message 9 of 12
(7,320 Views)

I'd like to follow up with a question relating to LVOOP and/or the actor framework. Suppose I want to create a controller class that is responsible for instantiating objects to manage acquisition and logging for the various channels for this measurement. The actor framework template includes something sort of analogous to this, with two actors that could be used for this purpose. But those actors, alpha and beta, are hard-coded into the controller classes private data.

 

Could anyone suggest how I would manage the controller's private data to deal with an arbitrary collection of counters, analog signals, encoders, etc, which might be specified in a configuration file? In my "native" language (python), I would create classes/subclasses with a common interface, and have my controller aggregate the instances of the various classes into a single collection (list or dictionary), and then iterate over the collection.

0 Kudos
Message 10 of 12
(7,158 Views)