DLL handle using libpointer

조회 수: 9 (최근 30일)
Andrew
Andrew 2011년 5월 2일
The following code works in R2008B but seems to be broken in R2009B and beyond. I am accessing a DLL using loadlibrary. The first "FT_Open" command should give my a 'handle' to the device in the form of a libpointer. FT_Open seems to work in both versions of Matlab, but in the newer versions subsequent library calls error out with "invalid handle". Can anyone think of what may have changed in Matlab that would have effected this code? Thanks. P.S.. I've tried chaning the datatype in libpointer to other things, but nothing I tried has worked.
%-----------------------------------------------------------------
% load the DLL and add the helper funtion directory to the path
%-----------------------------------------------------------------
try
unloadlibrary ftd2xx;
end
hfile = 'ftd2xx.h';
[notfound, warnings] = loadlibrary('ftd2xx', hfile);
%-----------------------------------------------------------------
% open a handle to the device (hard coded device ID for now)
%-----------------------------------------------------------------
handle = uint32(0);
ptr_handle = libpointer('voidPtrPtr',handle);
[err] = calllib('ftd2xx', 'FT_Open', uint32(0), ptr_handle);
msg = ['Open device: ' ftdi_error_string(err)];
disp(msg);
pause(1);
%-----------------------------------------------------------------
% perform some operation
%-----------------------------------------------------------------
[err] = calllib('ftd2xx', 'FT_SetBitMode', ptr_handle, uint8(0), uint8(0));
msg = ['Reset device: ' ftdi_error_string(err)];
disp(msg);
%-----------------------------------------------------------------
% close the device
%-----------------------------------------------------------------
[err] = calllib('ftd2xx', 'FT_Close', ptr_handle);
msg = ['Close Device: ' ftdi_error_string(err)];
disp(msg);
try
unloadlibrary ftd2xx;
end
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2011년 5월 2일
Do you have 32-bit MATLAB for R2008b, but 64-bit MATLAB for R2009b? Otherwise, have you examined the contents of the 'warnings' variable?

댓글을 달려면 로그인하십시오.

답변 (1개)

Philip Borghesani
Philip Borghesani 2011년 5월 2일
I believe you may have bumped into this bug in R2109b.
If you have trouble with the link search support for "loadlibrary typedef void".

카테고리

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