DLL handle using libpointer
9 ビュー (過去 30 日間)
古いコメントを表示
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
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
2011 年 5 月 2 日
If you have trouble with the link search support for "loadlibrary typedef void".
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Call C from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!