I want to read String Using serial communication

1 view (last 30 days)
My code is
s = serial('COM5');
set(s,'BaudRate',9600, 'Parity','none', 'Terminator', 'LF', 'InputBufferSize', 4500);
fopen(s);
fprintf(s, '$');
A = fgetl(s);
strlength = length(A);
while strlength < 4
A = fgetl(s);
strlength = length(A);
end
A
fclose(s);
delete(s)
clear s
on the other hand microcontroller continuously
transmitting sting 012crlf
i just want to display first three digits wha should i do..??

Answers (2)

Walter Roberson
Walter Roberson on 17 Apr 2014
Your code appears to be written to read lines until it finds one that is 4 or more characters long and then to display that line.
If all you want is to display the first three digits then just read a single line and display the first three characters of it.
A = fgetl(s);
A(1:3)

Sagar Sojitra
Sagar Sojitra on 17 Apr 2014
i mean my data is coming continuously and i need to continuously display it... daa is coming like
100crlf 120crlf 200crlf 040crlf
and i just want to display first three digit continuously so this will work...???

Community Treasure Hunt

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

Start Hunting!