i am try to get the 4 sensors data from a serial port and my data lies in 13,15,17,19 bytes of a packet .I want to plot the data of each sensor in real time but i am facing problem even though one sensor is giving maximum output i couldnt see it i

1 次查看(过去 30 天)
%run('clean');
clear all;
close all;
delete(instrfindall);
s = serial('COM5'); %assigns the object s to serial port
set(s, 'InputBufferSize', 512); %number of bytes in inout buffer
set(s, 'BaudRate', 115200);
%set(s, 'Timeout',10);
%clc;
fopen(s); %opens the serial port
t=1;
disp('Running');
x=0;
y=0;
z=0;
w=0;
while(true)
a1 =fread(s); %reads the data from the serial port and stores it to the matrix a
s1=a1(13);
a=(s1-175)/80;
x =[x a];% Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
plot(x,'Color','g');
axis auto;
grid on;
hold on;
drawnow;
s2=a1(15);
b=(s2-166)/89;
y =[y b];
plot(y,'Color','y');
axis auto;
grid on;
hold on;
drawnow;
s3=a1(17);
c=(s3-168)/87;
z =[z c];
plot(z,'Color','r');
axis auto;
grid on;
hold on;
drawnow;
s4=a1(19);
d=(s4-166)/89;
w =[w d];
plot(w,'Color','b');
axis auto;
grid on;
t=t+1;
drawnow;
%a1=0; %Clear the buffer
end
fclose(s); %close the serial port
  4 个评论
Walter Roberson
Walter Roberson 2014-3-12
which sensor? How do you know it is giving the maximum value?
By the way, my house elves get all of March off to go skiing, so I have to do my own grocery shopping, leaving me out of contact sometimes.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by