From: Muhammad Saeed Anwer on
i need some code about serial communication with Matlab but fwirte and fprintf not work why?
i want to transfer 'String' data to Microcontroller through Serial Port. i write Matlab code in following form:

s=serial('com1','baudrate',115200);
fopen(s)
fprinf(s,'typeAlpha/r') %'typeAlpha/r' data to transfer
fclose(s)

plz help...................
i need this within 2 days
From: Steven Lord on

"Muhammad Saeed Anwer" <mr_saeedanwer(a)hotmail.com> wrote in message
news:hhrtcv$pj1$1(a)fred.mathworks.com...
>i need some code about serial communication with Matlab but fwirte and
>fprintf not work why?

There is no "fwirte" function -- I assume you simply made a typo in this
posting, but I figured I'd call it out in case it was a typo in your code as
well.

> i want to transfer 'String' data to Microcontroller through Serial Port. i
> write Matlab code in following form:
>
> s=serial('com1','baudrate',115200);
> fopen(s)
> fprinf(s,'typeAlpha/r') %'typeAlpha/r' data to transfer

As above, you have a typo here. The function's name is "fprintf" not
"fprinf".

> fclose(s)
>
> plz help...................
> i need this within 2 days

If those typos are not the cause of this problem, you will need to explain
exactly what you mean when you say "fwirte and fprintf not work". Do they
throw a warning? Do they throw an error? Do they crash MATLAB? Do they
cause your computer to spontaneously combust? Post to the newsgroup (please
DON'T email me directly) showing a small piece of code that shows EXACTLY
what you've tried and state SPECIFICALLY what happens when you run that code
and you should receive some help.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Muhammad Saeed Anwer on
previous message have some typing mistakes, sorry for that

let i try to explain what exactly happen

i write below code in Matlab

%%%%%%%%%%%%%%%%%%%%%
s=serial('com1','baudrate',115200);
while 1
fopen(s)
y=fscanf(s)
if strcmp(y,'captureImage/r')==1
fprintf(s,'typeAlpha/r');
else
fprintf(s,'Nothing/r');
end
fclosed(s);
end
%%%%%%%%%%%%%%%%%%%%%

project is to take image when Microcontroller sends 'captureImage/r' string to PC(Matlab) continuously but in this code fscanf(s) run perfectly but fprintf(s,'typeAlpha/r') is not working. keep in mind that after 'captureImage/r' received then 'typeAlphe/r' sends to the Microcontroller. if i use only

s=serial('com1','baudrate',115200);
fopen(s);
fprintf(s,'typeAlpha/r');
fclosed(s);

then nothing occur on the screen and even not generating any error but my data 'typeAlpha/r' not send to the microcontroller.

note:
Microcontroller Baudrate =115200

in last i mention that all are right and project is working perfectly by HyperTerminal.


plz help i need this

there is also one problem that is:
when captureImage not received then message occur in following way:

warning: Timeout...............
y='' %blank