title: Unable to parse GPS information via serial port
body: <p>I have used the following packages to:</p>
  <ol>
  <li>read from the serial port (<code>go get go.bug.st/serial</code>)</li>
  <li>parse the incoming message from the serial port (<code>go get adrianmo/go-nmea</code>)</li>
  </ol>
  <p><strong>Host machine</strong>: <strong>Windows 10</strong></p>
  <p><em>Go Version</em>: <strong>go version go1.14.4 windows/amd64</strong></p>
  <p>Based on the documentation I wrote a simple code that opens the dedicated serial port (<code>COM4</code>) and reads the  NMEA data from the port and tries to parse the data according to the <code>go-nmea</code> package</p>
  <h2>Data</h2>
  <p>Incoming Data from GPS sensor:</p>
  <pre><code>$GPRMC,135533.000,A,5306.6644,N,00851.3177,E,0.11,214.59,300620,,,A*6E
  
  $GPRMC,135534.000,A,5306.6643,N,00851.3177,E,0.06,187.72,300620,,,A*68
  
  $GPRMC,135535.000,A,5306.6643,N,00851.3177,E,0.22,341.68,300620,,,A*6C
  
  $GPRMC,135536.000,A,5306.6644,N,00851.3176,E,0.20,324.35,300620,,,A*60
  
  $GPRMC,135537.000,A,5306.6645,N,00851.3176,E,0.12,348.37,300620,,,A*69
  </code></pre>
  <h2>Code Snippet</h2>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;log&quot;
  
      &quot;github.com/adrianmo/go-nmea&quot;
      &quot;go.bug.st/serial&quot;
  )
  
  func main() {
  
      mode := &amp;serial.Mode{
          BaudRate: 9600,
          Parity:   serial.NoParity,
          DataBits: 8,
          StopBits: serial.OneStopBit,
      }
      serPort, err := serial.Open(&quot;COM4&quot;, mode)
      if err != nil {
          log.Fatal(err)
      }
  
      defer serPort.Close()
  
      buff := make([]byte, 1024)
  
      for {
          n, err := serPort.Read(buff)
          if err != nil {
              log.Fatal(err)
              break
          }
          if n == 0 {
              fmt.Println(&quot;\nEOF&quot;)
              break
          }
          rawSentence := string(buff[:n])
          fmt.Print(rawSentence)
          s, err := nmea.Parse(rawSentence)
          if err != nil {
              log.Fatal(err)
          }
          if s.DataType() == nmea.TypeRMC {
              m := s.(nmea.RMC)
              fmt.Printf(&quot;Raw sentence: %v\n&quot;, m)
              fmt.Printf(&quot;Time: %s\n&quot;, m.Time)
              fmt.Printf(&quot;Validity: %s\n&quot;, m.Validity)
              fmt.Printf(&quot;Latitude GPS: %s\n&quot;, nmea.FormatGPS(m.Latitude))
              fmt.Printf(&quot;Latitude DMS: %s\n&quot;, nmea.FormatDMS(m.Latitude))
              fmt.Printf(&quot;Longitude GPS: %s\n&quot;, nmea.FormatGPS(m.Longitude))
              fmt.Printf(&quot;Longitude DMS: %s\n&quot;, nmea.FormatDMS(m.Longitude))
              fmt.Printf(&quot;Speed: %f\n&quot;, m.Speed)
              fmt.Printf(&quot;Course: %f\n&quot;, m.Course)
              fmt.Printf(&quot;Date: %s\n&quot;, m.Date)
              fmt.Printf(&quot;Variation: %f\n&quot;, m.Variation)
          }
      }
  }
  
  </code></pre>
  <h2>Problem</h2>
  <p>If I run the code I get the following error:</p>
  <pre class="lang-sh prettyprint-override"><code>2020/06/30 16:02:16 nmea: sentence does not start with a '$' or '!'
  exit status 1
  </code></pre>
  <p>which is strange because if I comment out the code parsing code:</p>
  <pre class="lang-golang prettyprint-override"><code>        // s, err := nmea.Parse(rawSentence)
          // if err != nil {
          //  log.Fatal(err)
          // }
          // if s.DataType() == nmea.TypeRMC {
          //  m := s.(nmea.RMC)
          //  fmt.Printf(&quot;Raw sentence: %v\n&quot;, m)
          //  fmt.Printf(&quot;Time: %s\n&quot;, m.Time)
          //  fmt.Printf(&quot;Validity: %s\n&quot;, m.Validity)
          //  fmt.Printf(&quot;Latitude GPS: %s\n&quot;, nmea.FormatGPS(m.Latitude))
          //  fmt.Printf(&quot;Latitude DMS: %s\n&quot;, nmea.FormatDMS(m.Latitude))
          //  fmt.Printf(&quot;Longitude GPS: %s\n&quot;, nmea.FormatGPS(m.Longitude))
          //  fmt.Printf(&quot;Longitude DMS: %s\n&quot;, nmea.FormatDMS(m.Longitude))
          //  fmt.Printf(&quot;Speed: %f\n&quot;, m.Speed)
          //  fmt.Printf(&quot;Course: %f\n&quot;, m.Course)
          //  fmt.Printf(&quot;Date: %s\n&quot;, m.Date)
          //  fmt.Printf(&quot;Variation: %f\n&quot;, m.Variation)
          // }
  </code></pre>
  <p>The serial port prints the GPS co-ordinates as mentioned above.</p>
  <p>Where am I going wrong here? I tried removing the <em>new-line</em> and <em>carriage-return</em> by doing the following in the code:</p>
  <pre class="lang-golang prettyprint-override"><code>        rawSentence := string(buff[:n])
          rawSentence = string.ReplaceAll(rawSentence, &quot;\r\n&quot;, &quot;&quot;)
          fmt.Print(rawSentence)
  </code></pre>
  <p>But I still get the same error.</p>