LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert "Generic" to Labview .NET

Hi Community

 

I want use the .NET features of Labview to build a very simple application by using the .NET API of an instrument manufacturer.

 

Up to now we have some experience in using .NET in labview. (Sometimes good and sometimes bad expirience)

 

Now I have the big problem to "translate" this line into labview code.

 

var remoteService = driver.Services.GetService<IRemoteService>();

 

////Get the Service of type <T>

///var aService = driver.Services.GetService<T>();

 

///C#:

//Get the IRemoteService instance

///var remoteService = driver.Services.GetService<IRemoteService>();///

 

Is there anyone out there who has a good idea to solve this problem.

 

A solution without building a wrapper would be prefered but may be impossible.

 

 

Thank you and have a nice weeked

 

Gernot

Gernot Hanel
IONICON Analytik Gesellschaft m.b.H.
0 Kudos
Message 1 of 6
(4,523 Views)

The only way to avoid a wrapper DLL is to use .Net Reflection. That is however a painful process since you have to generate the objects yourself through low level .Net functions. Here is an example for the creation of generic .Net lists. However I personally wouldn't consider this preferable above the creation of a .Net wrapper, and it certainly has a great potential to fail if you upgrade some .Net componenents related to your object.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(4,509 Views)

rolfk, what I can't follow is how to create the .NET constant which is wired into the target class of "To More Specific Class"?

0 Kudos
Message 3 of 6
(4,459 Views)

Well, usually you would have some API that requires this specific type so you can normally do a right-click "Create Constant" from there. If you don't have that you could also use the generic System.Collections.IList interface, but you will have to convert the according datatype yourself to and from a .Net refnum (To .Net Object.vi and .Net Object to Variant.vi).

.Net Collection.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 6
(4,430 Views)

Right, I get doing it that way, although it gets very cumbersome.  So what you're saying is that to get the constant (at the top of this image):

you need to write a Wrapper to define it - in which case you can get by without using the .NET Reflection methods anyway.  I was thinking there might be a scripting method that would create a .NET constant of a particular class.

 

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

Hi all

 

Thank you for your help.

 

I tried it doing without a wrapper without sucess (after a few hours)

 

So now I went for the c# wrapper dll which seems to work very nice.

 

I think a scripting vi is no option because I need to build a stand alone application where it was said this may not work in builds. (don't know if this is true)

 

Neverthelss

 

Thank you

 

Nottilie

Gernot Hanel
IONICON Analytik Gesellschaft m.b.H.
0 Kudos
Message 6 of 6
(4,383 Views)