LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LABVIEW calling .net method with Interface as parameter

Hi,

I want to access data from TFS (Microsoft's Team Foundation Server) using LabVIEW.

To get connection to TFS here is the C# code .

 

TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFSServerString"));

ITestManagementService teamProject = projectCollection.GetService<ITestManagementService>();

ITestManagementTeamProject testProject = teamProject.GetTeamProjec("ABC");

 

I was able to get projectCollection object in LabVIEW, but facing issue in calling "GetService" method. I am not able to get reference for "ITestManagementService". Please see attached vi.

 

Can you please suggest what can be done for this?

 

Thanks in advance.

 

0 Kudos
Message 1 of 15
(6,467 Views)

Have you tried the "To More Specific Class" to cast the gneric Collection class into the more specific interface? Otherwise you may try to use the "Variant to Data" node in the ActiveX menu. Seems it can also do something similar like this for .Net refnums.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 15
(6,451 Views)

As I mentioned, I am not able to select "ITestManagementService"  for .net reference . So type casting to / from that type is not working.

 

 

0 Kudos
Message 3 of 15
(6,426 Views)

But do you know where is this class in the library?

You can create dNet class constant (I do not know where is it in pallettes, so I use Create constant from .Net property node terminal. Then you can right click it -> "Select .Net Class" -> Browse and find way to  ITestManagementService

dNet reference.png

0 Kudos
Message 4 of 15
(6,401 Views)

Yes, I tried to do that way also. After selecting "ITestManagementService"  from object browser I press ok. (ObjectSelection.png) Then when I check the current .net object this constant refering to is not matching with selected object. (.netType.png)

 

This is the same behaviour I am seeing if I do with Constant or Control.

Download All
0 Kudos
Message 5 of 15
(6,378 Views)

Do you get other classes when unchecking the "Show Creatable objects only" checkbox? This has IMHO to do if you can use a constructor to create an object, but this class is never constructed in itself but always retrieved through the server factory.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 15
(6,351 Views)

Can you try to convert ITestManagementService into system.type using "To more Generic class" and then convert GetService output into ITestManagementService class with "To more specific class"?

 

GetService output type should match type specifying input, but I do not know how LabVIEW deals with outputs that adapt to input in case of .NET functions.

0 Kudos
Message 7 of 15
(6,326 Views)

ITestManagementService is an Interface, so we don't have constructor for that.

If I uncheck the "Show creatable objects only", I didn't see any additional class coming in the list.

Can we reference Interface in LabVIEW and then get "TypeOf" it?

0 Kudos
Message 8 of 15
(6,317 Views)

>> Can we reference Interface in LabVIEW and then get "TypeOf" it?

 

I would say that "Type of" object in LabVIEW is  that blank reference of specific .Net types. There is no real object or interface associated with them - trying to call methods would yield "no object exists" error, but type is correct.. That is why I suggested using "to Generic" and "To specific" converters.  

 

I tried to look into System.Type library for this method - "get Type" object from specific object, but no luck.

0 Kudos
Message 9 of 15
(6,264 Views)

Alexander is right, the LabVIEW refnum is the interface, while the value in the refnum is the object instance. The interface determines what methods and properties can be invoked on the object, but in order for this to be executable there needs to be an actual object instance.

 

Now why can't the refnum be assigned the Interface you desire? Looking at MSDN there seems to be something about TfsTeamProjectCollection.GetService() that looks a bit strange. There are in fact two methods with this name. One takes a parameter of type System.Type that determines the type of the returned service. The other uses Generics (the variant shown in your C# code with <ITestManagementService> after the method name). LabVIEW does not support Generic interfaces at all, so you can't call the second method from LabVIEW. But the one shown in your diagram is the first one so should work anyhow. You just need to be able to create a System.Type that describes the ITestManagementService interface.

 

System.Type however is not something used in normal code but rather something that is part of so called reflection, the technique to retrospectively inspect or build classes at runtime without prior knowledge of the exact datatype. It's rather involved and not easy to understand. However it can be used to create objects in LabVIEW that have Generic interfaces but it requires you to know the exact string to create that object using reflection. This shows a way how to use reflection to create a particular object type. You would then use that both as input to the GetService() method. After that I'm a little lost at what might be the problem with ITestManagementService here. It's not that it makes use of Generics itself, which would otherwise also cause it to not even be available in the browse dialog.

 

Unfortunately I don't have any machine available at this point with VS2010 or newer available so can't test it out myself at the moment.

 

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 10 of 15
(6,234 Views)