mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
reuest node enablement
This commit is contained in:
parent
b82e2cd12a
commit
a6cbc340e5
@ -117,6 +117,10 @@ module.exports = function(RED) {
|
||||
setCallback(node, node.serialConfig);
|
||||
});
|
||||
|
||||
this.on("close", function(done) {
|
||||
serialPool.close(this.serialConfig.serialport,done);
|
||||
});
|
||||
|
||||
function setCallback(node) {
|
||||
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.not-connected"});
|
||||
node.port = serialPool.get(node.serialConfig);
|
||||
@ -174,28 +178,37 @@ module.exports = function(RED) {
|
||||
});
|
||||
});
|
||||
|
||||
// Serial In
|
||||
this.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)
|
||||
if (sender !== node) { return; }
|
||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.ok"});
|
||||
msgout.status = "OK";
|
||||
node.send(msgout);
|
||||
});
|
||||
this.port.on('timeout', function(msgout, sender) {
|
||||
if (sender !== node) { return; }
|
||||
msgout.status = "ERR_TIMEOUT";
|
||||
node.status({fill:"red",shape:"ring",text:"serial.status.timeout"});
|
||||
node.send(msgout);
|
||||
let serialConfig = this.serialConfig;
|
||||
serialConfig.on('newport', function(newPort) {
|
||||
node.port = serialPool.get(serialConfig);
|
||||
setCallback(node);
|
||||
});
|
||||
|
||||
// Common part
|
||||
node.port.on('ready', function() {
|
||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
||||
});
|
||||
node.port.on('closed', function() {
|
||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"});
|
||||
});
|
||||
// Serial In
|
||||
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)
|
||||
if (sender !== node) { return; }
|
||||
node.status({ fill: "green", shape: "dot", text: "node-red:common.status.ok" });
|
||||
msgout.status = "OK";
|
||||
node.send(msgout);
|
||||
});
|
||||
node.port.on('timeout', function (msgout, sender) {
|
||||
if (sender !== node) { return; }
|
||||
msgout.status = "ERR_TIMEOUT";
|
||||
node.status({ fill: "red", shape: "ring", text: "serial.status.timeout" });
|
||||
node.send(msgout);
|
||||
});
|
||||
|
||||
// Common part
|
||||
node.port.on('ready', function () {
|
||||
node.status({ fill: "green", shape: "dot", text: "node-red:common.status.connected" });
|
||||
});
|
||||
node.port.on('closed', function () {
|
||||
node.status({ fill: "red", shape: "ring", text: "node-red:common.status.not-connected" });
|
||||
});
|
||||
};
|
||||
setCallback(node);
|
||||
}
|
||||
else {
|
||||
this.error(RED._("serial.errors.missing-conf"), {});
|
||||
@ -372,6 +385,7 @@ module.exports = function(RED) {
|
||||
},
|
||||
}
|
||||
//newline = newline.replace("\\n","\n").replace("\\r","\r");
|
||||
obj._emitter.setMaxListeners(50);
|
||||
var olderr = "";
|
||||
var setupSerial = function() {
|
||||
obj.serial = new SerialPort({
|
||||
|
Loading…
x
Reference in New Issue
Block a user