Example Code

Creating a Value Change Event for Shared Variables

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 demonstrates how to use the Datalogging and Supervisory Control (DSC) functions to create user events for shared variables. 

 

Description

This project demonstrates how to read shared variables with an event based architecture. The project includes a library of shared variables. Once deployed, these variables are updated from the "Change Shared Variable Value.vi". Each variable is bound to a front panel control.

When an update occurs, the event structure inside of the "Value Change Event for Shared Variables.vi" will fire and the value will be changed inside of an indicator for each shared variable. The event structure also keeps track of a timestamp for each update.

 

This method is perfect for creating a very efficient architecture that will not require constant polling of the shared variables within the application. It is also very efficient for large numbers of variables since it uses an array of variable constants to register for value change events.

 

Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • LabVIEW Datalogging and Supervisory Control (DSC) Module 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 ZIP-file
  2. Open the [Main] ...VI and follow the instructions on the Front Panel

 

Additional Information or References

[Main] Value Change Event for Shared Variables - Front Panel.png
[Main] Value Change Event for Shared Variables - Block Diagram.png

 

In order to use this example, you must have LabVIEW DSC module. The value change user events can only be created with this module installed. This example was created and used in the "All You Need To Know About Shared Variables" presentation.

 

**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.**
Asa Kirby
CompactRIO Product Marketing Manager
________________
Sail Fast!

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

Comments
Member
Member
on

Using LV 2009, it seems like I can get "events" (the ability to detect a value change of a shared (network) variable) simply by binding a give varaible to a control.  Once I establish a binding via the control's properties section, that control reflects any changes in the shared variable's value. Have things gotten easier in LV2009 compared to this 8.6 example, or am I missing something?

Active Participant
Active Participant
on

Hi Steve,

I like your idea binding a control to a network shared variable to achieve this scenario.

Could you upload your example code to this approach?

However, I think this example gives us a very good idea to handle large amount of IOs with minimum CPU usage.

I wonder if this works with I/O server method through OPC sever.
If yes, this would be a very good design pattern to communicate with PLCs.

Member
Member
on

Hi Ting1224,

Unfortunately, I can't provide any code.... that project is from a previous job and am no longer able to extract a sample.

Member
Member
on

For anyone coming across this, it seems that yes, front panel values will be updated with the shared variable's values, but they can't be used to trigger an event case that way.

It's as if the front panel is updated from a value property node instead of a value(sgnl) property node.