Problem using array in MATLAB with external library from DLL

4 次查看(过去 30 天)
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

回答(1 个)

Manish Annappa
Manish Annappa 2017-7-12
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 个评论
Cameron Park
Cameron Park 2017-7-13
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by