Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing 2-D array from Labview to C#

I am trying to figure out using network variables to pass a 2-d array from LV to C# (and vice versa).

I created a simple vi with a 2x3 array custom control which looks like:
1 2 3
4 5 6

In C# the recieved variable looks like:
[0,0] 1
[0,1] 4
[0,2] 2
[1,0] 5
[1,1] 3
[1,2] 6

So it looks like instead of being stored in memory in row/column form (1 2 3 4 5 6) it's being stored in column/row form (1 4 2 5 3 6). So how do I convert from the LV form to the C# form, or am I thinking of this the wrong way?

Chuck
0 Kudos
Message 1 of 6
(5,045 Views)
Hey Chuck,

I am able to see exactly what you are talking about.  It is a bit weird, and it is due to the way LabVIEW stores its data internally.  If you test sending data from LabVIEW to LabVIEW through a network variable (shared variable), the data is interpreted correctly.  I am currently looking into this further, but in the mean time you could send your array of data through a simple algorithm (in the C# environment) that would correct the mis-interpretation.  You would need to send the data through this function before you send data to LabVIEW and after you receive it from LabVIEW.  I hope this helps, and I will let you know more if there is more to it than this.
Best Regards,
Software Engineer
Jett R
0 Kudos
Message 2 of 6
(5,022 Views)
Hi Jeff,

Thanks for the reply. I thought about writing my own array processing routines, which shouldn't be very difficult, but I hoped that Measurement Studio already had that. Unfortunately, it doesn't seem as simple as transposing.

Thanks.

Chuck
0 Kudos
Message 3 of 6
(5,020 Views)
Sorry Jett about getting your name wrong. My eyes aren't what they used to be.

Chuck
0 Kudos
Message 4 of 6
(5,019 Views)
Hey Chuck,

Basically, LabVIEW and a few other programs store 2-D arrays in Column-Major Order, while C and .NET program store 2-D arrays in Row-Major Order.  To send data between these two standards you will need to convert the data somewhere.  If you want to standardize on the Row-Major Order, you can call the below ConvertToRow VI before you write to your shared variable in LabVIEW.  You will also need to pass your data through the ConvertFromRow VI after you read from the shared variable as well.

For more information on the different orders, there is a Wikipedia article on this topic: Row-major order.  I hope this helps.  Also, these VIs are saved to version LabVIEW 7.1 for compatibility.
Best Regards,
Software Engineer
Jett R
Download All
0 Kudos
Message 5 of 6
(5,009 Views)
Hi Jett,

Thanks for the info. I'll be implementing the fix in the C# code since the LV program is done and the C# program is just a utility.

Also, it looks like that while LV is using Column-major order, the network variable reports the array size as the same at both the LV and C# end. That made it a bit confusing since the LV array and the C# array won't be transposes for the purpose of using the transpose function.

The wiki had a good discussion of the issue.

Chuck
0 Kudos
Message 6 of 6
(4,999 Views)