Reading serial data (NMEA) into simulink

7 ビュー (過去 30 日間)
Jan De Vries
Jan De Vries 2011 年 10 月 2 日
I have a NMEA compass connected to my PC through COM1 (4800 baud, 8 data bits, 1 stop bit, no parity).
It sends heading data into the following format:
where hhh.h is the direction the compass is heading in degrees with 1 decimal.
I am able to read the output of the compass using the "Query instrument". I tried saving the output of this block into a matlab file to check what happens, and it yields me a series of ascii codes corresponding to the format above (eg. 36 72 67 72 etc. which corresponds to $HCH). It's reading out the output as long as mu simulation runs, so I get a long string with multiple sentences in the format described above.
However, I am only interested in the heading hhh.h, and do not want all the other characters. I want to have a signal in my simulink model which is equal to the (realtime) heading to control my direction.
How can I filter out the heading from the Query Instrument output?

回答 (2 件)

Shankar Subramanian
Shankar Subramanian 2011 年 10 月 13 日
Hi Jan,
Do you receive a response from the compass after you send a query command to it? Or do you continuously get data from the compass? If it is streaming, have you tried to use Serial Configuration and Serial Receive blocks? The Serial receive block has the option of specifying header and terminator on the mask to separate out the required data alone.
  2 件のコメント
Jan De Vries
Jan De Vries 2011 年 10 月 13 日
Just took a quick look at the serial receive block, might be what I'm looking for.
Now I need to find a way to extract the heading info from the NMEA sentence, that is, to get hhh.h from the sentece


Marc 2013 年 5 月 7 日
I am trying to use "serial receive block" to recieve data from the gyros conected to my arduino. I send this with Serial.write() which sends bytes. My problem is: when I try to select my port (COM3) in the "serial receive block" no port apperas, just the sentence "please select a port..".
Is there any configuration that I might be missing? How can I select the port?
Thank you


Find more on Event Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by