LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

arrays as input to shared library function

Solved!
Go to solution

I've been playing with calling LV VI's using matlab.

So I built a simple VI which gets an integer as input and multiplies it by 10, I then put it in a shared library and called it from matlab- so far so good.

 

Now I tried doing the same with an array- I want to send an array to the VI and have it multiplied by 10, but when I build the .h file it seems that the function expects to get both the input array AND the output array as inputs.

 

so how can I build a shared library VI that gets an array (of a constant size if it matters) and multiplies it by 10?

 

thanks!

Download All
0 Kudos
Message 1 of 4
(2,895 Views)
Solution
Accepted by shayelk

A function in a DLL can only return a scalar, not an array, regardless of which languages are used. To return an array, instead the caller allocates the array, passes a reference to the array to the DLL, and then after the function call the referenced array contains the new data. This is why there are two parameters - the input array (actually a pointer to it) and a pointer (reference) to the output array. You need to change your MATLAB code, there's nothing you can do about this in LabVIEW. EDIT: Also note that this allows re-use of the input array as the output, if you want, by passing a reference only to the input array, and then modifying that. You can do this in LabVIEW by configuring the array parameter as both input and output.

Message 2 of 4
(2,879 Views)

thanks nathand!
I tried building the library with what you said in mind, but when I tried loading it using matlab I got the following error:

Error using loadlibrary (line 422)
Failed to preprocess the input file.
Output from preprocessor is:math.h
C:\Users\*********\math.h(1) : fatal error C1083: Cannot open include file: 'extcode.h': No such file
or directory

 

the "loadlibrary" matlab function worked just fine with the scalar VI, any Ideas why it won't work with the array VI?

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

First, make sure you configured the array parameter(s) as passed by array data pointer - any of the other options use LabVIEW-specific datatypes that may cause problems for Matlab.

 

If it still builds a .h file that includes extcode.h, you can either tell Matlab where to find that file (I'm sure there's a setting somewhere for the include search path, although I don't know where) or you can edit the .h file to remove the reference to extcode.h and replace any LabVIEW datatypes with equivalent C data types (sort-of - the reason LabVIEW defines its own types in extcode.h is to ensure consistency in the size of datatypes since C doesn't actually have a standard).

 

If that's not clear, attach the .h file or copy its contents into a reply and I'll try to help.

Message 4 of 4
(2,828 Views)