Sending four byte commands To serial port

17 ビュー (過去 30 日間)
Jason
Jason 2021 年 10 月 15 日
コメント済み: Jason 2021 年 10 月 15 日
Whilst I am familiar using the Serialport objects in Matlab with text, Im not sure to how to use the protocol "four byte commands". I've spend a bit of time searching but didn't find any examples applicable to the "new" serialport object in the latest versions of Matlab.
In particular, what syntax would I use to send the command (in bold):
Command: 8112 0000
And then read the response (in bold) and extract the numerical value of yy
Response: 5512 00yy
Thanks for any pointers
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 15 日
are those hex values or decimal?
Jason
Jason 2021 年 10 月 15 日
Thats the issue, I dont know

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 15 日
cmd = [0x81 0x12 0x00 0x00];
write(YourPortObject, cmd, 'uint8');
response = read(YourSerialPortObject, 4, 'uint8');
if isequal(response, [0x55 0x12 0x00])
yy = response(4);
else
fprintf('unexpected response, got: %s\n', mat2str(yy));
end
  1 件のコメント
Jason
Jason 2021 年 10 月 15 日
Thamkyou Walter

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSerial and USB Communication についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by