LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get .net ref to array in LabVIEW

Solved!
Go to solution

Is it possible to get the necessary "Ref" for the dInterpCounts function. See the attached bmp.

 

Thanks and Best Regards,

Gary

0 Kudos
Message 1 of 10
(4,535 Views)
What is the method expecting? We do not have this "Spectrometer" class.
0 Kudos
Message 2 of 10
(4,534 Views)

Hi there

 

First try would be to create a new constructor node, select the "Spectrometer" namespace and select the "dInterpCounts" object the same way you created the Spectrometer constructor node. But this is just a wild guess because i don't have that assembly.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 3 of 10
(4,532 Views)

Thanks.  I looked for dInterpCounts in the Spectromter and it isn't there.

 

The developer is using C#. Looking below you will see "if (this._spectrometer.GetWaveInterpData(ref dArray).Equals(0))".

However the Spectrometer class doesn't appear to provide me with a method or property of getting the "(ref dArray).

 

I will try to attach the Spectrometer DLL and the Interface.html to this message.

 

Thanks for the help.

:

 private void btnSpectrometerScan_Click(object sender, EventArgs e)
        {
            // Example does not use dark compensation or shutter control
            //
            dArray = null;
            float[] fArray = null;

            this._spectrometer.Init(dExp, nAvg); //, false, false);

            if (!chkRawCounts.Checked)
            {
                // Starts scan and yields wavelength interpolated data when done
                //
                if (this._spectrometer.GetWaveInterpData(ref dArray).Equals(0))
                {
                    if (darkArray != null && darkArray.Length == dArray.Length)
                    {
                        for (int i = 0; i < dArray.Length; ++i) dArray[i] -= darkArray[i];
                    }
                    btnExport.Enabled = true;
                    nStartWL = this._spectrometer.StartWavelength;
                    if (bValidCal)
                    {
                        double[] dCalArray = new double[Kcurve.Length];
                        for (int n = 0; n < dCalArray.Length; ++n)
                        {
                            dCalArray[n] = (double)Kcurve[n] * dExp;

                            // NOTE: the standard lamp and KCURVE are in Watts
                            // Check for divide by zero
                            if (dCalArray[n] >= dEPSILON)
                            {
                                dArray[n] /= dCalArray[n];
                            }
                            else
                                dArray[n] = dEPSILON;
                        }

                    }
                    this.LoadResultsListbox(dArray);

Download All
0 Kudos
Message 4 of 10
(4,514 Views)

Garyeh wrote:

Thanks.  I looked for dInterpCounts in the Spectromter and it isn't there.


And it wouldn't be there. "dInterpCounts" is the name of the argument. It's not the name of a type. I'm not sure what Chris was suggesting there.

 

That particular method accepts 2 arguments. Both are arrays of floats. The difference is that the second one is passed by "ref". All that this means is that the function assumes the caller (you) has already pre-allocated the array, and the function will attempt to update values in this array. 

 

When you call a method that takes in an array such as double[] the LabVIEW .NET interface is supposed to be able to determine the type and change the color of that parameter to indicate the type, as it does for the dScanArray, even if it's a "ref" argument. To verify this I wrote a simple class that has the same signature as the WavelengthInterpolate method. In the method I update the value of the first and last element. When I selected the method in LabVIEW the second argument was detected as being an array of doubles, so the color was orange, not green, as it would be for a generic reference type. The code ran just fine:

 

Was this assembly you have written in .NET 3 or 3.5? 

Message Edited by smercurio_fc on 10-10-2008 01:40 PM
0 Kudos
Message 5 of 10
(4,499 Views)

I'm not sure which version of .net they are using. I am using 3.5.

 

I tried wiring an array of doubles into dInterpCounts. I get a broken wire. 

 

I guess I'm not quite getting what you are saying.

 

Thanks.

0 Kudos
Message 6 of 10
(4,492 Views)

The wiring error description is

 

These cannot be wired together because their data types (numeric, string, array, cluster, etc.) do not match. Show the Context Help window to see what data type is required.
The type of the source is 1-D array of single [32-bit real (~6 digit precision)].
The type of the sink is .NET Refnum.

 

Thanks.

Gary

0 Kudos
Message 7 of 10
(4,489 Views)
Solution
Accepted by topic author Garyeh

I'm saying that what I showed you is what it should look like. Since LabVIEW is interpreting the dInterpCounts as a .NET refnum you obviously cannot wire it to an array of doubles, which is a LabVIEW datatype. I do not know why you are getting that input to be a .NET refnum instead of an array. As I said, I wrote a class that has a method with the same signature as the method is your class, and LabVIEW interpreted it correctly. It's possible it has something to do with .NET 3.5..NET 3.5 support in LabVIEW has not been officially established.

 

One thing that may work is to use the To .NET Object function. This will give you a .NET refnum, but I have no idea if this will work with your method. If that doesn't work then another thing to try is to create a .NET ArrayList, populate it with your data, and then call the CopyTo method of the ArrayList class to get an Array class, which may be acceptable to your class' method.

0 Kudos
Message 8 of 10
(4,485 Views)

OK. I've got it. The problem is the version of LabVIEW. The application is being written in LV8.0. LV8.0 doesn't properly interpet the .net function I'm trying to use.

 

Thanks,

Gary

0 Kudos
Message 9 of 10
(4,467 Views)
OK. That makes sense. LabVIEW 8.0 had a number of issues with .NET.
0 Kudos
Message 10 of 10
(4,464 Views)