forked from snaewe/node-nmea-1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added an example and small update to main file
- Loading branch information
Showing
2 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var serial = require('serialport') // voodootikigod / node-serialport : npm -g install serialport | ||
,nmea = require('nmea'); | ||
|
||
// don't print errors | ||
nmea.setErrorHandler(function(s) {}); | ||
|
||
// open the serial port at the required baud rate and use the line parser | ||
// note that NMEA output uses \r\n instead of just \n as a line delimiter | ||
var sp = new serial.SerialPort("/dev/ttyS0", | ||
{ | ||
baudrate:4800, | ||
parser: serial.parsers.readline("\r\n") | ||
}); | ||
|
||
// wait for data | ||
sp.on('data',function(line) { | ||
// parse the nmea sentence | ||
var s = nmea.parse(line); | ||
if (s != null) { | ||
// if it was parseable, print the raw line and the decoded object data | ||
console.log(line); | ||
console.log(s); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters