LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Errors when Calling dll built in LabView from Matlab

I am attempting to call a .dll that was built with LV Application Builder, from Matlab. I am wondering if anyone out there has attempted this with success?

 

When attempting to load the .dll library with Matlab, I get 100's of warnings stating various functions found in a file called extcode.h were not found.  Virtually none of the functions in the extcode.h file are actually used in the .dll I created.  We have found that if we remove the include for the extcode.h from the ServoStepperController.h file, that the library will load with no errors. Does anyone know the purpose of the extcode.h file? Why is it needed when none of the functions in it are used by the dll?  One of my co-workers has successfully build a dll that we can call from Matlab and he found that he had to delete the include for the extcode.h file.

 

When we get the library to load, we find that when we attempt to call the dll and hand off various command strings to be processed by the dll it fails to accept or respond to our commands.

 

My dll is a fairly simple application that takes a command$ and COM port number string and interprets it into the format that a RMS Technologies Stepper motor controller expects. It then sends the command to the designated COM port and waits for a response from the Step Motor controller, returning that response to the MatLab script.

Download All
0 Kudos
Message 1 of 10
(5,740 Views)

So, you're creating the DLL in LabVIEW. First things first, have you tried to call the DLL in LabVIEW after you've created it? The problem could lie within the files you're using to create the DLL, with LabVIEW, or with Matlab. We want to isolate the issue and take it piece by piece. Also, can you make a simple DLL in LabVIEW and call it successfully?

 

Jordan

0 Kudos
Message 2 of 10
(5,712 Views)

Jorden,

 

Per your recommendation I called the dll from LabView and found that it wasn't handling the passing of strings back from the dll properly. I reconfigured the output $ to be a CString fomat and the LabView dll call would then work properly. The main key to getting it to work was I had to pass a string into the input string corresponding to the output string that was => in length of the expected return string.

 

We then attempted to get Matlab to call the dll. I found a second Matlab expert in our organization that has done dll calls of LV code from Matlab.  In his implementation he is able to keep the #include "extcode.h" line in his prototype file. He first believed it was because Matlab needs to have a specific compiler loaded to interpret the C code generated by LV. He loaded that compiler on my machine. However, when I attempted to load the library from the LV build dll, it still got the 100's of warning errors. So, he may have loaded the wrong compiler, or I have the wrong version, assuming that is the problem.

 

Good news is that, we were able to get the dll to function by rem'ing out the #include "extcode.h" line in the prototype file.

 

I have attached to files. dll.build.jpg shows the function prototype as LV creates it in the application builder.  The second is the Matlab code that successfully calls the dll and returns data.

 

My concern at this point is "Why do I have to delete the #include "extcode.h" line from the prototype file to get Matlab to load the dll library?" Is there critical information in this #include "extcode.h"  file that could cause me problems as I begin to use the dll in larger Matlab scripts?

Download All
0 Kudos
Message 3 of 10
(5,693 Views)

Hi John,

 

This is something else you can try.  If the compiler does not know to look in the directory in which extcode.h resides, you may need to explicitly specify it.  For example, instead of using #include "extcode.h", try --> #include "c:\program files\national instruments\labview\cintools\extcode.h", or wherever your extcode.h file is located on your system.

 

You may have seen this, but this link to one of our KBs has some good information on creating DLLs in LV. 

http://digital.ni.com/public.nsf/allkb/01BD203DE97AEBA986256800007546BB

Regards,
Austin S.

National Instruments
Academic Field Engineer
0 Kudos
Message 4 of 10
(5,675 Views)

Austin,

 

It isn't a matter of Matlab not finding the extcode.h file.  It finds it OK.  I chokes on the code in the extcode.h file.  This file contains dozens of function definintions and Matlab doesn't seem to know what to do with them. I have attached a txt file that contains all the warnings that occur with Matlab executes extcode.h

 

I think one of the key is the fact that Matlab indicates it doesn't know compiler as indicated by this excerpt form the attachted file.

 

lcc preprocessor error: P:\FREEMAN\Labview\Builds\ServoStepperController\ServoStepperController\platdefines.h:116
P:\FREEMAN\Labview\Builds\ServoStepperController\ServoStepperController\extcode.h:14
P:\FREEMAN\Labview\Builds\ServoStepperController\ServoStepperController\ServoStepperController.h:1 #error directive:
"We don't know the Compiler"

 

Apparently one can tell Matlab which preprocessor to use. One of my co-workers told me that I needed the lcc preprocessor which I have installed. But, as you can see that doesn't seem to work.  ???

 

Thanks,

 

John

 

0 Kudos
Message 5 of 10
(5,668 Views)

John,

 

Sorry that you're still not having any luck with this.  To be honest with you, since the .dll from Labview works, but you're having issues reading it in Matlab and the 'include extcode.h' function, this sounds like something that you might want to give Mathworks a call about.  If you find out from them that it is actually an issue with something in the Labview .dll, then it'll be easier for us to figure out what's causing the issue from Labview on our end since we'll know it's not an issue with Matlab.  Right now, though, it's sounds pretty convincing, based on the troubleshooting information that you've given, that it may in fact be an issue with the Matlab .dll call function. 

Regards,
Austin S.

National Instruments
Academic Field Engineer
0 Kudos
Message 6 of 10
(5,653 Views)

Austin,

 

I sent the same exact files to Matlab as were attached in my last post. Here is the response I got from Matlab late yesterday. 

 

 

Hello John,

I am writing in reference to your Service Request # 1-EM046Y regarding 'Errors when Calling dll built in LabView from Matlab'.


I did look at the warning messages, but unfortunately, since these warning messages are generated by EXTCODE.H, which is a LabView header file, it is out of the scope of our Technical Support as this may require understanding of LabView.

Unfortunately at this point it is difficult to say how LabView is creating this file and what makes it not work in MATLAB.


Sincerely,


Tanveer Sure

Application Support Engineer
Technical Support Department
MathWorks
Phone: (508) 647-7000 option 2

 

Interesting that he made no acknowledgement about the unknown compiler or the need to have a special compiler installed with Matlab.

0 Kudos
Message 7 of 10
(5,650 Views)

Hi John,

 

I'd like to know if you finally got a solution on this issue. I got the same problem now, and would like to see if I can benefit from your findings.

 

Thanks,

Yanchu

0 Kudos
Message 8 of 10
(4,821 Views)

I never was able to successfully call the dll. I eventually abandoned the effort and ended up using Matlab stand alone.

0 Kudos
Message 9 of 10
(4,792 Views)

jjhnfr,

 

Had the same problem when matlab does not like something in extcode.h file. #error directive: "We don't know the Compiler"

 

It seems that the only thing my DLL used from extcode.h (technically from fundtypes.h) were int32_t and similar definitions

       typedef int             int32_t;
       typedef unsigned int    uint32_t;

 

If I replace them manually for Matlab and do not show Matlab extcode.h, dll works fine.

Dll is calling daqmx, transfers arrays of data.

 

Do not know, when (if) the problem becomes a problem, but it is not now.

 

0 Kudos
Message 10 of 10
(4,300 Views)