I have an On-Board Diagnostics (OBDII) tool that I am trying to read the values from. This tool helps me trouble codes on a car's ECU. I can use hyperterminal to read the values through the USB. When I open the terminal with COM1, baud rate of 9600 and type in 03, it returns me some value.
How do I do the same in MATLAB? Is this it or do I need to do more?
s = serial('COM1'); fopen(s) fprintf(s,'03') out = fscanf(s)
Please suggest.

 채택된 답변

Krishna Gummadi
Krishna Gummadi 2011년 8월 2일

0 개 추천

I had to add this before fscanf to work:
fprintf(s,'%s','13'); %CR

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 8월 2일
'13' would not send a CR, but 13 not in quotes would. That would be the same, though, as coding \r in the format like I suggested.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 7월 31일

0 개 추천

What terminator does the remote system need? fprintf(s,'03') is defined as fprintf(s,'%s\n','03') which sends 03 followed by whatever terminator is configured for the port. If that terminator does not match what the remote system is expecting, you could have difficulty.
Krishna Gummadi
Krishna Gummadi 2011년 7월 31일

0 개 추천

The document indicates this:
"All messages to the OBD Prompt must be terminated with a carriage return character (hex ‘0D’) before it will be acted upon. If a command has been started but not terminated by a ‘0D’ it will be aborted after 20 seconds of inactivity"
So, should I say fprintf(s,'030D') instead?

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 7월 31일
You could set the terminator to carriage return, or you could use
fprintf(s,'%s\r', '03')

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

카테고리

도움말 센터File Exchange에서 MATLAB Support Packages에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by