top of page

clc
delete(instrfind);
s2 = serial('COM3','BaudRate',9600,'DataBits',8);
b=0;
for i=1:1:10
fopen(s2);
s=fscanf(s2);
c = strsplit(s,',');
%x = str2double(s);
if(length(c)==4)
    b1 = str2num(cell2mat(c(1)));
    b2 = str2num(cell2mat(c(2)));
    b3 = str2num(cell2mat(c(3)));
end

if (numel(b2)==0 || numel(b3)==0)
    %fclose(s2);
    b(i)=b(i-1);
    plot(b);
    fclose(s2)
    pause(0.01)
end 

if (numel(b2)~=0 && numel(b3)~=0)
    b(i)=b2(1)+b3(1);
    plot(b);
    fclose(s2)
    pause(0.01)
end

end

bottom of page