08-02-2019 03:31 AM
@moonfall wrote:
Dear wiebe@CARYA and MarcDub thank you for your suggestions. I'll implement a simple .dll with MATLAB and tell you if there is still a problem, which means that the code generated through that coder has some issues when dealing with arrays. Indeed a simple .dll doing the sum of just two scalar works with no problems.
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.
08-02-2019 05:04 PM
@moonfall wrote:
The main difference is that in Labview I implement the function with the convolution, while MATLAB uses the complex-error-function as a sort of lookup table, and with this approach the generation is much faster. Indeed the implementation of the voigt lineshape with the complex-error-function has been treated with the purpose to fasten fitting algorithm of datasets similiar to the ones i'm collecting.
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. 😉
08-03-2019 04:10 PM - edited 08-03-2019 04:12 PM
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.
11-22-2019 11:24 AM
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
11-23-2019 01:21 PM - edited 11-23-2019 01:22 PM
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.
11-24-2019 03:19 PM
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.