From fac756b226b6d3ef8fa045e42baaf18b021706bf Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Thu, 14 Jan 2016 21:43:45 +0100 Subject: [PATCH] some scope related bug fixes --- nodejs/ar-com/arduino.js | 19 ++++++++++--------- nodejs/routes/index.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/nodejs/ar-com/arduino.js b/nodejs/ar-com/arduino.js index f49e9f3..e818b0a 100644 --- a/nodejs/ar-com/arduino.js +++ b/nodejs/ar-com/arduino.js @@ -10,35 +10,36 @@ var Arduino = function (baudrate) { } Arduino.prototype.setup = function () { + var self = this; child.exec('cd ../arduino && ino build && ino upload', function(err, stdout, stderr){ - if(err){console.log('Please install the ino utility and connect arduino!\nIf there are other open programs that communicate with the arduino, close them!'); return this.success = false;} + if(err){console.log('Please install the ino utility and connect arduino!\nIf there are other open programs that communicate with the arduino, close them!'); return self.success = false;} var buff = stdout.slice(stdout.indexOf('Guessing serial port ... ')+25); buff = buff.slice(0, buff.indexOf('\n')); console.log('Guessing serial port ... ' + buff); - this.serial = new serial(buff, { - baudrate: this.baudrate, + self.serial = new serial(buff, { + baudrate: self.baudrate, parser: serial.parsers.readline('\n') }, false); - this.serial.open(function (error) { + self.serial.open(function (error) { if ( error ) { console.log('Please check arduino!') - return this.success = false; + return self.success = false; } serialPort.write(new Buffer('00000000')); }); - - this.success = true; - this.processWriteBuffer(); + + self.success = true; + self.processWriteBuffer(); }); } Arduino.prototype.write = function (m) { - if (this.success) { + if (this.serial) { this.serial.write(m); } else { this.writeBuffer.push(m); diff --git a/nodejs/routes/index.js b/nodejs/routes/index.js index 66f1b18..223c30c 100644 --- a/nodejs/routes/index.js +++ b/nodejs/routes/index.js @@ -3,7 +3,7 @@ var router = express.Router(); var Arduino = new require('../ar-com/arduino'); var arduino = new Arduino(); -arduino.setup() +arduino.setup(); /* GET home page. */ router.get('/', function(req, res, next) {