LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a double 2D-array to a chart for plotting of 2 lines

Hi,

I am trying to create a wrapper function for a command which has a complicated struct type as an input. This wrapper function will be implemented using the library callback function node in labview.

Anyway I am almost there but lacked one way to pass the output of this command which is a double array(2 x m) out of the wrapper function. How should i do it?

In the library callback function node, for example, should i define as "long function(long x, long y, double** variable)" where the last entry is the output?

I tried the above but i do not really understand the extra structure that labview created in the .c code of this wrapper. Which option should i use for this output field? pointer
to data? array handler? double array handler?

I also plan to output this array into a chart to plot 2 lines (2 lines as there is a total of 2 rows in this array). Has anyone encountered this before?

Thanks

wee
0 Kudos
Message 1 of 6
(3,567 Views)
I would suggest looking at the shipping example Call DLL. It shows how to pass a 2-D array to a DLL both by handle and pointer. Notice that the 2-D array must be allocated before it goes to the DLL. You can find it in the example finder of 7.1 or under examples\dll\datapassing\Call Native Code.llb

If you do not know the size of the array needed then you will need to use the LabVIEW memory manager fucnitons which are discussed in the "Using External Code in LabVIEW" manual from the LabVIEW Bookshelf.
Message 2 of 6
(3,567 Views)
Hi Evan,

Thanks for your answer. I still have a small problem. I am running LV7.1 on a Linux system. I cannot find the above-mentioned folders and files!

Can you attach them here so that i can download them?

Thanks a lot.

I read the "Using external code in labview" manual on the passing of array using array data pointer in Chapter 2 (p2-37), "...you should allocate an array of sufficient size in Labview, pass the array to your function, and have this array act as the buffer". How do i allocate an array of certain size? I know how to initialise an array by feeding in element and dimension to the initialise array function but not the size. Sorry if this is too elementary.

Thanks

wee
0 Kudos
Message 3 of 6
(3,567 Views)
Wee,

I have attached the example. Unfortunately you will not be able to run it because the code calls DLLs compiled for Windows. However the C code is included, so you can see how LabVIEW code and the C code are written. I think that should work, if not let me know.

As far as initializing the memory you are completely correct in using the Initialize Array VI. If you want a 1D array of 10 elements then the dimension is 10. If you want a 2D array you need to expand the Initialize Array down so you have 2 dimension terminals. You then set the size by wiring the # of elements in each dimension. So a 10x2 would have dimension values of 10 and 2. I realize it is kind of confusing but the number of dimension terminals defines the number o
f dimensions your array will have. The values you wire in are the size of those elements.

Hope this helps.
Message 4 of 6
(3,567 Views)
Hi Evan,

Cool..that is what i am confused about. Thanks a lot.

Thanks for your attachment. I will test it out later.

But this brings another question to my mind. When you have 2 dimensions in the Initialise Array VI and you need to wire the # of elements in each dimension, which indicates the row and which the column? If the top dimension entry is wired with 10 and bottom is 2, is the array a (10x2 => 10 rows with 2 columns in each row) or (2x10 => 2 rows with 10 columns each row).

One other question, if i were to pass a 2D array (2 set of data combined to form this 2D array) to both a waveform chart and a waveform graph and my purpose is to plot 2 different lines in each, should my array be in the format of (2x10) or (10x2)?


I also found that when i pass a 1D array of 100 elements to both, waveform graph plots all the 100 elements but the chart only plots 1 point. Is it got to do with the history buffer in the chart?

Thanks again.

wee
0 Kudos
Message 5 of 6
(3,567 Views)
The top dimensions is rows, and then columns.

In regards to the waveform charts and graphs. You want an array that is 2 rows and 10 columns. When you wire to the graph you should get 2 plots, and when you wire it to the chart you may get 10 plots of 2 points. If so right click on the chart and deselect "Transpose Array" or you can do the same with the transose 2D array function.

With the 1D array I am confused, the chart should still graph all 100 points, and when I tested it here it did. Can you attach the VI where the chart only displays 1 point?
Message 6 of 6
(3,567 Views)