LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array allocation and initialization with a .dll to be used in Labview


@moonfall wrote:

Dear 


You need to make a test dll to see if the calling convention is correct.

 

If you make a dll with two arrays as input, you still won't know. If the order is reversed, you'd still get the expected result.

 

Make a dll with an array and a scalar. Add the scalar to the array. If that works, your calling convention is correct.

0 Kudos
Message 11 of 16
(850 Views)

@moonfall wrote:

 


Of course you could implement the same in LabVIEW too. I do fitting on very complicated models (example) in pure LabVIEW and of course use all the tricks in the book, such as lookup tables, vectorization, and caching of intermediary results, etc. 😉

0 Kudos
Message 12 of 16
(842 Views)

An unbounded Matlab array is in reality a somewhat complicated data structure that you have to create, reallocate and deallocate by calling specific Matlab C runtime functions. The LabVIEW Call Library Node has ABSOLUTELY no knowledge about this. The standard way is to write a wrapper DLL in C which provides more LabVIEW friendly parameters and translates them into the Matlab unbounded arrays before calling the Matlab DLL function (and possibly translates similar output arrays back into LabVIEW friendly datatypes before returning to LabVIEW.

It is theoretically possible to call the Matlab C runtime functions to deal with unbounded arrays also through additional Call Library Nodes so you don’t need to create the extra wrapper DLL but this requires even more low level C programming knowledge than writing the wrapper DLL, since you will basically take over some of the work the C compiler would do for you.

Rolf Kalbermatter
My Blog
Message 13 of 16
(828 Views)

Hi, I just read your question and I have the same problem right now. Even when I generate a very simple dll with Matlab coder I can't run it in LabVIEW, the same error and often LabVIEW crashes. I was wondering if you can tell me if you could solve your problem. TNX 

0 Kudos
Message 14 of 16
(794 Views)

Just as an indication of what the original poster would have needed to do to even get close to something working, here is a snipped of the VI I tried to create for lolz according to what I know about the Matlab coder environment (not a lot)! But you definitely can NOT pass LabVIEW arrays directly to a Matlab mxArray!!! Unfortunately this VI still crashes when executing the actual voigt function, so I'm not sure where the problem is.VoigtFunction.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 15 of 16
(762 Views)

So I did finally take the sources and recompiled them in Visual Studio and suddenly don't get any crashes anymore. The code itself is pretty convoluted and there doesn't seem any effort in the Matlab Coder to make the resulting code easily readable, so I didn't try to understand where potential issues could be. I also don't know at all if the resulting graph is at all correct.

I attach the result of the VIs with my own compiled version of the DLL.                                                                         

Rolf Kalbermatter
My Blog
0 Kudos
Message 16 of 16
(733 Views)