Hello, I am loading the .dll corresponding to a new piece equipment. Having never really worked with the calllib environment before I'm running into some problems. Calling functions from the .dll using calllib works for functions which do not possess any arguments (thankfully!), but I'm running into problems for those which require pointer arguments. I suspect this is an issue of improperly casting the values for the pointers.. But I've had no luck getting this to work without errors.
For example, I have two functions (to set a gain parameter) which according to the manufacturer docs has the following form
SetGain(INT ngain)
GetGain(INT* pgain)
When I load the library into Matlab R2007b and produce a detailed list of functions, I see these have the following form:
[lib.pointer, voidPtr] SetGain(voidPtr)
[lib.pointer, voidPtr] GetGain(voidPtr)
From there, in order to test that I've indeed set that parameter to an appropriate value (say 2), I write the following:
g = libpointer('voidPtr',uint8(2))
[status, gain] = calllib('lib', 'SetGain', g);
t = libpointer('voidPtr');
[status,t] = calllib('lib', 'GetGain', t);
Following the second line of code, I usually get a hardware error for invalid parameter, so clearly the input is not of the right type, but more alarmingly when I attempt to read out the Gain (which by default should be 1, even if the preceding command failed), calling the GetGain function returns an empty array. I'm certain the answer is staring me in the face. What am I doing wrong? I am defining the variable to be the correct pointer types as far as I can tell, and the first one is initialized to a realistic value.
Thanks!
Best Answer