04-25-2012 02:04 PM
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.
Solved! Go to Solution.
04-27-2012 08:35 AM
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
04-30-2012 11:36 AM
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.
05-01-2012 07:16 PM
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
05-02-2012 01:24 AM
@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?
05-15-2012 12:52 PM
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;
}
}
}
05-15-2012 01:42 PM - edited 05-15-2012 01:43 PM
@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.
05-15-2012 01:44 PM
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.
System.Object
System.Array
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
05-15-2012 01:47 PM
OK- that's what I was looking for.
05-15-2012 02:03 PM
Thanks- Just to be clear- WHERE in the .NET mess did you find the Array CreateInstance?