From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

complex cluster labwindows cvi

Solved!
Go to solution

Hello,

 

I am trying to convert some code from LabVIEW to LabWindows/CVI DLLs to meet some processor requirements. I am passing a cluster of parameters and variables to the DLL, some of the elements of which are arrays. My question is two fold:

  1. How do I reference the values contained within the array that is passed as part of my structure?
  2. In what order are multi-dimensional arrays passed from LabVIEW to a DLL (column-major or row-major order)?

To clarify number 1, if I have a type definition that reads as follows:

 

typedef struct {

    int32 dimSizes[2];

    float64 Numeric[1];

 } TD2;

typedef TD2 **TD2Hdl;

 

typedef struct {

    int16 index1;

    int16 index2;

    TD2Hdl array;

} TD1;

 

And my function prototype reads:

 

int myfcn (*TD1 input);

 

How would I reference the (index1, index2) element of the two-dimensional array array? None of the following seem to work:

 

input->array->Numeric[index1][index2];

input->array->Numeric[index1 + index2*dim1];

input->array[1][index1][index2];

input->array[1][index1 + index2*dim1];

etc.

 

Where dim1 is the length of index1. To clarify number 2, if I have a two dimensional array that has two rows and two columns:

 

[1, 2]

[3, 4]

 

Is this passed in row-major order as the list (1, 2, 3, 4), or in column-major order as the list (1, 3, 2, 4) to the DLL? This should be the order of the values stored in input->array->Numeric unless I am mistaken.

 

Thank you very much,

 

Nathan

0 Kudos
Message 1 of 4
(3,505 Views)

Sorry, I meant to say that dim1 is the length of each row/column, whichever is convenient for finding the right element in the array. 

0 Kudos
Message 2 of 4
(3,497 Views)

I've been working with Nathan via email, and wanted to include some information here as a reference to anyone else reading this thread.

 

First, here's some information on passing data of various types between C and LabVIEW:

 

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

 

The easiest way to see how LabVIEW represents data when passing to a C DLL is to drop a Call Library Function Node on the block diagram and configure the input parameters to Adapt to Type. In this case, I wired a cluster consisting of a numeric I32 and a 2D array of I32's into the input on the Call Library Function Node. Then, you simply right-click on the Call Library Function Node and choose "Create C File" to generate a C file with the proper data types and function headers. For my cluster, here was the data type created in C:

 

typedef struct {
int32_t dimSizes[2];
int32_t elt[1];
} TD2;
typedef TD2 **TD2Hdl;

 

typedef struct {
int32_t aNumber;
TD2Hdl array;
} TD1;

 

 

As you can see, the cluster is represented as a struct, so there's an int32_t (which is the I32 I had as my first element in the cluster) and a TD2Hdl type, which is the array, and is defined as a struct directly above the cluster struct. You can see that for an array, LabVIEW passes an int32_t dimSizes[] array, which is an array of all dimension sizes. The first element of this array is the number of rows in the LabVIEW array, and the second element is the number of columns. int32_t elt is a pointer to the beginning of the array.

 

A specific element in the array is accessed as elt[xIndex * numberOfColums + yIndex].

Message 3 of 4
(3,479 Views)
Solution
Accepted by topic author Engineero713

Also, as mentioned in our correspondance, LabVIEW passes arrays in row-major order, and you can dereference the (i, j) element of the array by using the call:

 

(*(Input->array))->elt[ j + i*numCols ];

 

Where Input is your TD1 object passed as a pointer to your function, so the function prototype might look something like:

 

int myFcn ( *TD1 Input );

 

Thanks for the help Daniel!

0 Kudos
Message 4 of 4
(3,436 Views)