clc;
close all;
data_att = zeros(1,256);
portnum1 = 10;
comPortName1 = sprintf('\\\\.\\COM%d', portnum1);
TG_BAUD_115200 = 115200;
TG_STREAM_PACKETS = 0;
TG_DATA_ATTENTION = 2;
path = 'C:\Users\Downloads\matlabdll\thinkgear.h';
path1 = 'C:\UsersDownloads\ThinkGear_Connector\ThinkGear_Connector\ThinkGear.dll';
loadlibrary(path1,path);
fprintf('Thinkgear.dll loaded\n');
dllVersion = calllib('Thinkgear', 'TG_GetDriverVersion');
fprintf('ThinkGear DLL version: %d\n', dllVersion );
connectionId1 = calllib('Thinkgear', 'TG_GetNewConnectionId');
if ( connectionId1 < 0 )
error( 'ERROR: TG_GetNewConnectionId() returned %d.\n', connectionId1 ) ;
end;
errCode = calllib('Thinkgear', 'TG_Connect', connectionId1,comPortName1,TG_BAUD_115200,TG_STREAM_PACKETS );
if ( errCode < 0 )
error( 'ERROR: TG_Connect() returned %d.\n', errCode );
end
fprintf( 'Connected. Reading Packets...\n' );
i=0;
j=0;
disp('Reading Brainwaves');
figure;
while i < 20
if (calllib('Thinkgear','TG_ReadPackets',connectionId1,1) == 1)
if (calllib('Thinkgear','TG_GetValueStatus',connectionId1,TG_DATA_ATTENTION ) ~= 0)
j = j + 1;
i = i + 1;
data_att(j) = calllib('Thinkgear','TG_GetValue',connectionId1,TG_DATA_ATTENTION );
disp(data_att(j));
plot(data_att);
title('Attention');
pause(1);
end
end
end
disp('Loop Completed')
calllib('Thinkgear', 'TG_FreeConnection', connectionId1 );