LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a Labview array into a C# ( .NET) array object

Solved!
Go to solution

HI-

I have an C#  assembly (dll) with a method that has the following signature:

 

public short SetParameterDataArray( string paramName, int occurrence, Array arrayData )

 

How can I pass an array of integers from Labview into this method?

This should be a simple task using the ,NET interfaces but I can't seem to find a solution.

 

Thanks.

 

0 Kudos
Message 1 of 16
(12,544 Views)

Hello prcatk,

 

I was poking around with the .NET constructor node, and most of the exposed objects I looked at had the typical "double[]" listed as an argument.  Unless you have already typedef'ed an array of some data type as Array you may need to go back and use the typical calling convention.

 

Something like:

 

public shrot SetParameterDataArray (string paraName, int occurrence, <somedatatype>[] arrayData)

 

the node should then have an input in LabVIEW that receives an array as an input 

Matthew H.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 16
(12,510 Views)

Yes if I change the C# source to use the "standard" [] array definition the data can be passed BUT the remaining code will FAIL unless you add more code to copy the passed data into the target class ( Array class type). Essentially you have to copy the data from the older C style data type to the C# Array class. Using .NET it should be possible to do this outside ( if for example you DO NOT have access to the source code) the called .dll. This is also complicated by the differences in the Array class support within the various ( 2.0, 3.X,4.X) .NET levels.

As more and more managed code uses the features of the Array class this will become a larger issue.

0 Kudos
Message 3 of 16
(12,488 Views)

Hello prcatk,

 

In retrospect, my thinking on that was a little backwards.  You are right that programmers will not always have access to the code that was compiled into the dlls they are trying to use.

 

If a function does expect a Array class object as it's input, wiring an array to it from within LabVIEW would be like providing an array[] to it.  It is possible to create a .NET object in LabVIEW, but the features you need must be public in order to be exposed to LabVIEW.

 

Best regards

Matthew H.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 16
(12,472 Views)

@prcngwsas wrote:

Yes if I change the C# source to use the "standard" [] array definition the data can be passed BUT the remaining code will FAIL unless you add more code to copy the passed data into the target class ( Array class type). Essentially you have to copy the data from the older C style data type to the C# Array class. Using .NET it should be possible to do this outside ( if for example you DO NOT have access to the source code) the called .dll. This is also complicated by the differences in the Array class support within the various ( 2.0, 3.X,4.X) .NET levels.

As more and more managed code uses the features of the Array class this will become a larger issue.


And where would be the problem to create the equivalent of what you need to do in your C# program to go from double[] to Array in the LabVIEW diagram? Are those .Net methods not publically callable for an application like LabVIEW? Does .Net not expose them in a way that a LabVIEW program can be written to do that translation?

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 16
(12,463 Views)

More fuel for this fire-

Here is a VEE example that allows one to directly call a C# Array class parameter. The group that originally wrote the library I'm using provided this example along with the requisite snipe about the "superior" support for .NET class entities-

 

 

 

 

using System;

 

using System.Collections.Generic;

 

using System.Linq;

 

using System.Text;

 

 

 

namespace ClassLibrary1

 

{

 

    public class Class1

 

    {

 

        public int testMethod1(Int32 param1)

 

        {

 

            return param1 * 2;

 

        }

 

        public int testMethod2(Array param1, int len)

 

        {

 

            return (Int32)param1.GetValue(0) * 2;

 

        }

 

    }

 

}

 

 

 

 

VEE-example-.png

0 Kudos
Message 6 of 16
(12,421 Views)
Solution
Accepted by topic author prcngwsas

@prcngwsas wrote:

More fuel for this fire-

Here is a VEE example that allows one to directly call a C# Array class parameter. The group that originally wrote the library I'm using provided this example along with the requisite snipe about the "superior" support for .NET class entities-


I fail to see what this proves. In LabVIEW it's more explicit, but just as doable. As Rolf indicated, the classes for the Array type are public, and fully documented, thus it's not really all that difficult.

 

Download All
Message 7 of 16
(12,415 Views)

Rolf,

The issue is that .NET does NOT expose the class constructors for the Array class-

From the MSDN "Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access."

"The Array class is the base class for language implementations that support arrays. However, only the system and compilers can derive explicitly from the Array class. Users should employ the array constructs provided by the language."

 

Here is the inheritance tree from MSDN but you can't CALL [from Labview] any of the Array class methods you need. Even in C# you have to create a .NET "object" ( Int32, String .. whatever) into the Array.CreateInstance which you can't explicitly call from Labview.

 

This support needs to be implemented into Labview not via the  currently "exposed" .NET interface.

I have no idea HOW the Labview team needs to do this but it IS possible- MATLAB supports this as does VEE.Smiley Mad

 

 

System.Object
  System.Array

 

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

 

Labview-NET fail.png

 

0 Kudos
Message 8 of 16
(12,412 Views)

OK- that's what I was looking for.

 

0 Kudos
Message 9 of 16
(12,408 Views)

Thanks- Just to be clear- WHERE in the .NET mess did you find the Array CreateInstance?

0 Kudos
Message 10 of 16
(12,402 Views)