필터 지우기
필터 지우기

RS232 with MATLAB: Doesn't send what I want

조회 수: 1 (최근 30일)
Julia
Julia 2014년 10월 30일
댓글: Julia 2014년 10월 30일
Hello everyone! I am using Matlab to communicate with a device on a RS232 connexion. My code is quite simple: I first open the correct COM port: obj=serial('COM3','BaudRate',9600); fopen(obj);
And send I send various ASCII commands. For example: fprintf(obj,'%s\n',[char(hex2dec('A1'))])
I have a sniffer on the RS232 port, so I can make sure I am sending the right command. in this case 'A1'.
However, sometimes when I try to send '8B' it sends '3F' instead (shown by the sniffer): fprintf(obj,'%s\n',[char(hex2dec('8B'))])
This is bizarre, because sometimes it works perfectly fine and for some ASCII characters, it doesn't work!
Do you know why this happens? And what can I do to avoid this? Are there other alternatives to communicate on RS232 serial port with MATLAB?
Thank you in advance for your response and your time!
  댓글 수: 1
Julia
Julia 2014년 10월 30일
ok so I understood something. When the characters I send are larger than 127 (so when the 8th bit is a 1: ex. 10000000 and larger), Matlab doesn't send the right number. This is why everything worked well for most of the characters, but as soon as I send a value larger than 127 (80 in hex) it didn't work properly.
Does someone know how I can avoid this? I guess Matlab considers the 8th bit as a sign or something...
Thank you!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by