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); },
|
write: function(m,cb) { this.serial.write(m,cb); },
|
||||||
}
|
}
|
||||||
//newline = newline.replace("\\n","\n").replace("\\r","\r");
|
//newline = newline.replace("\\n","\n").replace("\\r","\r");
|
||||||
|
var olderr = "";
|
||||||
var setupSerial = function() {
|
var setupSerial = function() {
|
||||||
obj.serial = new serialp.SerialPort(port,{
|
obj.serial = new serialp.SerialPort(port,{
|
||||||
baudrate: baud,
|
baudrate: baud,
|
||||||
@ -223,7 +224,17 @@ module.exports = function(RED) {
|
|||||||
parity: parity,
|
parity: parity,
|
||||||
stopbits: stopbits,
|
stopbits: stopbits,
|
||||||
parser: serialp.parsers.raw
|
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) {
|
obj.serial.on('error', function(err) {
|
||||||
RED.log.error(RED._("serial.errors.error",{port:port,error:err.toString()}));
|
RED.log.error(RED._("serial.errors.error",{port:port,error:err.toString()}));
|
||||||
obj._emitter.emit('closed');
|
obj._emitter.emit('closed');
|
||||||
@ -241,6 +252,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
obj.serial.on('open',function() {
|
obj.serial.on('open',function() {
|
||||||
|
olderr = "";
|
||||||
RED.log.info(RED._("serial.onopen",{port:port,baud:baud,config: databits+""+parity.charAt(0).toUpperCase()+stopbits}));
|
RED.log.info(RED._("serial.onopen",{port:port,baud:baud,config: databits+""+parity.charAt(0).toUpperCase()+stopbits}));
|
||||||
if (obj.tout) { clearTimeout(obj.tout); }
|
if (obj.tout) { clearTimeout(obj.tout); }
|
||||||
//obj.serial.flush();
|
//obj.serial.flush();
|
||||||
|
@ -26,7 +26,7 @@ Usage
|
|||||||
|
|
||||||
Provides two nodes - one to receive messages, and one to send.
|
Provides two nodes - one to receive messages, and one to send.
|
||||||
|
|
||||||
###Input
|
### Input
|
||||||
|
|
||||||
Reads data from a local serial port.
|
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
|
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.
|
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.
|
Provides a connection to an outbound serial port.
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-serialport",
|
"name" : "node-red-node-serialport",
|
||||||
"version" : "0.0.3",
|
"version" : "0.0.4",
|
||||||
"description" : "Node-RED nodes to talk to an serial port",
|
"description" : "Node-RED nodes to talk to an serial port",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"serialport" : "1.7.*"
|
"serialport" : "1.7.*"
|
||||||
},
|
},
|
||||||
|
"engineStrict" : true,
|
||||||
|
"engines" : { "node" : "<=0.12" },
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"type":"git",
|
"type":"git",
|
||||||
"url":"https://github.com/node-red/node-red-nodes/tree/master/io/serialport"
|
"url":"https://github.com/node-red/node-red-nodes/tree/master/io/serialport"
|
||||||
|
Loading…
Reference in New Issue
Block a user