Main Content

flush

Flush all GPS data accumulated in the buffers and reset properties

Description

example

flush(gps) clears the buffers and resets the values of SamplesRead and SamplesAvailable properties.

Examples

collapse all

Read data from the GPS receiver connected to the host computer using serialport object.

Required Hardware

To run this example, you need:

  • UBlox Neo-6M GPS module

  • GPS antenna

  • USB to UART module

  • USB cable

  • Connecting wires

Hardware Connection

Connect the pins on the UBlox Neo-6M GPS module to the pins on your USB to UART module. The connections are:

  • VCC - +5V

  • RX - TXO

  • TX - RXI

  • GND - GND

Connect the GPS antenna to the GPS module. Connect the USB to UART module to the host computer with a USB cable. GPS Fix can be easily acquired in locations that have a clear view of the sky. Wait for the GPS module to acquire satelite signals (Fix).This can be verified by checking the Fix LED (D1) of your GPS module.

Create GPS Object

Connect to the GPS receiver using serialport object. Specify the port name and the baud rate. Specify the output format of the data as matrix.

s = serialport('COM4',9600);
gps = gpsdev(s,'OutputFormat',"matrix")
gps = 
  gpsdev with properties:

                         SerialPort: COM4	
                           BaudRate: 9600 (bits/s)

                     SamplesPerRead: 1	 
                           ReadMode: "latest"	 
                        SamplesRead: 0	 
Show all properties all functions

Read the GPS data

Read the GPS data and return them as matrices.

[lla,speed,course,dops,gpsReceiverTime,timestamp,overruns] = read(gps)
lla = 1×3

   NaN   NaN   NaN

speed = NaN
course = NaN
dops = 1×3

   NaN   NaN   NaN

gpsReceiverTime = datetime
   NaT

timestamp = datetime
   22-Mar-2021 03:41:00.274

overruns = 1

Display number of samples read and the samples available in the host buffer.

gps.SamplesRead
ans = 1
gps.SamplesAvailable
ans = 0

Flush all GPS data accumulated in the buffers and reset the SamplesRead and SamplesAvailable properties.

flush(gps)

Display number of samples read and the samples available in the host buffer.

gps.SamplesRead
ans = 0
gps.SamplesAvailable
ans = 0

Clean Up

When the connection is no longer needed, clear the associated object.

delete(gps);
clear gps;
clear s;

Input Arguments

collapse all

The GPS sensor, specified as a gpsdev object.

See Also

Objects

Functions

Introduced in R2020b