how to read steaming data from a serial port?

4 ビュー (過去 30 日間)
Orel Levy
Orel Levy 2017 年 10 月 18 日
コメント済み: Walter Roberson 2018 年 11 月 13 日
Hello, I'm trying to read data off an IMU device connected through a serial port to matlab. I know that each line of new data starts with the header 'AA 55', and has 38 bytes including the header. I am trying to read the data within a loop, but the data's size changes each loop. How can I make sure i get just the 38 bytes each time starting with the known header?
Thanks.

採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 18 日
Once you are positioned just before the AA, then fread(s, 38, 'uint8')
You will have wanted to set the port BytesAvailableFcnMode to 'bytes'
  3 件のコメント
muhammad faiz
muhammad faiz 2018 年 11 月 13 日
how do you position to get the header (AA in your case)?
Walter Roberson
Walter Roberson 2018 年 11 月 13 日
the easiest approach involves wasting an input line . fread one byte at a time until you find AA hex . fread another byte and verify it is 55 hex. if not go back to the AA check . once you have seen AA55 then fread 36 more byte . You can now switch into reading groups of 38 bytes .
This is the easiest way . Slightly more difficult to code would be to make use of those 36 bytes instead of throwing them away .
You might need to send something to provoke the mcu to start sending data .

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox Supported Hardware についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by