Serial Communication terminator query

조회 수: 5 (최근 30일)
Aditya Suryavanshi
Aditya Suryavanshi 2012년 12월 19일
hello, i am trying to obtain data string from a serial comm port. i should be getting the string and LF/CR to the end.
i have tried to configure the port accordingly as :
handles.s= serial('COM1','BaudRate',9600,'DataBits',8,'Parity','none','StopBits',1, 'BytesAvailableFcnMode','Terminator','BytesAvailableFcn', {@Data_Fcn_Callback},'Terminator','LF/CR');
where @Data_Fcn_Callback is the function i want to be executed on receiving Lf/CR.
But the BytesAvailableFcnMode info from help states : 'You can configure BytesAvailableFcnMode only when the object is disconnected from the device.You disconnect an object with the fclose function. A disconnected object has a Status property value of closed.' I am unable to understand how to obtain data in such case.
Am i right in my procedure ? other ways/suggestions to do the same task will be appreciated .
Thank you.

답변 (1개)

Jan
Jan 2012년 12월 19일
You forgot to explain, if your program works as expected.
The help text means, that you cannot change the 'BytesAvailableFcnMode' property after the serial object has been opened. Your code does define this peroperty before calling fopen. Therefore everything should be ok.
  댓글 수: 1
Aditya Suryavanshi
Aditya Suryavanshi 2013년 3월 12일
편집: Aditya Suryavanshi 2013년 3월 12일
I forgot to mention that I have tested the program and it works according to expectations.
i encountered a situation though- for the incoming string , if null character was received , i was not able to receive the remaining string. So the terminator would never be reached in that case and i had received error stating Terminator cannot be reached.
I could not make changes for this in program , so had to do it at the transmitting end.
Can anyone please explain it ? Thanks in advance.

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by