How to extract only '$GPGGA' string real-time from Garmin gps device on matlab ?

4 visualizaciones (últimos 30 días)
Hello, I am trying to extract GPS signals real-time from a Garmin 18x device by using serial communication. But every time I run the program using a 'while' loop, there are other strings namely '$GPVTG' and '$PGRME' also being read. I just need '$GPGGA' string for my use case which I'm not able to extract.
I did try using 'textscan' and 'strtok' but nothing worked as there are 3 different string types and lengths. The command window showing the string data being read is as shown in the image.
The code I used is below:
% Extraction of data from GPS
garmin_gps = serial('COM4','Baudrate', 19200); %Create serial port object 'garmin_gps' to connect Garmin device
set(garmin_gps, 'InputBufferSize', 512000);
set(garmin_gps, 'terminator', '*')
fopen(garmin_gps);
Z = isempty('InputBufferSize')
while Z == 0
D = fscanf(garmin_gps, '%s')
end

Respuestas (1)

Mark McBroom
Mark McBroom el 15 de Mzo. de 2018
Have you tried regexp?
  1 comentario
Prajwal Ramakrishna
Prajwal Ramakrishna el 16 de Mzo. de 2018
Yes, But then it returns just the index values of the expression I require. In my case, I only need the '$GPGGA' string omitting the other two when the 'while' loop iterates every time. Please help me with this.

Iniciar sesión para comentar.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by