Serial I/O not getting input

조회 수: 1 (최근 30일)
Gabriel Ryan
Gabriel Ryan 2011년 7월 27일
Hi,
I am attempting to communicate with an XBee radio through Matlab serial, and while I am able to send data successfully, I am having trouble getting anything from the input.
For example, I can send a message with the following code to a terminal program connected to a matched XBee radio:
s = serial('COM8');
fopen(s);
fwrite(s,'TestMsg');
However, if I send a message from the same terminal that received the Matlab message, I cannot detect the message in Matlab using fscanf(s), or setting up a bytesavailable event with:
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcnCount = 1;
s.BytesAvailableFcn = @instrcallback;
I know the message is going through the radios because if I connect to the same serial port with a another terminal program (PUTTY or X-CTU) it shows up, so it seems like the problem must be with Matlab.
Thanks for any help!

채택된 답변

Gabriel Ryan
Gabriel Ryan 2011년 7월 28일
Actually I just figured out what was wrong. The XBee default configuration uses RTS flow control, so the XBee was not sending the data because Matlab wasn't asserting RTS. X-CTU on the other hand has an option to assert RTS that is on by default and I can only assume PUTTY also asserts RTS.
I hope this helps anyone else who runs into similar problems.
  댓글 수: 1
Gabriel Ryan
Gabriel Ryan 2011년 7월 28일
(I fixed the problem by configuring the XBee radio not to use RTS, but you could also just tell matlab to assert the RTS pin)

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

추가 답변 (1개)

Adi Mico
Adi Mico 2011년 7월 28일
  댓글 수: 1
Gabriel Ryan
Gabriel Ryan 2011년 7월 28일
Adi, thank you for your response.
I just tried setting the terminator to 13, which is what both PUTTY and X-CT interpret for <return>, and also 10 (which I think is default anyway), but still did not see anything when I tried to use fscanf or set up a bytesavailabe terminator triggered event.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by