Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView dll in C#

Hello, I just started using LabView few weeks ago. I made a vi that takes data from HH506R (thermometer) through RS-232. Now I am trying to use the dll in C#. Everytime I run the C# program, I get "0" which is incorrect. I have attached the labview and c# files. Thanks. 

0 Kudos
Message 1 of 6
(5,230 Views)

Hello wakka321,

 

After I ran your code, I also received a value of zero, but without any hardware.  After looking at your code, the problem may lie with how you are passing values by reference in C#.  Please refer to the following article for help on the topic.

 

ref (C# Reference)

http://msdn.microsoft.com/en-us/library/14akc2c7.aspx

Regards,

Shawn S. | NIC
Instrument Driver/IVI PSE
National Instruments
0 Kudos
Message 2 of 6
(5,202 Views)

Hello again wakka321,

 

Upon a second glance, I noticed a few other things wrong with this project.  You're currently using the .NET framework version 4.0 with this project, which is not supported.  You will want to create a new project in .NET 3.5. If you use .NET 4.0, you will likely encounter the following error:

 

VIAssemblyException "Failed to call InitLVClient function."

http://forums.ni.com/t5/LabVIEW/VIAssemblyException-quot-Failed-to-call-InitLVClient-function/td-p/1...

 

As well, the interop assembly is the .net equivalent of a C-dll file.  You will want to create an interop assembly and follow the instructions at the link below to do so.

 

Building a .NET Interop Assembly (Windows)

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

 

Regards,

Shawn S. | NIC
Instrument Driver/IVI PSE
National Instruments
0 Kudos
Message 3 of 6
(5,197 Views)

Hello Shawn,

 

Thanks for helping. I tried changing my project to .NET 3.5 and still did not work. Anyways, my application works now. I just took some VIs out, and my application works fine. I still do not know what was wrong. Again, thanks for helping. 

0 Kudos
Message 4 of 6
(5,191 Views)

Hi Shawn,

 

I am having this problem (VIAssemblyException "Failed to call InitLVClient function.")

 

I am forced to use .NET 4.0 as that is what my company is using. I'm the only LabVIEW user here so have relatively little influence. We want to call some of my LabVIEW 2011 code using .NET 4.0

 

What are the options?

0 Kudos
Message 5 of 6
(5,016 Views)

Hi caleyjag,

 

LabVIEW 2011 has limited support for .NET 4.0 assemblies. The reason for this is that LabVIEW has CLR 2.0 compatibility which only enables .NET 2.0, 3.0 and 3.5 compatibility as seen in the Requirements for Using .NET Assemblies in LabVIEW Help document.

 

An alternative that you can use is build a standard C dll and call that dll from the .NET application. A description of how to begin doing this is available in the KnowledgeBase article How Do I Use a LabVIEW DLL in Microsoft Visual Studio.NET?


Milan
0 Kudos
Message 6 of 6
(5,001 Views)