Example Code

Dynamic run-time creation of Shared Variables (without DSC) using LabVIEW

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

Download All

Overview
It is possible to create shared variables from within your program without creating libraries and the like. This is an example to illustrate the process, opeing references and holding them open for as long as the shared variable is required. It requires no additional LabVIEW toolkits and, although this is written in 2015, I did the same thing several years ago with an older version too.

 
Description
Several times recently, people have had a requirement where the ability to create shared variables at run-time would have made programming simpler. Although the DSC module provides some very nice tools for creating and publishing libraries, sometimes it would be better if they could just be generated programmatically on-the-fly. This can be done by simply opening a reference to the shared variable in question. As long as the reference is not closed, the variable will persist. This example gives a starting point for implementing this in an existing program by applying it as a subvi to one or more calling vis.

The parent vi passes in a reference to itself. From this we can retrieve references to all of the controls and indicators. As long as they have a caption or, failing that a label, then we have a name for the variable (created in a subfolder, under the name of the calling vi)

I've implemented booleans, floats and float arrays and strings. Booleans with latching action are excluded.

All indicators are assumed to publish data and controls to import from the SVs created (unless the "All" input is set)

The single vi can manage any number of vi front panels and, by excluding the calling vi reference, can update all vis in one pass.

If connecting via OPC to the created SV, the easiest way to find the URL is to place a control on a second, blank vi and under the control properties go into the binding tab. Choose datasocket and then browse DSTP. Both the PSP and OPC entries are available in that view.

This example just illustrates the idea and will probably need eidting for your particular needs.


Requirements

Software:

  1. LabVIEW 2015(or compatible)


Steps to Implement or Execute Code

  1. Unzip the project
  2. Open it and then open Demo host app.vi
  3. Run it
  4. Look at the SVs available on your machine, either by binding controls, using the Distributed System Manager or programatically.

 

Additional Information or References
VI Block Diagram

1.png 

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

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