Problem using array in MATLAB with external library from DLL

5 views (last 30 days)
I am using MATLAB to control Thorlabs software. I am having trouble with any of the functions from the imported library that need to return arrays. Here is an example of my code I am using and the description from the manual: my code:
waveType=libpointer('int32Ptr',0)
pupil=libpointer('int32Ptr',1)
arraywavefront=zeros(spotsy.value,spotsx.value,'uint16');
calllib('WFS_64','WFS_CalcWavefront',hdl.value,waveType,pupil, arraywavefront);
I am having trouble with the arraywavefront syntax. when I look at arraywavefront after calling this function, it is still a 2D array of all zeros. I have also tried:
array=zeros(spotsy.value,spotsx.value);
arraywavefront=libpointer('doublePtr',array)
which gives me the error "Error using calllib, Array must be numeric or logical"
For context, here are the parameters from the library:
WFS_CalcWavefront(instrumenthandle, ViInt32 waveType, ViInt32 pupil, float arrayWavefront[]);
for the arrayWavefront parameter:
float[], this parameter returns a 2D array of float containing the data
would love any help or insight anyone can offer! Hope this is enough context/code

Answers (1)

Manish Annappa
Manish Annappa on 12 Jul 2017
As I understand from your description, you want 'arraywavefront' to be modified by the shared library. According to the link below 'libpointer' is the correct function to be used for this scenario.
The prototype of the function 'WFS_CalcWavefront' shows that 'arrayWavefront' parameter is of float type. According to the link below, corresponding data type in MATLAB for C type 'float *' is 'singlePtr'. Make changes in 'libpointer' statement accordingly.
  1 Comment
Cameron Park
Cameron Park on 13 Jul 2017
right, but the minute I change it to
array=zeros(spotsy.value,spotsx.value);
arraywavefront=libpointer('singlePtr',array)
matlab gives me an error window and says it needs to close immediately. So still unsure what the problem is.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!