LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read an array from .net by reference in labview

Hello, 

in Labview, I Integrated with .net DLL, which has a function that returns an array of integers,

this function takes an initialized array by reference to be filled.

 

so, my problem is I can't do it with LabVIEW [I'm totally a beginner].

I need to retrieve this array and display it.

 

I attached the .net code and LabVIEW node

Download All
0 Kudos
Message 1 of 10
(1,973 Views)

any idea?

0 Kudos
Message 2 of 10
(1,918 Views)

@Peterboshra wrote:

I attached the .net code and LabVIEW node


All you did so far is attach two pictures.

0 Kudos
Message 3 of 10
(1,896 Views)

I tried to display it on the array but the values didn't come to its still zeros. 
so this is my question bcoz I don't know how to do this.

0 Kudos
Message 4 of 10
(1,849 Views)

That .Net code looks strange to me. It seems that the parameter is really a function??

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 10
(1,835 Views)

I would assume you either simply initialize an array and wire it to the input, or you need a "to.NET object" in between.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 10
(1,817 Views)

@rolfk wrote:

That .Net code looks strange to me. It seems that the parameter is really a function??


its an interop DLL the original function written in c++ with "SafeArray(int)*" Argument

0 Kudos
Message 7 of 10
(1,781 Views)

@Yamaeda wrote:

I would assume you either simply initialize an array and wire it to the input, or you need a "to.NET object" in between.


the problem is there is not input in the node

0 Kudos
Message 8 of 10
(1,777 Views)

@rolfk wrote:

That .Net code looks strange to me. It seems that the parameter is really a function??


this is how I can read the array in vb.net

Peterboshra_0-1670250754972.png

this is what shown in dotpeek 

Peterboshra_1-1670251357353.png

 

 

 

0 Kudos
Message 9 of 10
(1,762 Views)

So how exactly is it failing? Is there an error that occurs?

 

 

@Peterboshra wrote:

@Yamaeda wrote:

I would assume you either simply initialize an array and wire it to the input, or you need a "to.NET object" in between.


the problem is there is not input in the node


 

My first question for you would be are you certain that the method signature is correct? A parameter with the out keyword is not required to be initialized prior to being passed to the method. Seeing "Int32[]&" when you hover over the terminal indicates that LabVIEW is correctly identifying it as an integer array. If the signature is correct, this should function properly.

 

If the array truly must be initialized first, then the parameter should be using the ref keyword.

 

Take this example class:

 

 

    public class Class1
    {
        public static int GetSomeArray(out int[] arr)
        {
            arr = new int[] { 1, 2, 3, 4 };
            return arr.Length;
        }
        public static int FillSomeArray(ref int[] arr)
        {
            for (int i = 0; i<arr.Length;i++)
            {
                arr[i] = i;
            }
            return arr.Length;
        }
    }

 

 

Note that if GetSomeArray() did not assign a new reference to arr that it would not compile.

 

ref = the parameter being passed may be modified by the method, and must be initialized prior to calling.

in = the parameter being passed will not be modified by the method and must be initialized prior to calling.

out = the parameter being passed must be modified and does not need to be initialized prior to calling.

 

LabVIEW will not generate an input terminal for out parameters, and shouldn't really need to.

 

You can call the methods from the example class in LabVIEW like this. (It could get more complex if there were different data types involved, but for primitives like Int32 that LabVIEW can automatically handle marshalling of, it's pretty simple.)

image.png

 

0 Kudos
Message 10 of 10
(1,733 Views)