Ce contenu n’est pas disponible dans votre langue préférée.

Le contenu est disponible dans une autre langue. Votre navigateur peut inclure des fonctionnalités qui vous aideront à traduire le texte.

Using Custom .NET Class Library in LabVIEW

Updated Oct 17, 2023

Environment

Software

  • LabVIEW
  • Microsoft Visual Studio

Programming Language

  • C# .NET
  • Visual Basic .NET

Class libraries are the shared library concept for .NET. They enable you to componentize useful functionality into modules that can be used by multiple applications. The guide here below shows how to create a simple class library assembly that uses Pythagoras formula example in Visual Studio, which later to be use in LabVIEW. The formula is then used in Invoke Node.

1. Launch Visual Studio and create a .NET framework class library project according to desired text-based language. 
Select VB Class Library.pngSelect CS Class Library.png
2. Insert either of the snippet code given below based on the selected text-based language.

Using VB.NET
Imports System.Math
Public Class MathsList
    Public Function PythagorasTheorem(a As Double, b As Double) As Double
        Dim c As Double
        c = Sqrt((a ^ 2) + (b ^ 2))
        PythagorasTheorem = c
    End Function
End Class
Using C#
public class MathsList
    {
        public void PythagorasTheorem(double a, double b, out double c)
        {            
            c = Math.Sqrt((a * a) + (b * b));            
        }
    }
3. Press Ctrl-B to build the DLL. The built DLL file  can be found in the Debug folder of the project path. 
PathLocation.png
4. Open a new LabVIEW VI and drop the Constructor Node on the block diagram. Navigate to the location of the DLL by pressing the Browse button and select the DLL file. 
NavigateToDLL.png
5. Once the DLL is loaded, the constructor within the DLL will appear. 
SelectConstructor.png
6. Place an Invoke Node on the block diagram and wire the output of the Constructor Node to the input of the Invoke Node. The method will appear when clicked on the Invoke Node.
Wiring.png
Using VB.NET                                                              Using C#
VBInvokeNode.pngCSInvokeNode.png
 

The value can be verified by changing the value of the numeric control.
Result.png