フィルターのクリア

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 Center および File ExchangeLanguage Fundamentals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by