LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL 2D Input Output

Hi all,

 

I have been lately attempting to work with DLLs in LabVIEW. I have attempted single element and 1D input/output DLL in LabVIEW, and they work perfectly well. Further, when I attempted the 2D input/output DLLs they don't seem to work. Here is a simple example I started with:

 

block.PNG

 

And the following is the definition of prototype, which was auto generated. In the 1D input/output scenario it asked for a size of the array, but in case of 2D although I know it is expected, but there is no such parameter in the definition. 

  

dll_call_prototype.PNG

 

 

I request the community to please help me solve this silly problem I am facing, which probably would also be beneficial to other users. 

 

Thank You.

0 Kudos
Message 1 of 4
(2,161 Views)

What doesn't work?  Where are the project files with build specification and VIs? Pics are pretty, but totally useless to debug such things.

 


@patilrp1 wrote:

 

And the following is the definition of prototype, which was auto generated. In the 1D input/output scenario it asked for a size of the array, but in case of 2D although I know it is expected, but there is no such parameter in the definition. 


That's most likely caused because the DLL Builder doesn't allow you to specify a C array pointer as parameter. Instead the DLL interface exports a function that takes native LabVIEW array handles. As such you have to configure the Call Library Node to also pass the native array handle to the function.

And the reason is that 2D (and nD) arrays in C are not well defined. You can create them in C in many different variants, whatever your fancy makes you choose and the DLL Builder would be hard pressured to offer you a choice for every possible option there exists. So instead of providing a feature that will be in many cases wrong, it's easier to not provide it at all!

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 4
(2,112 Views)

Thank you for the insight @rolfk. I had previously not attached project files due to compatibility issues users have.

 

Please find the attached example i.e. a simple test case to square a 2D array (main.vi). The attached files are built in LabVIEW 2019. Aim was to generate a DLL to square a 2D array.

 

Yes I understanding calling DLL files built in C or any other language to say could be easier to adapt in LabVIEW since they are programmed accordingly.

 

Also a solution for my problem would be simply reshaping the 2D array into 1D and reshape it later. I know that would work too. But that also means I will have to keep reshaping 2D arrays for ever iteration. Which for smaller arrays is not an issue but something like a 1024 x 512 array can be computationally complex. 

 

Therefore I hoped if it is possible to pass a 2D array and get a 2D array out directly. 

 

On clarification of the above said doubts, I can adapt the understanding to more complex programs.

 

Thank You.

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

@patilrp1 wrote:

 

Therefore I hoped if it is possible to pass a 2D array and get a 2D array out directly. 

 


It is possible but only as LabVIEW native data array handle. Now while that of course can work, it only works seamlessly if you call this DLL from LabVIEW. But that is not very interesting as if you call that code from LabVIEW, you can have that alot easier without going the detour over an external DLL.

 

For calling this DLL from C you have to do some extra work in your C program. The DLL exports additional functions to create, resize and deallocate the necessary array variable in your C program. Check out the according header file that the DLL Builder generated!

 

#include "mul2d.h"

int32 i, j, arraySizes[2] = { 2, 1024 };

DoubleArray result = NULL;
DoubleArray source = AllocateDoubleArray(&arraySizes);
if (source)
{
	for (i = 0; i < (*source)->dimSizes[0]; i++)
	{
		for (j = 0; j < (*source)->dimSizes[1]; j++)
		{
			(*source)->Numeric[i * (*source)->dimSizes[1] + j] = something;
		}
	}

	mul2d(&source, &result);

	// Access result array data
	for (i = 0; i < (*result)->dimSizes[0]; i++)
	{
		for (j = 0; j < (*result)->dimSizes[1]; j++)
		{
			something = (*result)->Numeric[i * (*result)->dimSizes[1] + j];
		}
	}

	err = DeAllocateDoubleArray (&result);
	err = DeAllocateDoubleArray (&source);
}

 

Please note: this is not ready to compile code, only a general idea what needs to be done. If you have trouble to understand this, you should probably reconsider wanting to use DLLs.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,091 Views)