how to read steaming data from a serial port?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Orel Levy
le 18 Oct 2017
Commenté : Walter Roberson
le 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 commentaires
Réponse acceptée
Walter Roberson
le 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 commentaires
Walter Roberson
le 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 .
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Instrument Control Toolbox Supported Hardware dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!