LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help Building a .NET 4.0 Interop Assembly using LabView 2012

Hello,

 

I am trying to export a LabView 2012 VI for use in a Microsoft C# .NET 4.0 program written in Visual Studio 2010 with Measurement Studio 2012.  To my knowledge, NI has not yet provided example code to use the new, native .NET functionality built into LabView 2012.  My previous request for documentation yielded an example using unsafe code and a call into a C DLL, NOT a C# Interop Assembly.

 

I have completed the following steps:

 

1) Create a LabView Project

2) Construct a VI in this project.  This VI will be called usng the Interop Assembly LabView will build for me.

3) Create a build in LabView 2012 for a .NET Interop Assembly and compile the build with the exported LabView VI

4) Reference the Interop Assembly in a Visual Studio Project, and additionally Reference the NationalInstruments.LabVIEW.Interop.dll assembly from ProgramFiles (x86)

5) Attempt to call the exported VI from a C# program using a direct invocation (i.e. MyNamespace.MyLabViewDLLClassName.ExportedVIfunction(int foo, out double bar); )

 

When targeting "AnyCPU" in visual studio, and executing on a 64-Bit OS, the C# program generates an error stating that it cannot find the VI.  When Targeting "x86" in visual studio, the function call works.

 

I would like NI to provide example code for the following:

 

1) Example code for calling an Interop Assembly generated in labview 2012 32-bit in c# 2010

2) Example code for calling an Interop Assembly generated in labview 2012 64-bit in c# 2010

3) Documentation detailing the subtleties of building c# code in Visual Studio 2010 for a mixed 32 and 64-bit deployment that uses LabView 2012 Interop Assemblies.

 

Thanks!

 

0 Kudos
Message 1 of 9
(5,990 Views)

I'm afraid you can't mix and match 64 bit and 32 bit LabVIEW generated assemblies at will. While .Net assemblies created with a MS Visual environment are really byte code assemblies that are mostly bit agnostics, that is not true for the LabVIEW VIs inside a .Net assembly created by LabVIEW. LabVIEW always compiles the executable code to machine code for the target it is executing in. So if you use LabVIEW 32 bit the generated LabVIEW code with need to run inside the Windows 32 bit environment, and if you use LabVIEW 64 bit, the resulting VI code will need to run in 64 bit Windows environment. Even when you create a .Net assembly, the LabVIEW in fact creates a .Net wrapper that invokes the actual compiled LabVIEW VIs.

 

So if your .Net assembly was created in LabVIEW 32 bit, it will only run when called from a .Net application context that runs as 32 bit process.

Rolf Kalbermatter
My Blog
Message 2 of 9
(5,979 Views)

Hi,

 

You can check some information about .NET Interop Assemblies at the following link:

 

http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/building_a_net_assembly/

 

Regards,

0 Kudos
Message 3 of 9
(5,967 Views)

Although I appreciate your answer to AbstractContext' question. I was also stuck with errors trying to generate a dll from a VI I created then call if from a VB.net app I am building. 

To his point however, why have NI no updated its example list to offer a simple example of how to do this using current SW?

We can spend hours upon hours trying to figure it out, or you can provide us with a simple example much like you did for Labview 6.0 that actually work on VS 2008 and above.

Labview it a beautiful language and an enticing tool to work with, and NI documentations are nerdy and unhelpful as can be.

Thanks,

0 Kudos
Message 4 of 9
(5,611 Views)

wlam02,

 

I couldn't immediately find an example either. You don't mention which version of LabVIEW you are running, but I was able to find this document which runs through the process in LabVIEW 2011:

 

http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/building_a_net_assembly/

 

The LabVIEW 2013 manual doesn't seem to pull all the information on to the same page as nicely as the 2011 manual, but seems to reference it in the "building applications" section. It's about half way down the page, and admittedly doesn't seem to be as thorough:

 

http://zone.ni.com/reference/en-XX/help/371361K-01/lvhowto/develop_distribute_applications/

 

If you could direct me to the LabVIEW 6.0 documentation you are referring to I can look for something more similar to what you're looking for..

 

Also, I'm glad to help but have found that many people have better luck getting community responses when they post a new topic rather than reviving a thread that hasn't been posted in for a while. If you think there is useful information in an old thread, just link to it as a reference. 

 

 

--------------------------------------
0 Kudos
Message 5 of 9
(5,576 Views)

Christopher,

First, thanks for the reply and info. I have access to Labview 2011 and 2012 but I am currently developing using the x64 version of 2013. I am trying to build and use a dll that I will access using MS VS VB 2008 (I also have access to the VS 2010).

In my search for an example on how to build a dll using Labview and call it from a VS code, I came across the article in the first link you offered (http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/building_a_net_assembly/) I am able to build and add as a reference the VI I made as a .net Interop, but that’s where it end for me. I do not know how to call it form VB code or use it as a function.  As far as I can tell, this article is no more than a detailed explanation of each option when you build the .net Interop but it does not extend to explain how to then call it from the VS environment. In fact the only reference to the usage of the .net Interop dll created is in the paragraph stating “After you build a .NET interop assembly, you can call the assembly from other programs that support .NET”. As you mentioned in your post, the link to the 2013 documentation does little to help extend the information noted on the first link.

So far, the only way I have been able to be partially successful in implementing my code, is by compiling my VI as a dll using the “New > Shared Library (DLL)” option (not the Interop) in the project manager, and even then I can only successfully access it from my VB code if I first build my code then run it. If I then try to add the dll as reference, it error out, and in order to call my dll I am forced to use the declare method to add my dll. (Here is the declaration call I make):

Declare Auto Function GPIB4HP6612C Lib "GPIB4HP6612C.dll" (ByRef GPIO As Double) As Double.

Additionally, VB error out if I try to run it in debug mode. As far as I can find out from different posting on forms, this has to do with the difference in the signature of the dll for when running in debug mode Vs dll used for normal operation (I think it’s an inherit behavior of the windows OS IDE environment reacting to the way Labview is compiling the dll but I am not sure). So I am left to compile my code first the run it with no real time debugging option while trying to develop my code.

I will be happy to make both my VI and my VB codes available for you if you want. As I mentioned in my original post, I am by no means an expert programmer, and a simple example of this process will go a long way to help clarify this for me (and I think for others as well).

Thanks,

Duke Moran.

0 Kudos
Message 6 of 9
(5,556 Views)

Just to confirm, you can call the DLL, but only when the project is built, not when it's in debugging mode.  Correct?

-Jim B
Applications Engineer, National Instruments
CLD, CTD
0 Kudos
Message 7 of 9
(5,537 Views)

Correct. And only if I use the declare method I described. (Can't add it as Ref to the project).

0 Kudos
Message 8 of 9
(5,530 Views)

 

There could be a few different issues going on here.

 

First, are you able to call other interops from within VB? If not, the following link may be useful: http://www.codemag.com/Article/0203031

 

Another potential problem is differences in .net frameworks. If I remember correctly, VS 2008 uses .net 3.5. LabVIEW 2013 uses .net 4.0 by default. If a .net 4.0 interop even loads in a .net 3.5 environment, it is very unlikely that it will work.

 

It is possible to change the version of the framework used for building assemblies in LabVIEW, and that is detailed at the following link.

 

http://digital.ni.com/public.nsf/allkb/1BAA896E8E51E1BD86257B6A0055F200?OpenDocument

--------------------------------------
0 Kudos
Message 9 of 9
(5,491 Views)