How to save data from serial port to an array in Matlab gui? -


i want read serail port every 0.1s , append incoming data array, can show data time array seems store newest data. can tell me why? thanks. here code:

function wtsmat_openingfcn(hobject, eventdata, handles, varargin) ..... %%tact array store data tact=ones(1,84); handles.tact=tact; % update handles structure guidata(hobject, handles); 

here setting of scom

scom=serial(com_cur,'baudrate',baud_curnum,'parity','none','databits',8,'stopbits',1,...     'inputbuffersize',1000,...     'timeout',1,...     'timerperiod',0.1,...     'timerfcn',{@mycallback,handles}); fopen(scom); handles.scom=scom; guidata(hobject,handles); 

here mycallback function

function mycallback(scom,bytsavailable,handles) %start single frame acquisition showdata=ones(84,1); showwin=ones(14,6); %%get previous data handles tact=handles.tact; fwrite(scom,uint8(hex2dec(['aa';'aa';'aa';'20';'01';'00';'00';'8f';'83']))); mydata = fread(scom,183);%read raw data sensor i=1:84     showdata(i,1)=mydata(13+i*2)*16*16+mydata(12+i*2); end %%append tact array tact=[tact;showdata']; handles.tact=tact; .... 

save tact when close scom

function pb_close_callback(hobject, eventdata, handles) % hobject    handle pb_close (see gcbo) % eventdata  reserved - defined in future version of matlab % handles    structure handles , user data (see guidata) scom=handles.scom; %stop acquising fwrite(scom,uint8(hex2dec(['aa';'aa';'aa';'22';'00';'00';'0e';'76']))); fclose(scom); tact=handles.tact; save('tact.mat','tact'); 

try creating buffer , saving new data in last position @ every iteration

buf_len = 100; index = 1:buf_len; %initialize array arrayofdata = zeros(buf_len,1);  % data here. let's new value theta  arrayofdata = [ arrayofdata (2:end) ; theta ];  plot(index,tdata,'r','linewidth',2); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -