-
Notifications
You must be signed in to change notification settings - Fork 7
/
din.js
74 lines (68 loc) · 2.85 KB
/
din.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module.exports = function (RED) {
function DINNode(config) {
RED.nodes.createNode(this, config);
this.plate = RED.nodes.getNode(config.config_plate).plate;
this.input = parseInt(config.input, 10);
this.state = 0;
var node = this;
if (RED.nodes.getNode(config.config_plate).model == "TINKERplate") {
const conf = {cmd: "setIN", args: {bit: node.input}};
node.plate.send(conf, (reply) => {});
}
node.on('input', function (msg, send, done) {
let type = RED.nodes.getNode(config.config_plate).model;
let channelValid = false;
let cmd_str = "getDINbit";
if (type == "DAQCplate" || type == "DAQC2plate") {
// valid values are 0-7
if (node.input >= 0 && node.input <= 7) {
channelValid = true;
}
} else if (type == "DIGIplate") {
// valid values are 1-8
if (node.input >= 1 && node.input <= 8) {
channelValid = true;
}
} else if (type == "ADCplate") {
// 0-3 plus TRIG is 4
if (node.input >= 0 && node.input <= 4) {
channelValid = true;
}
} else if (type == "TINKERplate") {
if (node.input >= 1 && node.input <= 8) {
channelValid = true;
}
cmd_str = "getDIN";
}
if (!node.plate.plate_status && channelValid) {
const obj = {cmd: cmd_str, args: {bit: node.input}};
node.plate.send(obj, (reply) => {
node.state = reply.state;
node.status({text: node.state});
msg.payload = node.state;
send(msg);
});
} else if (node.plate.plate_status == 1) {
node.status({fill: "red", shape: "ring", text: "invalid plate"});
node.log("invalid plate");
node.plate.update_status();
} else if (node.plate.plate_status == 2) {
node.status({fill: "red", shape: "ring", text: "missing python dependencies"});
node.log("missing python dependencies");
} else if (node.plate.plate_status == 3) {
node.status({fill: "red", shape: "ring", text: "python process error"});
node.log("python process error");
} else if (!channelValid) {
node.status({fill: "red", shape: "ring", text: "invalid channel"});
node.log("invalid channel");
}
if (done) {
done();
}
});
this.on('close', function () {
// cleanup goes here
});
}
RED.nodes.registerType("ppDIN", DINNode);
}