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?
Many of LabVIEW's primitive functions can accept many different data types at their inputs. For example, the Equal?
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
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:
We can also make
LV-Read-Write.xnode from this package is growable and has elements that are selectable like a property node.
With VI Scripting, XNodes can create and edit .ctl files. This allows them to create and edit types.
Fake Extensions to the LabVIEW Type System
Some programming languages support
This set of XNodes provides what look like
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.
Today we sat down and talked with one of our Erdos Miller employees to learn about [..]
In a previous blog post on the building blocks of an MWD system, I mentioned that [..]
Finite Element Analysis (FEA) can seem like magic when you first use it. The program [..]