Example Code

Dynamic Producers or Consumers

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Description

Overview
This example VI show a way to dynamically call different producers depending on the hardware you want to use (or in the case of the demo, what waveform you want to generate) by encapsulating the producer into a subVI.

 


Description
The producer consumer design pattern is one of the most useful patterns we have for DAQ systems.  Sometimes it can be useful to have the same code for a DAQ system even if you are using different hardware. There are two key elements make this technique work, one is that use an interprocess communication method which can work in subVIs (e.g. queues, notifiers, FGVs), local variables will not work, the other is that the data interface (both the connector pane and the format of data in the queue/notifier/FGV) must be the same so the consumer can interpret it. If this is extremely difficult you could have an FGV that does the hardwork but having a different set method for different data sources but then formats the data the same for the get method used by a consumer.

Notes: there is another technique available for this. This example works well as long as we can isolate our DAQ code into a single subVI and there isn't too much hardware independent code repeated across the different producers. If you do need better integration of the code but still achieve hardware abstraction then object oriented programming (OOP) can help with this.  There are many resources for this in the NI Center of Excellence. There is a fantastic white paper discussion of the technique at http://www.ni.com/example/31307/en/ .

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Unzip and download the attached folder to your computer
  2. Open the project "Dynamic Producers 2012 NIVerified.lvproj"
  3. Open the VI "Main Application.vi"
  4. Click the button and choose the function waveform to display
  5. Run the program

 

Additional Information or References
VI Block Diagram of "Main Application.vi"

Block Diagram.PNG 

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.