some scope related bug fixes
This commit is contained in:
parent
54850cde26
commit
fac756b226
2 changed files with 11 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Reference in a new issue