Programmatically Create and Deploy Libraries and Shared Variables

Updated Mar 7, 2024

Environment

Software

  • LabVIEW

This article explains how to programmatically create a library with shared variables and visualize it in your main LabVIEW project without utilizing the LabVIEW Datalogging and Supervisory Control (DSC) Module.

You can programmatically create new libraries and shared variables in a LabVIEW project without using the LabVIEW DSC Module by using VIs that ship with LabVIEW. You won't be able to find these VIs in the Functions Palette in LabVIEW - instead, you will have to find them in C:\Program Files (x86)\National Instruments\LabVIEW 20xx\vi.lib\Utility\Variable, where 20xx is your installed LabVIEW version. The steps below outline an example program which will create a library in your project and add a shared variable of a data type you choose to that library.
Full code snippet of program explained in this article.
 

The files used to create libraries and shared variables in this example can be found at C:\Program Files (x86)\National Instruments\LabVIEW 20xx\vi.lib\Utility\Variable, where 20xx is your installed LabVIEW version.
  1. Open a reference to the project you want to add a library to using an Invoke Node, and create a new library in the project using CreateOrAddLibraryToProject.vi found in the file location above.
Gets a reference to the project we're looking to add a library to, and creates the library.
  1. Configure the basic properties for the library you're creating using a property node. Here, we set the computer and file location where the Shared Variable Engine (SVE) will log data related to the library, enable the variable database and set the amount of days the SVE will log data for, and enable the logging of alarms and events to the same database that is being used for logging variable data. These properties must be configured before creating your library or you will encounter an error.
Setting of basic properties for library to be programmatically created.
  1. Now that we've created and configured a library, we can create a shared variable and add it to the library. Select a type of variable you'd like to create, implemented here as an enum control on the front panel and a case structure, and convert it to Variant data type. Then, add your shared variable to your library using AddSharedVariableToLibrary.vi found in the file location above.
Select variable type and add it to your created library.
  1. Save your new library using an Invoke Node, and then close the reference to your library.
Save library and close reference.
  1. If you would like to open the project window for the project you're adding the library to, do so using an Invoke Node, and close the reference to the project - if you do not need to open the project window, just close the reference. Afterwards, deploy your library using an Invoke Node to your target or host computer.
Open project window and deploy library to target.
 

Next Steps

The above example creates a single library, adds a single variable to it, and deploys the library. This example can be used as a baseline to create more complex VIs involving creating multiple libraries and shared variables, and executing multiple deployments.

When deploying a library that contains variables with binding to remote targets, such as a NI Real-Time controllers, it is important to consider that binding needs to point to active PSP items. As setting binding to LabVIEW project items will result in errors, as there's no reference project when deploying using this method.