LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting an array from .NET

Hi

I'm trying to get an array from a .net execute file prepared for me.

I'm passing a prefilled array to the .net program and expecting to get it back with the right values.

I did this according to the examples I found on the forum.

I'm attaching a screen shot of the part of the LV StartScan sequence which should read back the values.

The other variables are returned ok but the array comes back as all zeroes.

The .NET code used for passing the arrays follows;

Does anyone have any idea what is not matched up properly??

 

public static double[] DataArray;

 

public struct ScanResults

      {

          public bool ExitState;

          public float Temp;

          public int dataLength;

      }

 

public static ScanResults GetLastScanResultsEX(ref double[] OutDataArray)

      {

            ScanResults ScanRes;

            ScanRes.dataLength = sampNumCfg * 2;

            ScanRes.ExitState = ScanExitStatus;

            ScanRes.Temp = LastTemperature;

            DataArray.CopyTo(OutDataArray, 0);

           return ScanRes;

       }

Thanks MArtin

 

0 Kudos
Message 1 of 7
(2,618 Views)

I don't see where DataArray is actually being set to anything.

Message 2 of 7
(2,604 Views)

 

Hi Knight

Thanks for answering.

Before entry into the stacked sequence there is a data array called REImArray that is given an array of constants.

In the sequence I have a property node for REImArray passing values to the .NET invoke node.

will this work properly?

 

[  I am doing this according to an example that you posted earlier;

http://forums.ni.com/t5/LabVIEW/NET-component-in-Labview/td-p/732311

Except that you received an out of bounds error.

I redid your example with a larger array (50,000) and the posted DLL.

It worked for me without the error.  I got back the same array that I gave the DLL so I don't know if it worked properly.

But I know that the array passed to the DLL because of the variable Displacement1 that was updated from my array.]

 

Again, In my problem, I think I'm passing an array of 1's and I get back an array of zero's after running the VI.

I should be getting other values.

Is the C# part done properly??

Regards MArtin

0 Kudos
Message 3 of 7
(2,596 Views)

Hi Knight

Sorry I misunderstood your question.

You were referring to the DataArray in the C# code.

The programmer says that there is some code not shown.

 

The sequence of events is as follows

 

1. I invoke the program in Sequence frame 2 (attached) for a StartScan.

   StartScan gets values from a serial device and fills the DataArray.

2. I envoke the program in sequence frame 4 for GetLastScanResultsEx.

    and GetLastScanResultsEx passes the copy of DataArray and some other variables.

 

Could the array be getting lost somewhere between the 2 invocations?

 

We just rewrote it such that when running the "StartScan" case we are including initialization (which I do in another case in the VI) of all the parameters inside this sequence.

This version works and the array is now returning values instead of zeros.

 

The problem was that I was running this vi (it's a module to be placed in another main VI) as one shot at a time.

Once for each case. The VI would stop after each run and close references to the .NET i.e taking it out of memory.

So the .NET would forget all of its initial parameters on the next cycle.

Thanks you've been a great help.

 

Regards MArtin

 

0 Kudos
Message 4 of 7
(2,580 Views)

Martin, I am trying to do the same thing you attempted in this post.

Did you ever get this to work?

Do you have any tips or sample code you could share?

 

.net struct to LV.

 

Thanks,

Dustin

 

0 Kudos
Message 5 of 7
(2,510 Views)

Hi Dustin

Yes it worked in the end after much experimentation with different ways of doing te same thing.

It was 4 years ago and I don't remember exactly what we did but.

I still have the .vi that worked. Here maybe this will help? You can compare it to the oiginal .vi with which I started.

Five frames of the procedure are included. The first 3 frames of the sequence use proprty nodes to set up the serial port and scan parameters that I want in the .NET exe program that we wrote to interface with an AD5933 evaluation board. The constructor Node sets up the path of the .NET exe program used.

The third frame, Invoke Node, passes a dummy array "REImArray" that has all its values zeroed to the .NET exe program. This array is returned from the .NET exe program with proper values inserted. The Property node gets the size of the array returned.

 Regards MArtin

0 Kudos
Message 6 of 7
(2,462 Views)

Hello guys,

 

This document can be useful in this case:

 

https://decibel.ni.com/content/docs/DOC-16079

Randy @Rscd27@
0 Kudos
Message 7 of 7
(2,369 Views)