reuest node enablement

This commit is contained in:
Yoonseok Hur 2023-11-14 15:41:56 +09:00
parent b82e2cd12a
commit a6cbc340e5

View File

@ -117,6 +117,10 @@ module.exports = function(RED) {
setCallback(node, node.serialConfig); setCallback(node, node.serialConfig);
}); });
this.on("close", function(done) {
serialPool.close(this.serialConfig.serialport,done);
});
function setCallback(node) { function setCallback(node) {
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.not-connected"}); node.status({fill:"grey",shape:"dot",text:"node-red:common.status.not-connected"});
node.port = serialPool.get(node.serialConfig); node.port = serialPool.get(node.serialConfig);
@ -174,15 +178,22 @@ module.exports = function(RED) {
}); });
}); });
let serialConfig = this.serialConfig;
serialConfig.on('newport', function(newPort) {
node.port = serialPool.get(serialConfig);
setCallback(node);
});
// Serial In // Serial In
this.port.on('data', function(msgout, sender) { function setCallback(node) {
node.port.on('data', function (msgout, sender) {
// serial request will only process incoming data pertaining to its own request (i.e. when it's at the head of the queue) // serial request will only process incoming data pertaining to its own request (i.e. when it's at the head of the queue)
if (sender !== node) { return; } if (sender !== node) { return; }
node.status({ fill: "green", shape: "dot", text: "node-red:common.status.ok" }); node.status({ fill: "green", shape: "dot", text: "node-red:common.status.ok" });
msgout.status = "OK"; msgout.status = "OK";
node.send(msgout); node.send(msgout);
}); });
this.port.on('timeout', function(msgout, sender) { node.port.on('timeout', function (msgout, sender) {
if (sender !== node) { return; } if (sender !== node) { return; }
msgout.status = "ERR_TIMEOUT"; msgout.status = "ERR_TIMEOUT";
node.status({ fill: "red", shape: "ring", text: "serial.status.timeout" }); node.status({ fill: "red", shape: "ring", text: "serial.status.timeout" });
@ -196,6 +207,8 @@ module.exports = function(RED) {
node.port.on('closed', function () { node.port.on('closed', function () {
node.status({ fill: "red", shape: "ring", text: "node-red:common.status.not-connected" }); node.status({ fill: "red", shape: "ring", text: "node-red:common.status.not-connected" });
}); });
};
setCallback(node);
} }
else { else {
this.error(RED._("serial.errors.missing-conf"), {}); this.error(RED._("serial.errors.missing-conf"), {});
@ -372,6 +385,7 @@ module.exports = function(RED) {
}, },
} }
//newline = newline.replace("\\n","\n").replace("\\r","\r"); //newline = newline.replace("\\n","\n").replace("\\r","\r");
obj._emitter.setMaxListeners(50);
var olderr = ""; var olderr = "";
var setupSerial = function() { var setupSerial = function() {
obj.serial = new SerialPort({ obj.serial = new SerialPort({