MATLAB: Serial – only reads one string.

complotrealtimeserialuc

Hi
I have a microcontroller with a sensor. The uC sends out a string every tenth of a second to the COM-port. The string is filled with data XXX (Where XXX is 000-999)
Looks like this:
char output_verbose[] = {"XXX\r\n"};
The matlab-code is like this:
s1=serial('COM7','Baudrate',9600);
fopen(s1);
value=0;
str='';
sen=0;
j=1;
while(j<1000)
str=fscanf(s1);
sen=str2num(str);
accX(j)=sen;
plot(j,value);
drawnow;
j=j+1;
end;
fclose(s1);
delete(s1);
clear s1;
The probem after i have debugged a bit, is that when i want to read value number 2, the string is empty. It wont get the string from the COM-port again. And the uC sends the values 10 times a second, this is checked via PuTTY. I also have a LED that blinks everytime it sends.
Please help me

Best Answer

You have not configured the line terminator for the serial object.
Also your code
while(while(j<1000)
is invalid syntax.