how to read steaming data from a serial port?
4 views (last 30 days)
Show older comments
Orel Levy
on 18 Oct 2017
Commented: Walter Roberson
on 13 Nov 2018
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 Comments
Accepted Answer
Walter Roberson
on 18 Oct 2017
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 Comments
Walter Roberson
on 13 Nov 2018
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 .
More Answers (0)
See Also
Categories
Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!