HOW to send serial data to matlab to pic controller? and how to differentiate multiple data which is transmitted by matlab?

조회 수: 2 (최근 30일)
matlab code
st=12 %person in
sto=10 %person out
total=st-sto;
s=serial('com15');
set(s,'BaudRate',9600,'DataBits',8,'Parity','none','StopBits',1,'FlowControl','none','InputBufferSize',102400) % serial port properties
fopen(s);
fwrite(s,st);% serial data transmission
fwrite(s,sto);%serial data transmission
fwrite(s,total);serial data transmission
stopasync(s);
fclose(interfaceObj);
delete(interfaceObj);
clear(interfaceObj);

답변 (1개)

Walter Roberson
Walter Roberson 2014년 2월 24일
You need to know what data form the other side expects. I think it more likely that you want to use
fwrite(s, uint8(st));
fwrite(s, uint8(sto);
fwrite(s, uint8(total));
but it is also possible you want something like,
fprintf(s, '%d', st);
fprintf(s, ' %d', sto);
fprintf(s, ' %d', total);
  댓글 수: 2
rinku some
rinku some 2014년 2월 24일
HEY thanks for reply now i transmitted this data by mat lab and receive it by pic and display this on lcd so how i know that this particular bit is for st or sto .
Walter Roberson
Walter Roberson 2014년 2월 24일
You create a "protocol", which is a formal sequence of the order of operations and the representation of those, and the appropriate response.
For example your protocol could say "The first 8 bits are an unsigned 8 bit integer representing the number of people in; the next 8 bits are an unsigned 8 bit integer representing the number of people out; this sequence is to continue indefinitely. The end of the stream of data is signaled by the people in and people out both being 255."
If both ends are "free running" then your protocol may have to be more complex in order to achieve synchronization.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Instrument Control Toolbox에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by