mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow Serial nodes to close asynchonously
This commit is contained in:
parent
c317ccc36d
commit
8f1dd62515
@ -80,9 +80,11 @@ module.exports = function(RED) {
|
||||
this.error("missing serial config");
|
||||
}
|
||||
|
||||
this.on("close", function() {
|
||||
this.on("close", function(done) {
|
||||
if (this.serialConfig) {
|
||||
serialPool.close(this.serialConfig.serialport);
|
||||
serialPool.close(this.serialConfig.serialport,done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -115,12 +117,11 @@ module.exports = function(RED) {
|
||||
this.error("missing serial config");
|
||||
}
|
||||
|
||||
this.on("close", function() {
|
||||
this.on("close", function(done) {
|
||||
if (this.serialConfig) {
|
||||
try {
|
||||
serialPool.close(this.serialConfig.serialport);
|
||||
} catch(err) {
|
||||
}
|
||||
serialPool.close(this.serialConfig.serialport,done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -203,23 +204,29 @@ module.exports = function(RED) {
|
||||
}
|
||||
return connections[id];
|
||||
},
|
||||
close: function(port) {
|
||||
close: function(port,done) {
|
||||
if (connections[port]) {
|
||||
if (connections[port].tout != null) clearTimeout(connections[port].tout);
|
||||
if (connections[port].tout != null) {
|
||||
clearTimeout(connections[port].tout);
|
||||
}
|
||||
connections[port]._closing = true;
|
||||
try {
|
||||
connections[port].close(function() {
|
||||
util.log("[serial] serial port closed");
|
||||
done();
|
||||
});
|
||||
} catch(err) { };
|
||||
}
|
||||
delete connections[port];
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
RED.httpAdmin.get("/serialports",function(req,res) {
|
||||
serialp.list(function (err, ports) {
|
||||
console.log(JSON.stringify(ports));
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.write(JSON.stringify(ports));
|
||||
res.end();
|
||||
|
@ -35,11 +35,12 @@ function Node(n) {
|
||||
}
|
||||
|
||||
Node.prototype.on = function(event,callback) {
|
||||
var node = this;
|
||||
if (event == "close") {
|
||||
if (callback.length == 1) {
|
||||
this.close = function() {
|
||||
return when.promise(function(resolve) {
|
||||
callback(function() {
|
||||
callback.call(node,function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user