Problem with searial port reading

Hello i am tryng to read from a serial port device.The divice is a parallax gps receiver. The output of the device is NMEA protocol.The output looks like this:
$GPGSV,3,3,11,18,07,324,25,07,03,091,,11,01,058,*45 $GPRMC,110725.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*6C $GPGGA,110726.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*5E $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110726.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*6F $GPGGA,110727.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*5F $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110727.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*6E $GPGGA,110728.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*50 $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110728.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*61 $GPGGA,110729.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*51 $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110729.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*60 $GPGGA,110730.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*59 $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPGSV,3,1,11,26,82,234,40,28,70,055,,15,41,306,21,08,38,074,*7E $GPGSV,3,2,11,17,33,137,44,27,29,289,22,05,17,215,38,09,11,282,16*7E $GPGSV,3,3,11,18,07,324,25,07,03,091,,11,01,058,*45 $GPRMC,110730.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*68 $GPGGA,110731.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*58 $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110731.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*69 $GPGGA,110732.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*5B $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110732.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*6A $GPGGA,110733.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*5A $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110733.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*6B $GPGGA,110734.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0,M,,0000*5D $GPGSA,A,3,17,26,18,05,15,09,,,,,,,2.1,1.4,1.6*30 $GPRMC,110734.000,A,4313.3418,N,02756.2409,E,0.00,248.59,070612,,,A*6C $GPGGA,110735.000,4313.3418,N,02756.2409,E,1,06,1.4,164.7,M,37.0
I want to read only the rows that contain %GPGSV in the beggining.So far i am using this code: serialObject = serial('COM6');
set(serialObject, 'BaudRate', 4800);
set(serialObject, 'Parity', 'none');
set(serialObject, 'ReadASyncMode', 'continuous');
set(serialObject, 'StopBits', 1);
set(serialObject, 'FlowControl', 'none');
fopen(serialObject);
data='';
while isempty(strmatch('$GPGSV',data))
data = fscanf(serialObject);
end
The problem is i receive only one row. Can you guys please help me receive a continuous string of data.
Also after acquiring only the %GPGSV rows i want to separate all the data between the commas.

4 Kommentare

Walter Roberson
Walter Roberson am 16 Jun. 2012
I suggest replacing the fscanf() line with
data = fgetl(serialObject);
but that is more a matter of taste (fscanf() is designed for formatted reads but you are using it to get the entire line.)
Mihail Kolev
Mihail Kolev am 17 Jun. 2012
Ok but how to get fgetl() to read all the line but not just one
Mihail Kolev
Mihail Kolev am 18 Jun. 2012
Guys pls help i really need to complete this project.
I still can't get a continuous string out of the serial port.I can read only one line.
Walter Roberson
Walter Roberson am 18 Jun. 2012
Without getting into complicating details: Yes, you can only expect to be able to read one line at a time.
What happens on the second fgetl() ?

Antworten (0)

Diese Frage ist geschlossen.

Tags

Gefragt:

am 16 Jun. 2012

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by