1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Ensure serial node has a default reconnect time (#733)

This commit is contained in:
Nathanaël Lécaudé 2021-01-13 05:13:46 -05:00 committed by GitHub
parent edc640be4d
commit 55de84772c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ module.exports = function(RED) {
var events = require("events"); var events = require("events");
var serialp = require("serialport"); var serialp = require("serialport");
var bufMaxSize = 32768; // Max serial buffer size, for inputs... var bufMaxSize = 32768; // Max serial buffer size, for inputs...
const serialReconnectTime = settings.serialReconnectTime || 15000;
// TODO: 'serialPool' should be encapsulated in SerialPortNode // TODO: 'serialPool' should be encapsulated in SerialPortNode
@ -350,7 +351,7 @@ module.exports = function(RED) {
} }
obj.tout = setTimeout(function() { obj.tout = setTimeout(function() {
setupSerial(); setupSerial();
}, settings.serialReconnectTime); }, serialReconnectTime);
} }
}); });
obj.serial.on('error', function(err) { obj.serial.on('error', function(err) {
@ -359,7 +360,7 @@ module.exports = function(RED) {
if (obj.tout) { clearTimeout(obj.tout); } if (obj.tout) { clearTimeout(obj.tout); }
obj.tout = setTimeout(function() { obj.tout = setTimeout(function() {
setupSerial(); setupSerial();
}, settings.serialReconnectTime); }, serialReconnectTime);
}); });
obj.serial.on('close', function() { obj.serial.on('close', function() {
if (!obj._closing) { if (!obj._closing) {
@ -371,7 +372,7 @@ module.exports = function(RED) {
if (obj.tout) { clearTimeout(obj.tout); } if (obj.tout) { clearTimeout(obj.tout); }
obj.tout = setTimeout(function() { obj.tout = setTimeout(function() {
setupSerial(); setupSerial();
}, settings.serialReconnectTime); }, serialReconnectTime);
} }
}); });
obj.serial.on('open',function() { obj.serial.on('open',function() {