Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Matlab having problem interpreting streamed string into numbers.

조회 수: 1 (최근 30일)
fima v
fima v 2020년 10월 28일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello , i am sending 0x61 over and over which is the letter 'a' to matlab as shown bellow.
But when i want to convert the recieved letters into number and plot it gives me all NAN instead of 61 as shown bellow.
sObject=serial('COM4','BaudRate',115200,'TimeOut',10,'Terminator','LF')
Why do i get this NAN,i tried to plot and i get blank screen,why it cant convert my sent data into numbers?
Thanks.
function callbackSerial(ser,~)
global time;
val=fscanf(ser);
numval=str2double(val)
%numval=dec2bin(val);
time(16)=numval;
time(1)=[];
disp(time);
figure(1),plot(time);
end
  댓글 수: 5
fima v
fima v 2020년 10월 29일
Hello Rik, to your question i dont know how its recieved by matlabs i cant describe how i serially connect to MATLAB i use
val=fscanf(sObject);
To connect serial communication to matlab i use the following code.
In general i dont send character i send UINT8 data,specifically for our case
i send 0x61 ('a' value) and '\n' for LF terminator shown bellow.
how do i catch the HEX data
sObject=serial('COM4','BaudRate',115200,'TimeOut',10,'Terminator','LF')
sObject.BytesAvailableFcn={@callbackSerial};
fopen(sObject);

답변 (1개)

Steven Lord
Steven Lord 2020년 10월 29일
Please remove the semicolon from the end of this line, let your callback trigger a few times, and show us exactly what gets displayed in the Command Window.
val=fscanf(ser);
That information will likely help us determine how to "interpret" the data you're receiving from the serial port.
I suspect what you want is hex2dec not str2double, but the information about what exactly val is will support or refute that suspicion.
  댓글 수: 1
fima v
fima v 2020년 10월 30일
Hello steven, i have written again and added the data you asked in the link shown bellow
could you answer it?
https://www.mathworks.com/matlabcentral/answers/630864-serial-communication-shows-huge-batch-istead-of-steady-small-bursts?s_tid=srchtitle

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by