-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtester.js
41 lines (35 loc) · 889 Bytes
/
tester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var serialport = require("serialport")
var m;
var Mirobot = function(port, cb){
var self = this;
self.cb = undefined;
self.msgs = [];
var init = function(port, cb){
self.s = new serialport.SerialPort(port, {
baudrate: 57600,
parser: serialport.parsers.readline('\n')
});
self.s.on('open', function () {
cb();
});
self.s.on('data', function (data) {
console.log(data);
self.msgs.push(data);
self.cb(self.msgs);
});
}
this.send = function(str, timeout, cb){
console.log(str);
self.msgs = [];
self.s.write(str + "\r\n", function(err, bytesWritten) {
self.cb = cb;
console.log(bytesWritten);
});
}
init(port, cb);
}
m = new Mirobot("/dev/tty.usbserial-FTE3AQ5M", function(){
m.send('{"cmd":"version","id":"foo"}', 100, function(success, data){
console.log(data);
});
})