Hardware Reference
In-Depth Information
// Need to add exports.serialParsers = m.module.parsers;
// to the end of /usr/local/lib/node_modules/bonescript/serial.js
var b = require ( 'bonescript' );
var nmea = require ( 'nmea' );
var port = '/dev/ttyO4' ;
var options = {
baudrate : 9600 ,
parser : b . serialParsers . readline ( "\n" )
};
b . serialOpen ( port , options , onSerial );
function onSerial ( x ) {
if ( x . err ) {
console . log ( '***ERROR*** ' + JSON . stringify ( x ));
}
if ( x . event == 'open' ) {
console . log ( '***OPENED***' );
}
if ( x . event == 'data' ) {
console . log ( String ( x . data ));
console . log ( nmea . parse ( x . data ));
}
}
If you don't need the NMEA formatting, you can skip the npm part and remove the lines
in the code that refer to it.
NOTE
If you get an error like this
TypeError: Cannot call method readline of undefined
add this line to the end of file /usr/local/lib/node_modules/bonescript/serial.js :
exports.serialParsers = m.module.parsers;
Search WWH ::




Custom Search