Home › Forums › Software Development › EyeX gaze data stream in Matlab › Reply To: EyeX gaze data stream in Matlab
09/01/2015 at 15:44 #2340
Pete
Participant
I’ve made a start with the loadlibrary method. Unfortunately my ignorance of C is a bit of a limiting factor, and I’m still not 100% sure whether it is even possible to pass handlers from Matlab to C. Nonetheless, below is my first attempt, which at least gets as far as initializing the library (before I lost the plot and gave up). Perhaps somebody with more technical expertise may be able to take it further.
if libisloaded('eyex')
unloadlibrary('eyex')
end
% specify paths to .dll, and .h files
d1 = 'D:\Dropbox\MatlabToolkits\Tobii\4. EyeX\TobiiEyeXSdk-Cpp-0.23.325\lib\x86'; % path to .dll
d2 = 'D:\Dropbox\MatlabToolkits\Tobii\4. EyeX\TobiiEyeXSdk-Cpp-0.23.325\include\eyex'; % path to .h files
loadlibrary(fullfile(d1,'Tobii.EyeX.Client.dll'), ...
fullfile(d2,'EyeX.h'), ...
'addheader',fullfile(d2,'EyeXActions.h'), ...
'addheader',fullfile(d2,'EyeXAsyncData.h'), ...
'addheader',fullfile(d2,'EyeXBehavior.h'), ...
'addheader',fullfile(d2,'EyeXBounds.h'), ...
'addheader',fullfile(d2,'EyeXClientTypes.h'), ...
'addheader',fullfile(d2,'EyeXCommand.h'), ...
'addheader',fullfile(d2,'EyeXContext.h'), ...
'addheader',fullfile(d2,'EyeXEvent.h'), ...
'addheader',fullfile(d2,'EyeXFrameworkTypes.h'), ...
'addheader',fullfile(d2,'EyeXInteractor.h'), ...
'addheader',fullfile(d2,'EyeXInternalLiterals.h'), ...
'addheader',fullfile(d2,'EyeXInternalTypes.h'), ...
'addheader',fullfile(d2,'EyeXLiterals.h'), ...
'addheader',fullfile(d2,'EyeXMacros.h'), ...
'addheader',fullfile(d2,'EyeXNotification.h'), ...
'addheader',fullfile(d2,'EyeXObject.h'), ...
'addheader',fullfile(d2,'EyeXProperty.h'), ...
'addheader',fullfile(d2,'EyeXQuery.h'), ...
'addheader',fullfile(d2,'EyeXSnapshot.h'), ...
'addheader',fullfile(d2,'EyeXStates.h'), ...
'addheader',fullfile(d2,'EyeXSystem.h'), ...
'addheader',fullfile(d2,'EyeXUtils.h'), ...
'mfilename', 'eyexM', ...
'alias','eyex')
% N.B. multiple warnings cannot be fixed because function pointers are not supported by loadlibrary
%% display
libfunctions eyex
libfunctionsview eyex
%% extract enumerated values
[methodinfo, structs, enuminfo, ThunkLibName] = eyexM; % courtesy of http://uk.mathworks.com/matlabcentral/answers/109924-accessing-enum-value-in-dlls-header-file
%% ------------------------------------------------------------------------
% Test 1, just attempt to initialize the library
%% 1
[TX_RESULT, int32Ptr] = calllib('eyex','txIsSystemInitialized',0)
%% 2
[TX_RESULT, TX_LOGGINGMODELptr, TX_THREADINGMODELPtr, TX_SCHEDULINGMODELPtr] = calllib('eyex','txInitializeSystem',enuminfo.TX_SYSTEMCOMPONENTOVERRIDEFLAGS.TX_SYSTEMCOMPONENTOVERRIDEFLAG_NONE, [], [], [])
%% 3
[TX_RESULT, int32Ptr] = calllib('eyex','txIsSystemInitialized',0)
%% 4
calllib('eyex','txUninitializeSystem')
%% 5
[TX_RESULT, int32Ptr] = calllib('eyex','txIsSystemInitialized',0)
%% ------------------------------------------------------------------------
% try to initialize a full minimal working example, as per http://developer.tobii.com/c-sample-walk-minimalgazedatastream/
% useful links:
% http://developer.tobii.com/c-sample-walk-minimalgazedatastream/
% http://uk.mathworks.com/help/matlab/matlab_external/working-with-pointers.html
% http://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk
[TX_RESULT, TX_LOGGINGMODELptr, TX_THREADINGMODELPtr, TX_SCHEDULINGMODELPtr] = calllib('eyex','txInitializeSystem',enuminfo.TX_SYSTEMCOMPONENTOVERRIDEFLAGS.TX_SYSTEMCOMPONENTOVERRIDEFLAG_NONE, [], [], [])
%%
% see EyeXClientTypes.h
% TX_EMPTY_HANDLE = 0;
TX_EMPTY_HANDLE = libstruct('txInteractionContext') % ????
TX_INVALID_TICKET = 0
TX_TRUE = 1
TX_FALSE = 0
hContext = libpointer('txInteractionContext',TX_EMPTY_HANDLE)
hConnectionStateChangedTicket = libpointer('int',TX_INVALID_TICKET)
hEventHandlerTicket = libpointer('int',TX_INVALID_TICKET)
% remember to clear these objects before rerunning: clear('TX_EMPTY_HANDLE','hContext','hConnectionStateChangedTicket','hEventHandlerTicket')
%%
[TX_RESULT, txInteractionContextPtrPtr] = calllib('eyex','txCreateContext',hContext,0) % let matlab convert to a pointer pointer (?)
%%
OnEngineConnectionStateChanged = [] % ???????
TX_RESULT = calllib('eyex','txRegisterConnectionStateChangedHandler', hContext, hConnectionStateChangedTicket, OnEngineConnectionStateChanged, [])
%....
%
% TX_RESULT = calllib('eyex','txRegisterEventHandler(hContext, &hEventHandlerTicket, HandleEvent, NULL)')
% TX_RESULT = calllib('eyex','txEnableConnection(hContext)')