LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting LV types to .NET types

Hi !
I'm trying to use a .NET coded dll in my application. One of the functions is asking for a "datatype" parameter (in C# it would be returned by typeof() ). I used a LV control associated to "To .NET Refnum" function for this parameter but it always returns an error : Class conflict. Indeed, "To .NET Refnum" delivers a System.Object refrence instead of a System.Type reference.
I tried to cast the reference outputted by "To .NET refnum" function or use the "to more specific class" function but in both case it doesn't work or returns an error.
Does somebody has a solution ???


Message Edité par zyl7 le 07-11-2008 11:43 AM
CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 1 of 8
(3,414 Views)
You can use the GetType() method for a type, but you have to create the type first:




Message Edited by smercurio_fc on 07-11-2008 02:44 PM
Message 2 of 8
(3,398 Views)
Hi!
Thanks smercurio ! This solution looks great !
However, which constructor did you choose ? Can you provide me a picture of the Constructor Explorer showing which constructor is providing the type (Int16 in your example) ?

Thank you !
CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 3 of 8
(3,380 Views)
Follow the instructions I provided in this response. In step (4) select Int16 instead of IntPtr.
Message 4 of 8
(3,370 Views)
Thank you very much !! It perfectly works !
CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 5 of 8
(3,350 Views)
In fact, I only found the way to make it work for "simple" types (Int xx, UInt xx)...
But I'm trying to reproduce this C# line code :

int hEAnaArr1;
Int16[] EAnaArr1;

hEAnaArr1 = tcAds.CreateVariableHandle("TASK 1.INPUTS.TableauEAna_1");
EAnaArr1 = (Int16[])tcAds.ReadAny(hEAnaArr1, typeof(Int16[]), new int[] { 8 });
Everything is ok except for the bold expression (typeof(Int16[ ])... Following your method, I tried to use IntPtr constructor associated to a "Get Type" method... But it doesn't work...
Do you have an idea ?
CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 6 of 8
(3,342 Views)
Nevermind, I found a solution !
I use this combination of function/method to make it work... I should have thought about it before...

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 7 of 8
(3,330 Views)
That will also work. I've never tested if there's a perfomance difference, but given the inherent lag with the LabVIEW <-->.NET interface layer I doubt it's worth considering.
0 Kudos
Message 8 of 8
(3,322 Views)