Drive thorlabs Motorized Microscope Focus Controller with matlab

Hi All
I am working on control Thorlabs focus drive MFC1 with Matlab. Thorlabs only offers its command function in header file ( ZStepper_SDK.h) in C++ and library ( ThorZStepper.dll; ThorZStepper.lib). They don't provide the source code. I am thinking about loading the library in Matlab with function "loadlibrary". It works for examples in mathworks. However, when I tried it with Thorlabs file
loadlibrary('ThorZStepper.dll','ZStepper_SDK.h')
, error came out:
Does anyone know how to fix the problem or any other way to control the focus drive with Matlab. I appreciate it a lot.

Réponses (1)

Walter Roberson
Walter Roberson le 12 Oct 2018
Modifié(e) : Walter Roberson le 12 Oct 2018
In C, & is the unary operator used to take the address of something, or is the bitwise "and" operator. Either way, it is an operator, and cannot appear in a type declaration -- only in an executable expression (such as to initialize a variable.)
In C++, & can also be used in type declarations https://en.cppreference.com/w/cpp/language/declarations to indicate lvalues . This is the first time I have seen that described so I do not presently understand quite what the difference is compared to some of the other forms.
The code you are compiling uses & in type declarations. That means that the code is illegal as standard C -- although possibly valid under some extension.
MATLAB's loadlibrary() can only work with C language .h files, not with C++ header files. (The .h file could potentially be dual-purpose, as long as it protected the C++ specific portions with a #if or #ifdef )
Starting in R2018a, a new C++ MEX API was added to make it easier to call MATLAB from within C++. However, that interface does not provide any added support for calling third-party C++ from within MATLAB.

Communautés

Plus de réponses dans  Power Electronics Control

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by