diff --git a/io/serialport/25-serial.js b/io/serialport/25-serial.js index b5468c00..efa296db 100644 --- a/io/serialport/25-serial.js +++ b/io/serialport/25-serial.js @@ -216,6 +216,7 @@ module.exports = function(RED) { write: function(m,cb) { this.serial.write(m,cb); }, } //newline = newline.replace("\\n","\n").replace("\\r","\r"); + var olderr = ""; var setupSerial = function() { obj.serial = new serialp.SerialPort(port,{ baudrate: baud, @@ -223,7 +224,17 @@ module.exports = function(RED) { parity: parity, stopbits: stopbits, parser: serialp.parsers.raw - },true, function(err, results) { if (err) { obj.serial.emit('error',err); } }); + },true, function(err, results) { + if (err) { + if (err.toString() !== olderr) { + olderr = err.toString(); + RED.log.error(RED._("serial.errors.error",{port:port,error:olderr})); + } + } + obj.tout = setTimeout(function() { + setupSerial(); + }, settings.serialReconnectTime); + }); obj.serial.on('error', function(err) { RED.log.error(RED._("serial.errors.error",{port:port,error:err.toString()})); obj._emitter.emit('closed'); @@ -241,6 +252,7 @@ module.exports = function(RED) { } }); obj.serial.on('open',function() { + olderr = ""; RED.log.info(RED._("serial.onopen",{port:port,baud:baud,config: databits+""+parity.charAt(0).toUpperCase()+stopbits})); if (obj.tout) { clearTimeout(obj.tout); } //obj.serial.flush(); diff --git a/io/serialport/README.md b/io/serialport/README.md index 25e1d7dc..4a321554 100644 --- a/io/serialport/README.md +++ b/io/serialport/README.md @@ -26,7 +26,7 @@ Usage Provides two nodes - one to receive messages, and one to send. -###Input +### Input Reads data from a local serial port. @@ -44,7 +44,7 @@ It then outputs **msg.payload** as either a UTF8 ascii string or a binary Buffer If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters is sent - again either as ascii chars or size 1 binary buffers. -###Output +### Output Provides a connection to an outbound serial port. diff --git a/io/serialport/locales/en-US/25-serial.json b/io/serialport/locales/en-US/25-serial.json index 4e39027a..c2e3ebbe 100644 --- a/io/serialport/locales/en-US/25-serial.json +++ b/io/serialport/locales/en-US/25-serial.json @@ -48,4 +48,4 @@ "closed": "serial port __port__ closed" } } -} \ No newline at end of file +} diff --git a/io/serialport/package.json b/io/serialport/package.json index f96da70d..5b35ecf5 100644 --- a/io/serialport/package.json +++ b/io/serialport/package.json @@ -1,10 +1,12 @@ { "name" : "node-red-node-serialport", - "version" : "0.0.3", + "version" : "0.0.4", "description" : "Node-RED nodes to talk to an serial port", "dependencies" : { "serialport" : "1.7.*" }, + "engineStrict" : true, + "engines" : { "node" : "<=0.12" }, "repository" : { "type":"git", "url":"https://github.com/node-red/node-red-nodes/tree/master/io/serialport"