LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

New in labview: i want send a cluster to a function in c#. I can not.

i want send a cluster to a function in c#. I can not.

I make a cluster with one field for example, a int field.

I made a dll, a class with a member that get a parameter. This parameter is an object of a class with the same fields than in the cluster. I use the "to .net object" tool from labview and another tool for generic class and there is not errors in compilation but yes in runtime.

In general, is it possible send a cluster to a .net member of a class?

How work the "to .net object"? i can not use it.

 

Thank you. I am new with labview totally.

0 Kudos
Message 1 of 12
(4,169 Views)

Well, if you are "new to LabVIEW", does it make sense (to you) to start with becoming skilled in "pure LabVIEW code" before trying to worry about advanced topics like calling a C++ function through a DLL.

 

I believe that the C++ structure analogous to a Cluster is the Struct.  Does your DLL accept Structs as inputs (or outputs)?

 

Bob Schor

0 Kudos
Message 2 of 12
(4,124 Views)

I am new on labview but i am studing it about some weeks. I know the basic, and a can do dll with c# (not c++, i said c#) and reciebe parameters from labview, single types and arrays but... i need pass from labview to the dll a cluster.

My class c# can accept an object, or a struct or a generic object, it does not matter.

I can not understand how works the "to .net object" icon of labview, i thought it would be the way to convert a cluster to a object and then pass it to my dll but i can not.

In general: how can i pass a cluster to a member function of a class on c#? How works the "to .net object"? Is it for anther thing?

Some example working would be useful.

 

Thank you!

0 Kudos
Message 3 of 12
(4,098 Views)

The test that does not work (sending a cluster):

 

View images.

Download All
0 Kudos
Message 4 of 12
(4,081 Views)

What if you change numeric in cluster to int (right click numeric -> Representation) to match type? They even have different sizes...

Though in 2011, help for "To .NET object" says 

>> Converts a LabVIEW data type to a .NET object. You can convert numeric (except extended precision and complex), string, Boolean, timestamp, path, .NET refnum, and array data types.

Though cluster of simple type may work.

0 Kudos
Message 5 of 12
(4,052 Views)

Hello. I have convert the numeric field in clusters (both, in and out) for i32 type.

The result is the same. If i run the program (see images before), there is a run time error in labview, just in the to .net object box and labview says "error 1199 ocurred at invoke node in to .net objct.vi"

 

"Cannot covert the specified labview type to .net object"

 

1) what is wrong with my test?

2) can i send a cluster to a member function .net in wich it has an object parameter (object from a custom class or even the class object).

 

Thanks

0 Kudos
Message 6 of 12
(4,029 Views)

Check help for "To .Net object.vi"

in LabVIEW 2011, help for "To .NET object" says 

>> Converts a LabVIEW data type to a .NET object. You can convert numeric (except extended precision and complex), string, Boolean, timestamp, path, .NET refnum, and array data types. 

So you can not convert cluster to .Net object.

Change your function to accept string with known byte order and "Flatten to String.vi" in LabVIEW

0 Kudos
Message 7 of 12
(4,025 Views)

Well, if it is impossible pass from cluster to .net object with the "to .net object" box ok.

But i want to pass a cluster (with some fields) to a member function in a .net class. How can i do it?.

 

Class A

{

     Int a;

     String b;

}

 

Class B

       void test (A cluster)

       {

          ....

        }

}

 

In labview:

 

I create a cluster and in it a int and string field (same fields than class A)

 

How pass the cluster to the "test" function?

 

0 Kudos
Message 8 of 12
(4,022 Views)

Try to use struct instead of class:

 

 

public struct A
{  
    public int price;  
    public string title;  
    public string author;  
}  

There is a small but not unimportant difference between .Net structs and .Net classes.

 

Not sure it will work, but it's at least worth a try. You shouldn't need the LabVIEW to .Net Object function then.

 

Also why do you write the variable types with uppercase? That looks more like Java than C#. (Yes there are many such cosmetic differences between the two, maybe to attempt to hide where much of the inspiration for C# was coming from Smiley Happy)

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 12
(3,996 Views)

1) I wrote it improvised at that moment from a tablet and it put the letters in capital letters, it was not real copied code but improvised code written by me at that moment.

 

2) Precisely the first time I tried it was with structs, and I could not pass it. Then i saw what happened with "to .net object" and said that it had to be with classes and not structures, and here i am, stuck with this. If someone had a very simple example to send a simple cluster (with a numeric field and another string for example) to a function in a class in .NET would appreciate it. The labview part and the .NET part so we can see the solution with ease.

Upper i put two images of c# code and labview code.

 

Thank you.

0 Kudos
Message 10 of 12
(3,973 Views)