ā04-23-2010 03:59 PM
I have a VI that I am calling from a C# app using the ActiveX VirtualInstrument method. I need to pass a reference to a C# object to my VI. What I've tried to do is create a Control of type Variant on my VI Front Panel, I also added a .NET RefNum object and I set the .NET Class to be my desired C# type. From my C# code I call VirtualInstrument.SetControlValue and I pass my reference.
On the VI side I take the output of my Variant control and input that into a 'Variant To Data', I connect my .NET Refnum to the type input of my 'variant to data' so I'm basically trying to cast my variant to my desired .NET type.
If I take the output of my 'variant to data' object and input that to an invoke node I can see that I get all of the methods of my .NET object so that seems to be the right thing to do. The problem is in passing my reference. I end up getting a type mismatch error at my 'variant to data' when I try to run.
I guess this isn't the proper way to pass a reference. Could somebody please help me and tell me the right way to do it?
VirtualInstrument vi = labVIEWAPP.GetVIReference(myPath, "", false, 0);
vi.OpenFrontPanel(true, FPStateEnum.eVisible);
vi.SetControlValue("Variant", m_myRef)
I've attached a screenshot of the relevant part of my VI
Thanks and regards
Mike
ā04-24-2010 06:17 AM
ā04-24-2010 11:38 PM
A refnum created in one application environment is not the same as a refnum created in a different application environment. For example, a file refnum created in C is in no way the same as a file refnum created in LabVIEW, even though they're both file refnums.
What exactly are you trying to do in the LabVIEW side? Why not just call the .NET assembly from LabVIEW?
ā04-25-2010 05:24 AM
ā04-25-2010 07:29 AM - edited ā04-25-2010 07:31 AM
If you tell LabVIEW that you pass it a variant you better make sure you create a correct variant from your reference. A variant is a very specific datatype in Windows (that can wrap many different datatypes) it is not equivalent to any datatype including references but simply a wrapper around most possible datatypes. So you must make sure you wrap your reference accordingly. There still is a possible difficulty since LabVIEW variants are not exactly the same as Windows variants. Most internal variant functions can deal with them both but I'm not sure that assigning a Windows variant to a LabVIEW variant exactly would work.
Also you seem to want to use the external reference as an object reference but that is likely not gonna fly as easily. LabVIEW refnums are not the external reference directly but a specific LabVIEW datatype that again wraps the native reference such as ActiveX or .Net references, but also network connections, instrument communication resources, etc.
ā04-26-2010 08:26 AM
ā04-26-2010 10:01 AM
ā04-26-2010 12:17 PM
I can compile my C# to a dll and call it directly with no problem. The problem is that I need to work with a specific object instance in LabView and I can't seem to pass a reference to this object from C# to LabView.
I've included some code that hopefully illustrates what I'm trying to do.
In the included C# Program I have a C# console application (ConsoleApp) and a very simple C# class (SimpleClass).
In the attached LabView VI OpenCSharpFromLabView I use the .NET Constructor object to create an instance of SimpleClass and call a function on it, that works great.
Now what I can't figure out how to do....
In my C# Console application I create an instance of SimpleClass (myClassA) and I call some some properties/methods on this instance...now I need to pass this instance (myClassA) to a LabView VI. In PassRefFromCSharpToLabView I've tried do this by adding a Variant control and trying to cast that to my .NET Type (SimpleClass). But I can't figure out how to do it. The code in this VI does not work, I get an error that the To .NET Object VI can't convert a variant, I also tried to use the Variant To Data object but I get a type mismatch error.
So I'm trying to figure out how to pass a reference to a specific instance of an object into LabView and work with that specific instance.
Thanks
Mike
ā04-26-2010 12:42 PM
Yamaeda wrote:
Compile the C# program as a .dll and call it directly?
I would rather create a .Net assembly exporting an entire interface including the right object types.
ā04-16-2012 04:41 PM
I came across the same situation. I need to pass the reference of .Net Object (Instance) to LabVIEW VI as parameter.
But seems that we cann't pass the .Net Object reference to labVIEW.
Anybody found the work arround for passing .Net object reference to and fro from LabVIEW.
Hemant