Matlab - Callback Function of a serial port that dont know the reference -



Matlab - Callback Function of a serial port that dont know the reference -

hello i'm using library of thinkgear connect bluetooth mindwave matlab need stablish callback function of serial port dont have reference of port.is there anyway it? dont want loop code: code

portnum1 = 5; %com port # comportname1 = sprintf('\\\\.\\com%d', portnum1); % baud rate utilize tg_connect() , tg_setbaudrate(). tg_baud_57600 = 57600; % info format utilize tg_connect() , tg_setdataformat(). tg_stream_packets = 0; % info type can requested tg_getvalue(). tg_data_raw = 4; %load thinkgear dll loadlibrary('thinkgear.dll'); fprintf('thinkgear.dll loaded\n'); %get dll version dllversion = calllib('thinkgear', 'tg_getdriverversion'); fprintf('thinkgear dll version: %d\n', dllversion ); %% % connection id handle thinkgear connectionid1 = calllib('thinkgear', 'tg_getnewconnectionid'); if ( connectionid1 < 0 ) error( sprintf( 'error: tg_getnewconnectionid() returned %d.\n', connectionid1 ) ); end; % set/open stream (raw bytes) log file connection errcode = calllib('thinkgear', 'tg_setstreamlog', connectionid1, 'streamlog.txt' ); if( errcode < 0 ) error( sprintf( 'error: tg_setstreamlog() returned %d.\n', errcode ) ); end; % set/open info (thinkgear values) log file connection errcode = calllib('thinkgear', 'tg_setdatalog', connectionid1, 'datalog.txt' ); if( errcode < 0 ) error( sprintf( 'error: tg_setdatalog() returned %d.\n', errcode ) ); end; % effort connect connection id handle serial port "com3" errcode = calllib('thinkgear', 'tg_connect', connectionid1,comportname1,tg_baud_57600,tg_stream_packets ); if ( errcode < 0 ) error( sprintf( 'error: tg_connect() returned %d.\n', errcode ) ); end fprintf( 'connected. reading packets...\n' ); %% %record info j = 0; = 0; while (i < 102400) %loop 20 seconds if (calllib('thinkgear','tg_readpackets',connectionid1,1) == 1) %if packet read... if (calllib('thinkgear','tg_getvaluestatus',connectionid1,tg_data_raw) ~= 0) %if raw has been updated j = j + 1; = + 1; data(j) = calllib('thinkgear','tg_getvalue',connectionid1,tg_data_raw); end end if (j == 256) plotraw(data); %plot data, update every .5 seconds (256 points) j = 0; end end %disconnect calllib('thinkgear', 'tg_freeconnection', connectionid1 );

matlab

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -