How to send an ASCII code via matlab : fwrite or fprintf ?

7 ビュー (過去 30 日間)
Stan sdsd
Stan sdsd 2013 年 1 月 18 日
How to send an ASCII code via matlab : fwrite or fprintf ? For example the code 'A30005". Do I need to add something like %s : fprintf(com1,'%s","A30005') Best regards Stanislas

採用された回答

Walter Roberson
Walter Roberson 2013 年 1 月 18 日
You an use either call. fprintf() like Thorsten shows, or
fwrite(com1, 'A30005')
If you need to send a terminator (CR or LF) then fprintf() is usually easier
fprintf(com1, '%s\n', 'A30005')
  4 件のコメント
Stan sdsd
Stan sdsd 2013 年 1 月 21 日
Okay, I have from my communication settings, a terminator in LF, so linefeed. And the terminator associated seems to be in wikipedia U+000A. So I have to use fprintf with %s\n and "my text", and after I have to send "U+000A" ? Best regards Stan
Walter Roberson
Walter Roberson 2013 年 1 月 21 日
If you use %s\n as your fprintf() format, then the U+000A will automatically be sent. The \n means to send the linefeed, which is U+000A

サインインしてコメントする。

その他の回答 (1 件)

Thorsten
Thorsten 2013 年 1 月 18 日
Just make sure to get the marks right:
fprintf(com1, '%s', 'A30005')
  1 件のコメント
Stan sdsd
Stan sdsd 2013 年 1 月 18 日
oh nice, I didn't notice my mistake

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by