Let serialport node only report errors once

instead of repeating
This commit is contained in:
Dave Conway-Jones 2015-11-02 10:40:53 +00:00
parent e1b02c90dd
commit fe2ae9c0a3
4 changed files with 19 additions and 5 deletions

View File

@ -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();

View File

@ -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.

View File

@ -48,4 +48,4 @@
"closed": "serial port __port__ closed"
}
}
}
}

View File

@ -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"