From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Convert Shared Variable Address Strings Between APIs

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

Overview

This example shows how to convert shared variable addresses between APIs.

 

Description

There are multiple ways to access shared variables from LabVIEW without using an actual shared variable node. Unfortunately, the address formatting used within these APIs is often incompatible with other APIs. This example allows the user to convert shared variable addresses (formatted as strings) between the following APIs.

  • Shared Variable API
  • DataSocket
  • Tag API (Part of the Datalogging and Supervisory Control Module)

Some APIs return "." or "My Computer" as an alias for localhost. All APIs will recognize "localhost", so this VI also replaces "." and "My Computer" with "localhost" if found. All other target names will be preserved in the converted address (also IP addesses).

The VI is designed to be used as a SubVI, so you can pass the string and desired output type in and receive the correctly formatted output address.

 

Example conversion (DataSocket --> Shared Variable API):

psp:\\localhost\OPC Library1\_ActiveTagCount --> ni.var.psp://localhost/OPC Library1/_ActiveTagCount

 

Example conversion (Shared Variable API --> DataSocket):

ni.var.psp://192.168.0.1/OPC Library1/_ActiveTagCount --> psp:\\192.168.0.1\OPC Library1\_ActiveTagCount


Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached file "Convert Shared Variable Address LV2012 NIVerified.zip"
  2. Follow the instructions in Front Panel of "[Main] Convert Shared Variable Address LV2012 NIVerified.vi" and run the program
  3. To use the VI in another application copy content of the attached zip file to your application directory and use "[Main] Convert Shared Variable Address LV2012 NIVerified.vi" as a SubVI. Pass shared variable address and desired address type enum parameters to the SubVI.

 

Additional Information or References

[Main] Convert Shared Variable Address LV2012 NIVerified.vi - Front Panel.png

 

[Main] Convert Shared Variable Address LV2012 NIVerified.vi - Block Diagram.png

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**

 

Caleb Harris

National Instruments | Mechanical Engineer | http://www.ni.com/support

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