Programming with the System Definition API in LabVIEW

NI VeriStand 2018 Help

Edition Date: May 2018

Part Number: 372846M-01

»View Product Info
Download Help (Windows Only)

You can use LabVIEW to access the NI VeriStand System Definition .NET API and programmatically control operation of the System Explorer window.

Note  Creating and communicating with .NET objects in LabVIEW requires the .NET CLR 4.0 that installs with LabVIEW. You must use a .NET 2.0 configuration file if you want to load .NET 2.0 mixed-mode assemblies.

You interface with the System Definition API in LabVIEW through the following block diagram nodes:

  • Constructor Node—Initializes a new instance of a specific class, such as the CANPort class.
  • Property Node—Get and set properties, such as the reference to the root item of the system definition.
  • Invoke Node—Invoke methods, such as the AddCANPort method that adds an instance of the CANPort class to the CAN section of a system definition file.

The following block diagram shows an example of using these three nodes to initialize a new system definition file and return references to components that appear in the System Explorer configuration tree.

Walkthrough: Accessing a Specific Class in the System Definition API

To access members of a specific System Definition API class in LabVIEW, first add a Constructor Node to the block diagram. When you add the node, LabVIEW displays the Select .NET Constructor dialog box, which lists all public assemblies in the Global Assembly Cache (GAC). The following figure shows a Constructor Node configured to initialize an instance of the SystemDefinition class from the NationalInstruments.VeriStand.SystemDefinitionAPI assembly.

The Constructors list in this dialog box shows that the SystemDefinition constructor is overloaded. The first overload, with many parameters, creates a new system definition file. The second overload, SystemDefinition(String), opens an existing system definition file whose path you specify. Note that the arguments after the class name correspond to initialization parameters. Constructor Nodes allow you to specify these initialization parameters, as the following block diagram shows.

After you initialize a new instance of a class, wiring the reference output of the Constructor Node to a Property Node allows you to get and set properties in the same class, such as the root-level item in the example block diagram. Wiring a class reference to an Invoke Node allows you to invoke a method in the class, such as the GetTargets method of the Root class in the example.

The hierarchy of classes in the System Definition API corresponds to the hierarchy of nodes that can appear in a system definition file displayed in the System Explorer window. Notice that the hierarchy of classes in the previous block diagram reflects the hierarchy of nodes in the System Explorer window, where XNETAPIExample is the root item that contains the Targets section, which in turn contains the target named Controller.

Shorthand Programming with Dottable Properties

Some classes contain dottable properties that concatenate with other properties or methods. Dottable properties work the same as cascading multiple Property Nodes together. For example, compare the following code examples that both invoke the GetTargets method to return a reference to the Targets section of a system definition file.

Cascading Property and Invoke Nodes

Dottable property

Shorthand Programming by Finding Nodes by Name or Path

Instead of traversing the hierarchy of System Definition API classes until you reach a specific section, you can use the following methods, which many of the System Definition API classes inherit, to directly find and access a node:

These methods are useful for decreasing the code required to access deeply nested nodes in system definition files. For example, the following block diagram shows the use of the FindNodeByPath method to access the CAN section under the first target in a system definition file.

In the previous block diagram, the FindNodeByPath method returns a BaseNode reference, which represents generic nodes in a system definition file. You must use the To More Specific Class function to typecast the reference to the appropriate class, which is CAN in this case.

Related Links

LabVIEW Walkthrough: Modifying a System Definition File

Finding LabVIEW Code Examples


Not Helpful