Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling .NET Assemblies From LabVIEW

Overview

The attached example VI calls the .NET DLL that accompanies it, which is a .NET class built in C# to emulate a very basic calculator.

 

 

Description

Although many shared libraries exist, and have the same extension of *.dll, you may or may not be aware that there are in fact two very different ways that DLLs are called from LabVIEW, depending on what language the Dynamic Linked Libraries (DLLs) were written and compiled in.  DLLs written in both ANSI C and the .NET languages (like VB.NET and C#.NET) both have the extension *.dll when compiled, and may appear to be the same on the surface, but are inherently different in the way they are called from LabVIEW.  Unlike a C-style DLL, which is called from LabVIEW using a Call Library Function Node, .NET DLLs are called using a .NET Constructor Node (Connectivity » .NET » Constructor Node in the Functions Palette).  This function, when placed on the block diagram, will allow you to browse for the .NET assembly (or DLL) that you wish to use.  Once you select the DLL, and the class from the DLL that you want to use, LabVIEW instantiates an object of that class, and passes a reference to the object out.  With this object, you can then access all of the properties and methods of the class using Property Nodes and Invoke Nodes.

 

 

Steps to Implement or Execute Code

  1. Download the TI83.dll and the example VI
  2. Use buttons on Front Panel to get/set properties of the calculator and to execute functions
  3. Use Execution Highlighting to observe how the VI uses the TI83.dll to get it's functionality
  4. Run the VI

 

 

Requirements

LabVIEW 2012 (or compatible)

.NET 3.5 Framework (or compatible)

 

Additional Information or References

Block Diagram

BD.PNG

 

 

Front Panel

FP.PNG

 

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

Chris_G
Sr Test Engineer
Medtronic, Inc.
Comments
Member EWiebe
Member

Thank you for the sample, but could you please add the C# source code (complete with solution and project file) ?

-------------------------------------------------------------------
Eugen Wiebe
Bernstein AG
CLAD - Certified LabView Associate Developer
Member GL999
Member

Thank you very much for your sample code. I am wondering whether both VC$ and LabView can call the same .net DLL?

George

Member tduffy
Member

There is no source code for the .Net assembly.  Could you please post?

Member BlackLin
Member

I got an error when I try to call the DLL got from other people. The error is saying "This assembly is built a runtime newer than the cirrently loaded runtime and cannot be loaded.

How do I know the current runtime version I have?

How do I update runtime loaded in my machine?

Black

Member bmitchell
Member

I am not trying to hijack your post but am simply posting since it is relevant. I implemented a library in LabVIEW that uses Perforce's .NET API, which is a prototypical .NET API with lots of objects and collections. So the LabVIEW library is a non-trivial example of how to properly handle multiple constructed .NET objects, .NET collections, and how to properly close out .NET references from LabVIEW, which is very important. When writing this library, I found there were very little non-trivial examples of how to use .NET from LabVIEW, although your post is nice since it shows how users can write their own .NET assemblies to be called from LabVIEW.

The library can be found here: https://decibel.ni.com/content/docs/DOC-43970