필터 지우기
필터 지우기

Serial communication with a header and a terminator

조회 수: 20 (최근 30일)
Marzieh Karami
Marzieh Karami 2019년 6월 10일
답변: Gayatri Menon 2022년 1월 4일
I want to send two uint16 numbers through the serial communication. The DSP wants the header and terminator to be equal to 'S' and 'E'. The command serial does not have an option for 'header' but it has an option for defining 'terminator'.
obj=serial(USBport);
obj.BaudRate=9600;
obj.Terminator='E';
obj.ByteOrder='LittleEndian';
To use the header I am writing
fwrite(obj,'S','char')
Now in order to send the two numbers I am using:
x = int16(1);
fwrite(obj,[x x],'int16')
I know that in each fwrite command an 'E' will be sent as well. How can I avoid this? Can I just send E at the end of the commands with another fwrite?
I am using this block to configure the DSP for receiving data.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 6월 10일
"I know that in each fwrite command an 'E' will be sent as well."
That should not happen. fprintf() can send terminators when you are not expecting them, but fwrite should not send the terminator unless you happen to send one as data.
However, you would want to check to see whether it sends each fwrite() as a separate packet, which could be a problem for USB over serial.
Marzieh Karami
Marzieh Karami 2019년 6월 17일
You are right! fwrite does not automatically send terminator.

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

답변 (1개)

Gayatri Menon
Gayatri Menon 2022년 1월 4일
Hi,
Protocol Decoder block and Protocol Encoder block might be useful in such scenarios.
For more info, refer the following links
Hope this helps
Thank you
Regards
Gayatri

카테고리

Help CenterFile Exchange에서 Get Started with DSP System Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by