send command to serial port with ASCII code

6 ビュー (過去 30 日間)
Ella
Ella 2019 年 3 月 20 日
コメント済み: Geoff Hayes 2019 年 3 月 20 日
I need to send command from PC to device, the ASCII code is:
SOH C L M STX S D ETB EOT CR
The corresponding hexadecimal numbers are:
01H 43H 4CH 4DH 02H 52H 44H 17H 04H 0DH
The sample code given in the manual was written in BASICS (I assume the sample code sends to port 1):
SD$=CHR$(1)+"CLM"+CHR$(2)+"SD"+CHR$(23)+CHR$(4)
PRINT #1, SD$
The following is the code I wrote in MATLAB, but it didn't work:
fprintf(device,'%cCLM%cSD%c%c',[1,2,23,4])
Can someone please help with this? Thank you!
  1 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 3 月 20 日
Ella - should you be using strings instead?
fprintf(device,'%sCLM%sSD%s%s','1','2','23','4')

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

回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by