LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Executing a DLL from LabVIEW?

Good day,

 

I am working on an image recognition application and moved recently to LabVIEW for a good real-time performance ( hopefully ). One problem that I have faced is as follows,

 

I am using cameras, and I need to get the real world coordinates for the snaps that am getting ( i.e. to calibrate my camera ). I already did that on MATLAB where i was working before using a " cook book " procedure that ends up with calling a dll file that converts a 2D coordinates to a 3D world coordinates. Now, I need to do the same in LabVIEW.

 

I read NI's "Can LabVIEW C?" , but I couldn't use the same procedure for using that dll .. the inputs for my dll are three, the calibration results file name, two points represent the 2D image coordinates. The outputs are apparently three, the three coordinates of the real world.

 

My output parameters are not the same as my inputs so how can I  define that ? I am getting the outputs same as the inputs!

 

In MATLAB, i used to write

 

[x,y,z]=ic2wc('calres.txt',100,50);

 

Any suggestions ? Do you think it would applicable to use a MATLAB function instead and then reach it from a math script ( oh , am I going really far ? ) ..

 

I know that LabVIEW has its vision VIs for calibration, but am happy with that accuracy delivered from that recipe,

 

I attach my files.

 

Any inputs are much appreciated,

 

Moh

Message 1 of 9
(12,333 Views)
You can pass to the DLL routine (via the "Call Library Node.vi") pointers to your three return variables. Search on "Configuring the Call Library Function Node" in the Labview Help for more details. I've done a lot of programming with Labview calling custom DLL functions and haven't had any problems a "wrapper" couldn't solve..
Message 2 of 9
(12,308 Views)
Well, I've read many documents including the help mentioned. still not working.
 
the main issue here is that I need three return back values, but can't set more than one! .. and of course am not getting a useful value in that too, it gives different values for that single output dependent on what i choose as a type .. amazing.
 
Labview also crashes when I change  the input values..
 
So how do you usually get more than one output ?
 
if u have any example , please post it here ..
 
thanks 
 
 
0 Kudos
Message 3 of 9
(12,282 Views)
Hello Moh,
 
Have you tried looking at the examples in LabVIEW. Open the example finder and do a search for dll - you'll find quite a few examples that show how to call a function from dll's, with varying function prototypes.
 
The help file in LabVIEW also gives lots of information about setting up the parameters to match the function prototype that you are trying to call. As does this document...
 
I've also found the following links which provide information from other users who have used a matlab dll inside LabVIEW:
 
It seems that a lot of people have created a C++ wrapper for their matlab dll, and then called this C++ dll from LabVIEW.
 
I hope this helps
 
Hannah
NIUK & Ireland
 
0 Kudos
Message 4 of 9
(12,271 Views)

Hi Hannah,

That Math Script is very useless and obsolete, or at least let's not relate it with MATLAB. It can just run the very simple examples. I have many single m-files that should be simple but Mathscript is finding syntax errors in them!

Labview crashes almost every time I try to connect a DLL. I've been browsing the links you provided and others I got via search, users obviously are facing much trouble in anything related with DLL.

a quick note for some more R&D would be appreciated 😉

Thanks for your time.

moh

 

0 Kudos
Message 5 of 9
(12,237 Views)
If you want more help, you should post a little more information than just the dll. You need to at least provide the .h file so that someone knows what the parameters are for the dll. The VI you've written would also help to see what you have tried so far.
0 Kudos
Message 6 of 9
(12,236 Views)
Yes Dennis, I agree, but there are some fundemental things that are not working the way they are supposed to. The MATLAB script node is not taking any variable and keeps on giving error 1047. The problem was in LabView 7.x because I think MATLAB 7 uses a different ActiveX than the one in previous versions, but what about LabVIEW 8? the same problem exists.
 
However, I will post more info about my problem. Your help and time are much appreciated.
 
Moh
0 Kudos
Message 7 of 9
(12,227 Views)
Hi Moh,
 
Error 1047 relates to the Matlab script node - not the LabVIEW MathScript node - so which one are you trying to use? Here is a KB which explains the error which occurs with the Matlab script node, and how to get around this
 
As for calling a dll in LabVIEW, you need to know lots of information about the dll, and sometimes there can be complexities when trying to call dlls from environments that structure complex data types differently from LabVIEW. Have you gone through the stage of wrapping the MATLAB generated dll in C yet? Or are you still trying to call the Matlab generated dll directly from LabVIEW.
 
If you are using LabVIEW 8.20 there is a new dll import wizard that can help.
 
Hope this helps, if you can post some more information about the dll you have created, then perhaps we can help more
 
Regards
 
Hannah
NIUK & Ireland
 
0 Kudos
Message 8 of 9
(12,203 Views)

Many thanks Hannah,

the MATLAB script node is fine now after replacing matscript.dll.

About accessing the DLL,

I got it that I can't access DLL from MATLAB directly and I have to create dll wrappers in C. I could reach two approaches but unfortunately none works so far.

The first one is using MATLAB's C shared library which says that the MATLAB Compiler generates a wrapper file, a header file, and an export list to be used by other applications. The attached archive has the original m file with the library after compilation and a VI that shows the trial. It gives the same error every time.

The other approach is creating the wrapper file myself using MSVC 2003. I tried to follow the steps as in this post (dllexample.zip) . I am finding difficulty in writing the wrapping function. In that example ( adding two matrices ) , the idea is to change the dimension of the matrices to 1 instead of two and then get them into the function, that should be a special case for a purpose, no? can't I get a 2D array into my function? in that example , to create the input data, it is defined:

in1=mxCreateDoubleMatrix (m,n,mxREAL);

I wanna forget about the m and n and get my matrix directly in. Please if you have a link to somewhere where they talk about data types related, let me know.

the other thing, about the library function, for example mlf* , how can I know it's inputs? it's different than the original function since it is of kind VOID.

It sounds a bit complicated, but I think it's doable,

any suggestions?

thanks,

moh

 

0 Kudos
Message 9 of 9
(12,187 Views)