mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Let serialport node only report errors once
instead of repeating
This commit is contained in:
parent
e1b02c90dd
commit
fe2ae9c0a3
@ -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();
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user