I want to read String Using serial communication
1 view (last 30 days)
Show older comments
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..??
0 Comments
Answers (2)
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)
0 Comments
See Also
Categories
Find more on Acquisition Using Any Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!