Serial Communication - Trying to make Matlab Wait in a Loop

조회 수: 4 (최근 30일)
Kishan
Kishan 2011년 3월 9일
Hello,
Basically i'm trying to make Matlab wait untill it receives a byte of data as a Trigger to run the other set of codes.
Now I'm able to receive data in Matlab from Micro-Controller but I wanted to form a loop as in if there is no data received I want matlab to continue waiting for data.
Present code:-
clear all; obj = serial('COM1','baudrate',600); set(obj,'Parity','none'); obj.StopBits=1; obj.DataBits=8; obj.ByteOrder=['bigEndian']; obj.ReadAsyncMode = 'continuous';
fopen(obj)
datain = fread(obj,1,'uchar');
fclose(obj);
delete(obj);
clear obj;
With the above code I'm able to receive but the DATA i receive in Matlab will not be the same if i 'RUN' the this code several times. But it identifies if there is transmission from the controller.
Hence since the data keeps changing I cannot include coding which compares 'DATA' received to the one required.
I'll be glad to give any further details if required. Pls help me solve this issue.
Thanks
Kishan

답변 (2개)

Walter Roberson
Walter Roberson 2011년 3월 9일
Does obj.BytesAvailable apply in continuous mode?

Kishan
Kishan 2011년 3월 9일
Hello sir,
I checked out in the Matlab help. It says we can use BytesAvailable while asynchronously receiving the data, which i'm presently doing in my project. I think it can be used in continuous mode.
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 3월 9일
Yes, I just re-checked the meaning of 'continuous' and BytesAvailable should apply. You might also wish to consider establishing a BytesAvailableFcn callback.

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

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for USB Webcams에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by