VeriStand .NET API Reference

Table of Contents

C# Walkthrough: Modifying a System Definition File

You can use any .NET-compatible programming language to access the NI VeriStand System Definition .NET API and programmatically control operation of the System Explorer window.

The example code in this topic, written in C#, uses the System Definition API to remove a CAN port from a system definition file and add a new one with an associated XNET database, CAN cluster, and incoming frame. As you follow the example, notice that the hierarchy of classes reflect the hierarchy of nodes that appear in the System Explorer window, shown as follows.

// Open an existing System Definition from disk
SystemDefinition xnetSysDef = new SystemDefinition("C:\\Users\\Public\\Public Documents\\National Instruments\\NI VeriStand 2012\\Projects\\XNETAPIExample\\XNETAPIExample.nivssdf");



// Find the first target in the system definition file by traversing the following nodes in the system definition file, in descending order: root-level item, Targets section, all targets
Target firstTarget = xnetSysDef.Root.GetTargets().GetTargetList()[0];



// Get a reference to the target's CAN section
canSection = firstTarget.GetHardware().GetChassisList()[0].GetXNET().GetCAN();



// Remove the first existing CAN port from the CAN section
canSection.GetCANPortList()[0].RemoveNode();



// Open an existing XNET database from disk
Database xnetTestDB = new Database("XNETTestDB");



// Create a CAN port associated with a cluster in the database you opened
CANPort car1CANPort = new CANPort("CAN1", 1, xnetTestDB, "Car1", 125000);



// Get the Single-Point Frame section that appears under the new CANPort
SinglePoint singlePointSection = car1CANPort.GetIncoming().GetSinglePoint();



// Add a frame to the database
singlePointSection.AddSignalBasedFrame(new SignalBasedFrame("Frame1",0,xnetTestDB,"Car1",8,-1,false,new string[]{"Signal11","Signal12","Signal13"}));



// Add the new CANPort to the target's CAN section
canSection.AddCANPort(car1CANPort);

// Save the changes to the system definition file
xnetSysDef.SaveSystemDefinitionFile;

Related Links

Navigating the System Definition API

Log in to get a better experience