how to read steaming data from a serial port?
4 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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 件のコメント
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 Exchange で Instrument Control Toolbox Supported Hardware についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!