MATLAB: Loadlibrary issue with dll

aardvarkdllloadlibraryMATLAB

Hello,
I'm trying to load a vendor dll and header file and call from Matlab. I've been able to successfully call this dll from Python, but I'm having mixed results in Matlab.
The library loads without out errors and it appears that I'm able to connect to the device (Total Phase Aardvark). However, a simple function call to turn on the target power does not work (it doesn't throw errors though).
The dll and header file are attached. Any thoughts on why this isn't completely working? Here is the code that I've been using.
%load dll shared library
[warnings, notfound] = loadlibrary('aardvark','aardvark.h');
This line returns several warnings:
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_find_devices does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_find_devices_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_find_devices_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_unique_id does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_target_power does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_sleep_ms does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_sleep_ms does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_bus_timeout does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_enable does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_enable does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_enable does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_write_stats_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_monitor_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_monitor_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_pullup does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_direction does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_pullup does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_set does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_change does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
the return variable notfound shows that some of the data types have errors which I feel may be the source of why it isn't completely working.
>> notfound
notfound =
aardvark.h
Type 'unsignedint__int8' was not found. Defaulting to type error.
Found on line 80 of input from line 79 of file H:\\Matlab\\aardvark.h
Type 'unsigned__int16' was not found. Defaulting to type error.
Found on line 81 of input from line 80 of file H:\\Matlab\\aardvark.h
Type 'unsigned__int32' was not found. Defaulting to type error.
Found on line 82 of input from line 81 of file H:\\Matlab\\aardvark.h
Type '__int8' was not found. Defaulting to type error.
Found on line 84 of input from line 83 of file H:\\Matlab\\aardvark.h
Type '__int16' was not found. Defaulting to type error.
Found on line 85 of input from line 84 of file H:\\Matlab\\aardvark.h
Type '__int32' was not found. Defaulting to type error.
Found on line 86 of input from line 85 of file H:\\Matlab\\aardvark.h
aardvark_thunk_pcwin64.c
Creating library aardvark_thunk_pcwin64.lib and object aardvark_thunk_pcwin64.exp
listing the available functions using:
libfunctions aardvark
shows all of the functions have loaded:
Functions in library aardvark:
c_aa_async_poll c_aa_i2c_monitor_read c_aa_open_ext
c_aa_close c_aa_i2c_pullup c_aa_port
c_aa_configure c_aa_i2c_read c_aa_sleep_ms
c_aa_features c_aa_i2c_read_ext c_aa_spi_bitrate
c_aa_find_devices c_aa_i2c_slave_disable c_aa_spi_configure
c_aa_find_devices_ext c_aa_i2c_slave_enable c_aa_spi_master_ss_polarity
c_aa_gpio_change c_aa_i2c_slave_read c_aa_spi_slave_disable
c_aa_gpio_direction c_aa_i2c_slave_read_ext c_aa_spi_slave_enable
c_aa_gpio_get c_aa_i2c_slave_set_response c_aa_spi_slave_read
c_aa_gpio_pullup c_aa_i2c_slave_write_stats c_aa_spi_slave_set_response
c_aa_gpio_set c_aa_i2c_slave_write_stats_ext c_aa_spi_write
c_aa_i2c_bitrate c_aa_i2c_write c_aa_status_string
c_aa_i2c_bus_timeout c_aa_i2c_write_ext c_aa_target_power
c_aa_i2c_free_bus c_aa_i2c_write_read c_aa_unique_id
c_aa_i2c_monitor_disable c_aa_log c_aa_version
c_aa_i2c_monitor_enable c_aa_open
Despite the notfounds and warnings I'm able to successfully connect to the device using:
aa_handle = calllib('aardvark','c_aa_open',0);
aa_handle returns a 1 which based on the dll documentation indicates it's a valid handle.
At this point I should be able to issue lib calls to functions such as turning on the target power. However, the device does not appear to respond to this function call (although it does using Python):
%turn on adapter power 0x03
calllib('aardvark','c_aa_target_power',aa_handle,3);

Best Answer

These lines of code :
typedef unsigned __int8 u08;
Are making use of a Microsoft extension to the c language ( __int8 ) and are not supported by loadlibrary. There may be no easy solution to the problem. I would probably make a copy of aardvark.h and edit it as need to make loadlibrary work. Your other option is to give up on loadlibrary and create your own mex file.
To make a modified version of aardvark.h work the typedefs secion might need to look like:
typedef unsigned char u08;
typedef unsigned short u16;
...
typedef char s08;
typedef short s16;
...
To get the include of aardvark to work correctly you might need to change it to
#include "aardvark.h"
That is standard c syntax if the header is in the same directory and not on the include path.
Related Question