Example Code

Difference Between a Controls/Indicators, Local Variables, and Value Property Nodes

Code and Documents

Attachment

Overview

A VI which shows the differences between using a control/indicator, local variable and value property node to update a value.

Description

When updating a graph you may need to position two cursors, change some colors, and write the data to the graph.  In older versions of LabVIEW, this required two nodes: one for properties and another (Local Variable or Indicator) for the value.  This resulted in two graph redraws. However, using a Value Property Node on the existing node instead of a Local Variable or Indicator will result in one less graph redraw, improving the performance of the code.

For controls that are updated very quickly (i.e. more than 50 times a second) Local Variables and Indicators have built in logic to alleviate and reduce the redisplays to save CPU cycles that would otherwise be spent redrawing objects unobservable to the human eye.  The VI Snippet below will demonstrate the performance benefit of using a local variable instead of a property node for quick updates.

Steps to Implement or Execute Code

  1. Run the VI and you will notice the loop that updates the property node will run slower. 
  2. If you want to force Indicator Update to update the front panel on every iteration, you can right-click Indicator Update and select Advanced>>Synchronous Display.
    Capture.JPG
  3. Run the VI again, and you will notice now that the loop writing to Indicator Update takes longer to complete.

Requirements

Software

LabVIEW 2012 and later

Hardware

None

Additional Images or Video

Local Variable vs Property Node_BD.png

Capture.JPG

Paolo F.
National Instruments
Applications Engineer

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

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

Thankyou for showing my #1 pet peeve with LabVIEW code I have seen.  Once upon a time, NI saw a lot of race conditions due to people using local variables.  So there came the mantra "Do not use local variables."  So the brilliant people I worked with started using the value property node, not realizing why they were not to use local variables.

You may want to do some benchmarking code to show the actual time difference between the different update methods.  My benchmarking caused some people to be in utter shock (the property node is over 2000x slower than the local and terminal).

Write To Indicator.PNG


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
crossrulz
Knight of NI Knight of NI
Knight of NI
on

A continuation of my though process of the previous post: A Look at Race Conditions


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Contributors