Example Code

Calling a Struct Datatype on a .NET C# DLL within LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW
  • Other

Code and Documents

Attachment

Download All

Overview
These example shows how to access a struct datatype that has been created on .NET C# within LabVIEW.

Steps to Implement or Execute Code:

  1. Open New project on Visual Studio
  2. Choose Visual c#>>Class Library
  3. Drop in this example code:

    namespace clusterPassing
    {
      public struct myStruct             //Here you define a structure within "ClusterParsing"
            {
                public string myStr;
                public int myInt;
            }  
        public class myClass            //Here a class is created within "ClusterParsing"
        {
            public int myMethod(myStruct data1)    //Here a method for this class is defined
            {
                return data1.myInt;
            }
        }
    }

     
  4. Select Build>>Solution (This will build a .NET assembly with the dll)
  5. Open LabVIEW and drop a .NET constructor Node in the block diagram
  6. Double click on the Constructor Node and it will bring a list of all the registered dlls on your machine. This registry is called the GAC(Global Assembly Cash). 
  7. Select the desired dll from the GAC. If you do not have a Microsoft certified dll you will have to browse to find it. This will happen if the dll was created by you.
  8. Now use Invoke Nodes to access Actions or Methods and Property nodes to access properties and variables from the classes found on this dll.

 

Additional Notes:
The LabVIEW example attached is not ready to be run, it is just meant to show how to access properties and methods of the class included on the respective dll.

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Regards,
Efrain G.
National Instruments
Visit http://www.ni.com/gettingstarted/ for step-by-step help in setting up your system.

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