Passing 2D Arrays between LabVIEW and CVI or Measurement Studio with Network Variables Primary Software: LabVIEW Development Systems>>Base PackagePrimary Software Version: 8.5.1 Primary Software Fixed Version: N/A Secondary Software: Measurement Studio>>.NET Support
Problem: When I pass a 2D array of data from LabVIEW to another programing environment, such as CVI or Visual Studio, the data becomes garbled. I am using a shared variable or network variable as the communication layer For example, I have a 2 x 3 array in LabVIEW that looks like this:
When I read the data in another environment it looks like this:
Solution: This mis-interpretation occurs because LabVIEW and other programs internally represent 2D array differently. LabVIEW along with a few other program use the Column-Major Order to represent 2D arrays, while C and .NET programs represent 2D arrays in Row-Major Order. Basically, LabVIEW stores the following array
in memory as 1, 4, 2, 5, 3, 6. This same Example Array is stored in C or a .NET language as 1, 2, 3, 4, 5, 6. When you pass data between these two different languages, it is passed in a flattened form (the list of numbers). The order type information is not passed with the array, and thus the mis-interpretation. You can fix this by writing an algorithm that will change one format into the other. Just pick which order you want to standardize to and convert. For example, if you wanted to standardize on the Row-Major Order, you would need to convert data being passed from LabVIEW into the shared variable from Column-Major Order to Row-Major Order. When you read data from the shared variable in LabVIEW, you would first need to convert it from Row to Column before you could use it. You can used the attached VIs at the bottom to do both of these conversions. See the below screen shot of how to use these VIs in LabVIEW. The VI with the icon picture "Convert 2-D" is the ConvertToRow.vi ![]() Note: To pass a 2D Array with network variable, you must make the network variable of type variant. Related Links: Wikipedia: Row-Major Order Attachments:
Report Date: 01/31/2008 Last Updated: 05/23/2008 Document ID: 4HUH7LQX |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

