diff --git a/examples/reset.js b/examples/reset.js index 96a70be..535837c 100644 --- a/examples/reset.js +++ b/examples/reset.js @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////// // Use the cool library // // git://github.com/voodootikigod/node-serialport.git // -// to reset an arduino . // +// to reset an arduino. // //////////////////////////////////////////////////////// var com = require("serialport"); @@ -12,6 +12,8 @@ var serialPort = new com.SerialPort("/dev/tty.usbmodem1411", { serialPort.on('open',function() { console.log('Port open'); + // note you get a dtr for free on port open so lets wait 5 seconds + // to make sure ours is seperate from that one setTimeout(asserting, 5000); }); @@ -19,23 +21,23 @@ serialPort.on('data', function(data) { console.log(data); }); - function asserting() { console.log('asserting'); - serialPort.set({rts:true, dtr:true}, function(err, something) { - console.log('asserted'); - setTimeout(clear, 250); - }); + //NOTE: you actually de-assert rts and dtr to toggle! + serialPort.set({rts:false, dtr:false}, function(err, something) { + console.log('asserted'); + setTimeout(clear, 5000); + }); } function clear() { - console.log('clearing'); - serialPort.set({rts:false, dtr:false}, function(err, something) { - console.log('clear'); - setTimeout(done, 50); - }); + console.log('clearing'); + serialPort.set({rts:true, dtr:true}, function(err, something) { + console.log('clear'); + setTimeout(done, 5000); + }); } function done() { - console.log("done resetting"); + console.log("done resetting"); } diff --git a/serialport.js b/serialport.js index 17202af..44b0cd2 100644 --- a/serialport.js +++ b/serialport.js @@ -60,9 +60,9 @@ function SerialPortFactory() { xon: false, xoff: false, xany: false, - rts: false, + rts: true, cts: false, - dtr: false, + dtr: true, dts: false, databits: 8, stopbits: 1, @@ -593,10 +593,18 @@ function SerialPortFactory() { options = (typeof option !== 'function') && options || {}; // flush defaults, then update with provided details - options.rts = options.rts || options.rts || _options.rts; - options.cts = options.cts || options.cts || _options.cts; - options.dtr = options.dtr || options.dtr || _options.dtr; - options.dts = options.dts || options.dts || _options.dts; + if(!options.hasOwnProperty('rts')){ + options.rts = _options.rts; + } + if(!options.hasOwnProperty('dtr')){ + options.dtr = _options.dtr; + } + if(!options.hasOwnProperty('cts')){ + options.cts = _options.cts; + } + if(!options.hasOwnProperty('dts')){ + options.dts = _options.dts; + } if (!fd) { var err = new Error('Serialport not open.');