Example Code

Retain Variable Value

Code and Documents

Attachment

Introduction

This example demonstrates how you can use a Property Node to define a shared variable's initial value. For example, if you wish to retain the value of a variable during an unexpected power failure, using this method would set the variable's value to the last user-set value when the power returns, instead of the default value for that datatype. As shown in the Target VI, this method is also fully compatible with the Variable Read function.

Project

project.png

Host VI Front Panel

host_vi.png

Host VI Block Diagram

host_vi_code.png

Target VI Front Panel

target_vi.png

Target VI Block Diagram

target_vi_code.png

Requirements

1. LabVIEW 2009 (for Read Variable VI + attached files)

2. DSC Module (for Shared Variable Constant)

3. NI-RIO driver

4. NI cRIO or cFP

How To Use

1. Download the zip file

2. Open the Project

3. Select your cRIO and move the VI and the library to your cRIO target

4. Run the target VI

5. Run the host VI and update the variable value

6. Stop the host VI (so it no longer tries to write to the variable)

7. Simulate a power failure by resetting the cRIO

8. Once the power is back up, run the target VI again (variable should read last user-set value)

Regards,


Imtiaz Chowdhury
Project Manager
Green Running / Austin Consultants

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

Contributors