File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ // From: https://github.com/jamesp/node-nmea
3
+
4
+ // Need to add exports.serialParsers = m.module.parsers;
5
+ // to /usr/local/lib/node_modules/bonescript/serial.js
6
+
7
+ var b = require ( 'bonescript' ) ;
8
+
9
+ var port = '/dev/ttyO1' ;
10
+ var options = {
11
+ baudrate : 9600 ,
12
+ parser : b . serialParsers . readline ( "\n" )
13
+ } ;
14
+
15
+ b . serialOpen ( port , options , onSerial ) ;
16
+
17
+
18
+ function onSerial ( x ) {
19
+ console . log ( x . event ) ;
20
+ if ( x . err ) {
21
+ console . log ( '***ERROR*** ' + JSON . stringify ( x ) ) ;
22
+ }
23
+ if ( x . event == 'open' ) {
24
+ console . log ( '***OPENED***' ) ;
25
+ setInterval ( sendCommand , 1000 ) ;
26
+ }
27
+ if ( x . event == 'data' ) {
28
+ console . log ( String ( x . data ) ) ;
29
+ }
30
+ }
31
+
32
+ var command = [ 'r' , 'R' , 'g' , 'G' ] ;
33
+ var commIdx = 1 ;
34
+
35
+ function sendCommand ( ) {
36
+ // console.log('Command: ' + command[commIdx]);
37
+ b . serialWrite ( port , command [ commIdx ++ ] ) ;
38
+ if ( commIdx >= command . length ) {
39
+ commIdx = 0 ;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments