libpointer.Value => The datatype and size of the value must be defined before the value can be retrieved.

7 vues (au cours des 30 derniers jours)
Hi everyone,
I've been trying to communicate with an FTDI cable that uses 'libMPSSE.dll'. I have read a couple of thing about libpointers here that were very helpfull. I'm now able to open the library and get some structs containing pointers.
loadlibrary('libMPSSE.dll','libMPSSE.DLL'); calllib('libMPSSE','Init_libMPSSE');
DeviceInfo = libpointer;
>> [x DeviceInfo] = calllib('libMPSSE','SPI_GetChannelInfo', 0 ,DeviceInfo);
>> [x DeviceInfo] = calllib('libMPSSE','SPI_GetChannelInfo', 0 ,DeviceInfo); %I have to do this twice for some reason?
>> DeviceInfo
DeviceInfo =
Flags: [1x1 lib.pointer]
Type: [1x1 lib.pointer]
ID: [1x1 lib.pointer]
LocId: 129
SerialNumber: [1x1 lib.pointer]
Description: [1x1 lib.pointer]
ftHandle: []
now when I try to get the value from Description for example I do:
>> DeviceInfo.Description.Value
??? The datatype and size of the value must be defined before the value can be retrieved.
>> DeviceInfo.Description.DataType
ans =
int8Ptr
Now when I look in the documentation of the .dll I get redirected to another document that tells me how the deviceInfo looks:
typedef struct _ft_device_list_info_node { DWORD Flags; DWORD Type; DWORD ID; DWORD LocId; char SerialNumber[16]; char Description[64]; FT_HANDLE ftHandle; } FT_DEVICE_LIST_INFO_NODE;
Does anyone know how I can get the value from this pointer? Thanks in advance!
Hans

Réponses (2)

Friedrich
Friedrich le 5 Avr 2013
Hi,
I guess you need to use setdatatype (take a look at the doc to get more information about that function). But I guess you need to use it like this:
setdatatype(DeviceInfo.Description,'int8Ptr',1,64)
get(DeviceInfo.Description)
Hope that helps
  2 commentaires
Hans
Hans le 5 Avr 2013
This indeed does something, now I get an array of 64 ints. I'll get back to you!
Thanks for the fast reply!!
Hans
Hans le 5 Avr 2013
Ok, I looked into this a bit more but this doesn't seem to do it for me.. If I use setdatatype() I can get an array of 64 ints as output by typing 'DeviceInfo.Description.Value' But each time I type this, I get different numbers..
Any other ideas?
Thanks again!

Connectez-vous pour commenter.


Philip Borghesani
Philip Borghesani le 5 Avr 2013
Modifié(e) : Philip Borghesani le 5 Avr 2013
What version of MATLAB are you useing? The DeviceInfo structure will not work in versions prior to R2007a.
The two calls to
>> [x DeviceInfo] = calllib('libMPSSE','SPI_GetChannelInfo', 0 ,DeviceInfo);
are a sign of problems. Only one should be needed. It is best to not use the same variable on both sides of the operation. When the input is a pointer or libstruct type then the output should not be needed.
I will guess that the first call is changing DeviceInfo from a libpointer to a MATLAB structure and then the second call is retuning an updated structure.
It looks to me that SPI_GetChannelInfo expects an allocated structure as input not a null pointer the correct code to call it should be something like:
DeviceInfo=libstruct('ft_device_list_info_node',struct('Flags',0));
x=calllib('libMPSSE','SPI_GetChannelInfo', 0 ,DeviceInfo);
get(DeviceInfo)
The data you show for DeviceInfo suggest that the header was not properly processed by loadlibrary. I suggest you examine any warnings you get from loadlibrary and fix your header files or generated prototype file so MATLAB can work with the correct data types.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by