How can I create a pointer to a structure with more than 3 elements?

8 Ansichten (letzte 30 Tage)
Hello to eveyone. I am trying to write a MATLAB code able to use the DLL library of WaveVision5 from Texas Instruments, in order to control my ADC Development board. I am just trying now to call a function from the DLL, in order to see if the library is up and working.
Of course there is a little bit to have a look at what kind of data I will need, for example the function which I am trying to call is taking in input some kind of data defined inside the library header.
Now my function is taking in input: * A pointer to a ulong (which on my MATLAB should be a int32) * A pointer to a null terminated string * A pointer to a structure composed by four ulong.
typedef struct {
/** Major */
WvWord Major;
/** Minor */
WvWord Minor;
/** Release */
WvWord Release;
/** Build */
WvWord Build;
} WvVersionNumber;
Now the problem is that I have created the first two pointers without problems, but it seems like I am not able to create a pointer to a structure containing more than 3 elements, for instance:
sm = struct('p1', int32(0), 'p2', int32(0), 'p3', int32(0), 'p4', int32(0));
sp = libpointer('c_struct',sm);
I receive the followind error:
A field does not match one in the struct.
Error in libpointer (line 18)
ptr=lib.pointer(varargin{:});
Error in ADC_test (line 34)
sp = libpointer('c_struct',sm);
Instead if I just get rid of one of those fields inside the structure, everything looks fine.
I suppose that using c_struct is not the best way to do this, how can I create the wanted pointer? Any ideas?
Best Regards, Giovanni
  1 Kommentar
dpb
dpb am 25 Jul. 2013
I've not used libpointer but it says in the doc that
P = libpointer('TYPE') returns an empty pointer to the given TYPE.
TYPE can be any MATLAB numeric type, or a structure or enum defined in a loaded library.
From that I infer that the problem is that your sm is a Matlab structure and not one from a loaded library. Looks to me like you need
doc loadlibrary
doc libstruct

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Philip Borghesani
Philip Borghesani am 29 Jul. 2013
dpb is correct the code should be something like:
% call loadlibrary to load mylib
sm = struct('Major', 0, 'Minor', 0, 'Release', 0, 'Build', 0) %let MATLAB worry about data types
verStruct=libstruct('WvVersionNumber',sm);
calllib('mylib','myfun', 0 ,'the string',verStruc);

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by