DLL handle using libpointer

9 Ansichten (letzte 30 Tage)
Andrew
Andrew am 2 Mai 2011
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 Kommentar
Kaustubha Govind
Kaustubha Govind am 2 Mai 2011
Do you have 32-bit MATLAB for R2008b, but 64-bit MATLAB for R2009b? Otherwise, have you examined the contents of the 'warnings' variable?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Kategorien

Mehr zu Call C from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by