Example Code

Simple VI Server .NET Wrapper using LabVIEW and C#

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

Description

Overview
LabVIEW can interact with other programming language through ActiveX, DLLs, network protocols (TCP, UDP...), File Mappings... For each item, a few examples show how it is done.

 
Description
If you are looking for an elegant and efficient way to access LabVIEW VI Server from an unmanaged language like C# or VB.NET, you should not forget about LabVIEW assemblys because they offer a better integration with those unmanaged languages.

Create your assembly that encapsulates the VI Server functions you need from LabVIEW, import the built assembly in you C# project, and start using the VI Server as if it was a native component!

 

 

Requirements

Software:

  1. LabVIEW 2013 (or compatible), C#


Steps to Implement or Execute Code

  1. Create your project library (dummy.lvlib) in LabVIEW. 

Add VI Server functions to this library (for example, Open VI Reference, RunVI, Front Panel Open, Front Panel Center...)

Connect the terminals to the connector pane for further mapping.

  1. Create a .NET Interop Assembly in the Build Specificaions in LabVIEW.
    Optionally change the names of the namespaces and Interop Classes.
    Add the VIs to be exported, and reconfigure the prototypes of the functions if needed. Refer to the help for details about configuring your build specification.
  2. Open Visual Studio and create a new project.
    Add the appropriate assemblys to your project:

NationalInstruments.LabVIEW.Interop.dll located in <Program Files>/National Instruments/Shared/LabVIEW Run-Time/<20xx>/.
myAssemblyName.dll which is the LabVIEW assembly you just built.Include the namespaces from these aforementioned assemblys in your code ("using ...;" at the top of your code).
Start writing your .NET code. You can now call the functions that were exported in your assembly. They will be seen as methods owned by a class named after your LV project library (dummy).
Make sure you build a 32-bit application (x86 processor architecture for most Windows machines). Make sure the LabVIEW Run-Time Engine (same version as the one which build the assembly) is installed on the machine running the Visual Studio project.

 

 

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

Eric M. - Senior Software Engineer
Certified LabVIEW Architect - Certified LabVIEW Embedded Systems Developer - Certified LabWindows™/CVI Developer
Neosoft Technologies inc.

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

Comments
的歌声
Member
Member
on

Hi ,

Thanks for you info.But i find some issues about it.if I set some delay in Vi.some problems will come.