LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate and use Matlab(R2007) .dll's in Labview

Is there a step-by-step example on how to generate and use Matlab(R2007)  .dll's in Labview.

Our experimenal hardware is LabView-controlled and we want to pass images/2d intensity arrays to a more complex matlab program that will return an array of extracted data which we want to use in LabView again.

 

Thank you

 

Carsten

0 Kudos
Message 1 of 6
(5,288 Views)

Hi,

 

Is there a reason so you don't use a "MATLAB script" inside a VI?

 

Michael. 

Message Edited by mishklyar on 03-14-2009 02:19 PM
_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 2 of 6
(5,236 Views)

Hi,

 

we only have a very limited number of Matlab lincences to use and it would be a waste to prepare the experiments and then not be able to do them because there are no free lincences at that time.

 

Dan

0 Kudos
Message 3 of 6
(5,207 Views)

I recommend having a wrapper created around the matlab dll that converts the datatypes for you. There is a lot of fooling around with pointers involved which is very difficult in LabVIEW. btw, this got much more complicated after Matlab 7. Essentially, you need to convert your inputs into mxArrays, and then add those mxArrays to an mxArray list that you pass by pointer into the matlab dll. You also need to create a mxArray list for the outputs from the dll which you will need to extract your data out of before converting it back into a LabVIEW supported datatype. It's a big hassle. We do this pretty often, but we have created a c library that handles all the conversions, so it is feasible for us. Unfortunately, I can't share the library, but hopefully this information will help you get where you want to be.

 

Like I said, it would be easier if you can just get a c developer to write a wrapper for you to keep it simple in LabVIEW. Alternatively, you might try getting your m-code to work in Mathscript.

 

Chris

0 Kudos
Message 4 of 6
(5,194 Views)

Hi again,

 

so what we tried was to edit the Matlab compiler generated c-wrapper (using the -c option) accordingly and change the header. How can we then use this to compile this into the dll?

 

(it then looked like this:

LIB_say_C_API
bool MW_CALL_CONV mlfSayzero(int nargout, double* pMout)
{
    mxArray* ppM;
    bool answer;
    ppM = mxCreateDoubleMatrix(1, 1, mxREAL);
    answer =  mclMlfFeval(_mcr_inst, "sayzero", nargout, 1, 0, ppM);
    pMout = mxGetPr(ppM);
    mxDestroyArray(ppM);
    return answer;
}

 Anything fundamental that we are missing? Unfortunately, we are not even convinced if the inititialization works right.

 

Dan

0 Kudos
Message 5 of 6
(5,187 Views)

We have never done it that way. It may be possible, but I don't know.

 

Just one more note, you will see this discussed elsewhere here, but when you call the dll you need to initialize it, but don't call the terminate function. These happen once for your labview instance, not for your vi, so if you call terminate, you won't be able to run your vi again until you close and restart labview.

0 Kudos
Message 6 of 6
(5,173 Views)