I need to connection between a microprocessor with a serial port (RS232) in Matlab.
My problem is the function sscanf isn't working.
Why? How do I correct the error?
I have this code in Matlab, connect.m:
================
...
s1 = serial('COM1');
set (s1, 'timeout', 60);
set (s1,''terminator',0);
set(s1,'inputbuffersize',1024);
fopen(s1);
fprintf('Serial port online');
% I have a ciclo the calculate the inputs data of the microprocessor
for i=3:N1-2
finputs = []; % for the first time the inputs are [0,0,0,0]
finputs = [y(i-1);y(i-2);u(i-1);u(i-2)];
ynew = cal(bla); % here ynew is a floating point
ynew2 = num2str (ynew); % here I convert floating point to string, because in the microprocessor only receive string
y(i)= ynew;
fprintf(s1,ynew2); %here I send the string to microprocessor
% I must receive the data of the microprocessor. The microprocessor sends to Matlab a string
unew2 = fscanf(s1); % it isn't working
unew = sscanf(unew2,'%f'); %here I convert the string to floating point
u(i)= unew;
end
fclose (s1)
plot (u);
plot(y);
delete(s1)
clear s1
================
Anybody help me?
Thanks