<img height="1" width="1" src="https://www.facebook.com/tr?id=1101141206686180&amp;ev=PageView &amp;noscript=1">


Edit Time Code Generation in LabVIEW - The POWER OF VI SCRIPTING!

The Power of VI Scripting

The LabVIEW Development Environment contains a set of functions, properties, and methods that can be used to inspect, edit, and create LabVIEW code. Yes, you read that right! This collection of functionality is VI Scripting. This functionality is often overlooked; however, if used correctly, it can be amazing. This blog post shows some of the ways in which we used VI Scripting at Erdos Miller and will hopefully be a guide for you to get started.

To begin our journey, we must first understand what an XNode is.

What are XNodes?

XNodes are block diagram nodes that have the ability to encompass VIs that run in the development environment. They are the block diagram equivalent of XControls. The ability VIs can change an XNode's appearance, change its run-time behavior by editing the underlying code, or do anything you can do in the development environment via VI Scripting. XNodes are not an official LabVIEW feature, and there is not a way to create them in the development environment, but the community has made tools to allow XNode creation and editing.

What are some things XNodes can be used for?

Parametric Polymorphism

Many of LabVIEW's primitive functions can accept many different data types at their inputs. For example, the Equal? function can accept values of any type at its inputs, as long as they are the same type (or as long as one type can be coerced to the other). This ability to handle values of different types is called parametric polymorphism. SubVIs cannot have this functionality because each of their inputs must be of a single type.

Polymorphic VIs resolve to one of a fixed number SubVIs based on input types or a menu selection. This is ad hoc polymorphism, and to make a polymorphic VI that can work with any type requires a lot of code duplication.

Parametric polymorphism can be achieved using XNodes because an XNode can change the type of its inputs and outputs based on an input type. The OpenG Array XNodes are an example.

VIMs (VI Macros), which use an XNode to do their work, also have this functionality without needing to write an XNode. To create a VIM you have to add "ExternalNodesEnabled=True" to your LabVIEW INI file. You can then change a SubVI's extension to .vim, and its inputs and outputs will have adaptive types. VIMs are also not an officially supported feature and should be used with caution.

Generate Different Code Based on Edit Time Information

Because runtime behavior of the XNode can be changed by the XNode at edit time, we can use edit-time information to decide what the node should do. An example of this is this LV-Control-Refs XNode.

It populates a cluster with control references to every control in the owning VI. When in this VI:



it generates this code:


but when dropped in this VI:


it generates this code:



Interactive Nodes

We can also make nodes with interactive behaviors. This package includes XNodes that allow a VI to be dropped onto them that it will asynchronously call.


LV-Read-Write.xnode from this package is growable and has elements that are selectable like a property node.



Create Types

With VI Scripting, XNodes can create and edit .ctl files. This allows them to create and edit types.

LV-Create-Signals.xnode, LV-Control-Refs.xnode, and LV-Define-Tagged-Union.xnode all have an output type that can change. This output type can be bound to an existing typedef that the XNode will update when it needs to.



Fake Extensions to the LabVIEW Type System

Some programming languages support sum types, types that are a disjoint union of other types. One common way to get similar functionality in LabVIEW is to use a cluster of an enumeration and a variant, where based on the enumeration value, the developer knows the concrete type of the value inside the variant. The downside of this method is that it requires the developer to use the Variant to Data function, and mistakes result in runtime errors.

This set of XNodes provides what look like sum types, but are really just a correctly-typed interface to an enum & variant cluster.




At Erdos Miller we use VI Scripting and Edit-Time Code Generation techniques to increase our productivity, make code easy to write and easier to maintain. We are always looking to meet new clients and help them solve their technical challenges quickly and efficiently. We are also always looking to expand our team and bring new ideas, minds and talents into our team. Get in touch with us today.


Recent Posts:

My Internship Experience at Erdos Miller
Publish Date 20 Mar 2017 Jonathan EisenbrandtJonathan Eisenbrandt


Filtering Basics: Importance of Linear Phase
Publish Date 20 Mar 2017 Jason ThaiJason Thai

Linear phase and computation/memory complexity are important characteristics to [..]

Revisiting OAuth 2 in LabVIEW
Publish Date 20 Mar 2017 John AmstadtJohn Amstadt

Recap In my previous blog, we took a look at how to implement OAuth2 in LabVIEW. [..]

Engineering a Better 3D Print (Part 1)
Publish Date 20 Mar 2017 Michael MaloneyMichael Maloney

3D Printing and its widespread use has been a long time coming and seems to have [..]

NVCC – Intro to Utilizing GPU Power to Offload the CPU Part 3
Publish Date 20 Mar 2017 Jack BakerJack Baker

Assumptions: Machine has a Nvidia CUDA Core GPU (such as a GeForce) with installed [..]

How I Learn New Skills for Personal Growth
Publish Date 20 Mar 2017 Bryce UrestiBryce Uresti

Learning new skills can be quite the task especially when there's already so much [..]

Controlling the Supply Chain Dream
Publish Date 20 Mar 2017 Thomas MathewThomas Mathew

You are out with your friends, bird watching, and nothing could be more peaceful. [..]