@vitormnm/node-red-simple-opcua 1.4.3 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/client/icons/opcua.svg +132 -132
  2. package/client/lib/opcua-client-browser.js +368 -330
  3. package/client/lib/opcua-client-method-service.js +88 -88
  4. package/client/lib/opcua-client-read-service.js +27 -15
  5. package/client/lib/opcua-client-subscription-id-service.js +24 -24
  6. package/client/lib/opcua-client-subscription-service.js +175 -170
  7. package/client/lib/opcua-client-write-service.js +146 -146
  8. package/client/opcua-client-config.html +80 -80
  9. package/client/opcua-client-utils.js +217 -22
  10. package/client/opcua-client.html +140 -140
  11. package/client/view/opcua-client.js +1144 -1140
  12. package/examples/flows_simple_opc.json +1 -2851
  13. package/icons/opcua.svg +132 -132
  14. package/icons/opcua2.svg +132 -132
  15. package/package.json +3 -3
  16. package/server/icons/opcua.svg +132 -132
  17. package/server/lib/opcua-address-space-alarm.js +341 -341
  18. package/server/lib/opcua-address-space-builder.js +1797 -1485
  19. package/server/lib/opcua-config.js +800 -546
  20. package/server/lib/opcua-constants.js +120 -109
  21. package/server/lib/opcua-server-events-child.js +139 -139
  22. package/server/lib/opcua-server-methods.js +2 -0
  23. package/server/lib/opcua-server-runtime-child.js +874 -819
  24. package/server/lib/opcua-server-runtime.js +385 -311
  25. package/server/lib/opcua-server-status-child.js +187 -187
  26. package/server/lib/server-node-utils.js +16 -16
  27. package/server/opcua-server-io.html +346 -346
  28. package/server/opcua-server-io.js +497 -496
  29. package/server/opcua-server-registry.js +270 -270
  30. package/server/opcua-server.css +265 -265
  31. package/server/opcua-server.html +158 -1643
  32. package/server/opcua-server.js +24 -13
  33. package/server/view/opcua-server.css +496 -0
  34. package/server/view/opcua-server.js +1585 -0
@@ -1,88 +1,88 @@
1
- "use strict";
2
-
3
- const { dataValueToItemResult, ensureArrayPayload, resolveNodeId, resolveMethodObjectId, buildVariantFromItem, callResultToItemResult } = require("../opcua-client-utils");
4
-
5
- class OpcUaClientMethodService {
6
- async execute(node, msg, session, itemsResolver) {
7
-
8
- // const items = ensureArrayPayload(msg, "OPC UA method call");
9
- const items = itemsResolver.ensureMethodItems(node, msg, "OPC UA method");
10
- const payload = [];
11
-
12
-
13
-
14
- for (const item of items) {
15
- const methodNodeId = this.resolveMethodId(item);
16
-
17
- try {
18
- const objectId = this.resolveMethodObjectIdFromItem(item) || await resolveMethodObjectId(
19
- session,
20
- methodNodeId,
21
- node.connection.methodObjectIdCache
22
- );
23
- const argumentDefinition = await this.safeGetMethodArgumentDefinition(
24
- session,
25
- methodNodeId,
26
- node.connection.methodDefinitionCache
27
- );
28
- const callRequest = {
29
- objectId,
30
- methodId: methodNodeId
31
- };
32
-
33
- if (Array.isArray(item.inputs) && item.inputs.length > 0) {
34
- callRequest.inputArguments = item.inputs.map((input) => buildVariantFromItem(input, input.type));
35
- }
36
-
37
- const callResult = await session.call(callRequest);
38
- payload.push(callResultToItemResult(item, callResult, argumentDefinition));
39
- } catch (itemError) {
40
- payload.push({
41
- name: item.name || methodNodeId,
42
- nodeID: methodNodeId,
43
- status: itemError.message,
44
- outputs: []
45
- });
46
- }
47
- }
48
-
49
- return payload;
50
- }
51
-
52
-
53
-
54
- resolveMethodId(item) {
55
- const methodId = item && (item.methodID || item.methodId || item.nodeID || item.nodeId);
56
- if (!methodId || !String(methodId).trim()) {
57
- throw new Error("Each method item must contain methodId or nodeID");
58
- }
59
-
60
- return String(methodId).trim();
61
- }
62
-
63
-
64
- resolveMethodObjectIdFromItem(item) {
65
- const objectId = item && (item.objectID || item.objectId);
66
- if (!objectId || !String(objectId).trim()) {
67
- return "";
68
- }
69
-
70
- return String(objectId).trim();
71
- }
72
-
73
- async safeGetMethodArgumentDefinition(session, methodNodeId, cache) {
74
- try {
75
- return await getMethodArgumentDefinition(session, methodNodeId, cache);
76
- } catch (error) {
77
- return {
78
- inputArguments: [],
79
- outputArguments: []
80
- };
81
- }
82
- }
83
-
84
- }
85
-
86
- module.exports = {
87
- OpcUaClientMethodService
88
- };
1
+ "use strict";
2
+
3
+ const { dataValueToItemResult, ensureArrayPayload, resolveNodeId, resolveMethodObjectId, buildVariantFromItem, callResultToItemResult } = require("../opcua-client-utils");
4
+
5
+ class OpcUaClientMethodService {
6
+ async execute(node, msg, session, itemsResolver) {
7
+
8
+ // const items = ensureArrayPayload(msg, "OPC UA method call");
9
+ const items = itemsResolver.ensureMethodItems(node, msg, "OPC UA method");
10
+ const payload = [];
11
+
12
+
13
+
14
+ for (const item of items) {
15
+ const methodNodeId = this.resolveMethodId(item);
16
+
17
+ try {
18
+ const objectId = this.resolveMethodObjectIdFromItem(item) || await resolveMethodObjectId(
19
+ session,
20
+ methodNodeId,
21
+ node.connection.methodObjectIdCache
22
+ );
23
+ const argumentDefinition = await this.safeGetMethodArgumentDefinition(
24
+ session,
25
+ methodNodeId,
26
+ node.connection.methodDefinitionCache
27
+ );
28
+ const callRequest = {
29
+ objectId,
30
+ methodId: methodNodeId
31
+ };
32
+
33
+ if (Array.isArray(item.inputs) && item.inputs.length > 0) {
34
+ callRequest.inputArguments = item.inputs.map((input) => buildVariantFromItem(input, input.type));
35
+ }
36
+
37
+ const callResult = await session.call(callRequest);
38
+ payload.push(callResultToItemResult(item, callResult, argumentDefinition));
39
+ } catch (itemError) {
40
+ payload.push({
41
+ name: item.name || methodNodeId,
42
+ nodeID: methodNodeId,
43
+ status: itemError.message,
44
+ outputs: []
45
+ });
46
+ }
47
+ }
48
+
49
+ return payload;
50
+ }
51
+
52
+
53
+
54
+ resolveMethodId(item) {
55
+ const methodId = item && (item.methodID || item.methodId || item.nodeID || item.nodeId);
56
+ if (!methodId || !String(methodId).trim()) {
57
+ throw new Error("Each method item must contain methodId or nodeID");
58
+ }
59
+
60
+ return String(methodId).trim();
61
+ }
62
+
63
+
64
+ resolveMethodObjectIdFromItem(item) {
65
+ const objectId = item && (item.objectID || item.objectId);
66
+ if (!objectId || !String(objectId).trim()) {
67
+ return "";
68
+ }
69
+
70
+ return String(objectId).trim();
71
+ }
72
+
73
+ async safeGetMethodArgumentDefinition(session, methodNodeId, cache) {
74
+ try {
75
+ return await getMethodArgumentDefinition(session, methodNodeId, cache);
76
+ } catch (error) {
77
+ return {
78
+ inputArguments: [],
79
+ outputArguments: []
80
+ };
81
+ }
82
+ }
83
+
84
+ }
85
+
86
+ module.exports = {
87
+ OpcUaClientMethodService
88
+ };
@@ -1,16 +1,28 @@
1
- "use strict";
2
-
3
- const { dataValueToItemResult, resolveNodeId } = require("../opcua-client-utils");
4
-
5
- class OpcUaClientReadService {
6
- async execute(node, msg, session, itemsResolver) {
7
- const items = itemsResolver.ensureClientItems(node, msg, "OPC UA read");
8
- const nodeIds = items.map((item) => resolveNodeId(item));
9
- const values = await session.readVariableValue(nodeIds);
10
- return values.map((dataValue, index) => dataValueToItemResult(items[index], dataValue));
11
- }
12
- }
13
-
14
- module.exports = {
15
- OpcUaClientReadService
1
+ "use strict";
2
+
3
+ const { dataValueToItemResult, resolveNodeId, enrichItemResultWithEnumeration } = require("../opcua-client-utils");
4
+
5
+ class OpcUaClientReadService {
6
+ async execute(node, msg, session, itemsResolver) {
7
+ const items = itemsResolver.ensureClientItems(node, msg, "OPC UA read");
8
+ const nodeIds = items.map((item) => resolveNodeId(item));
9
+ const values = await session.readVariableValue(nodeIds);
10
+
11
+ const cache = new Map();
12
+ const results = [];
13
+
14
+ for (let index = 0; index < values.length; index++) {
15
+ const dataValue = values[index];
16
+ const item = items[index];
17
+ let result = dataValueToItemResult(item, dataValue);
18
+ result = await enrichItemResultWithEnumeration(result, session, cache, nodeIds[index]);
19
+ results.push(result);
20
+ }
21
+
22
+ return results;
23
+ }
24
+ }
25
+
26
+ module.exports = {
27
+ OpcUaClientReadService
16
28
  };
@@ -1,25 +1,25 @@
1
- "use strict";
2
-
3
- const { ClientSubscription } = require("node-opcua");
4
-
5
- class OpcUaClientSubscriptionIdService {
6
- async execute(node) {
7
- const session = await node.connection.getSession();
8
- const subscription = ClientSubscription.create(session, {
9
- requestedPublishingInterval: 1000,
10
- requestedLifetimeCount: 100,
11
- requestedMaxKeepAliveCount: 10,
12
- maxNotificationsPerPublish: 100,
13
- publishingEnabled: true,
14
- priority: 10
15
- });
16
-
17
- const subscriptionId = subscription.subscriptionId;
18
- await subscription.terminate();
19
- return subscriptionId;
20
- }
21
- }
22
-
23
- module.exports = {
24
- OpcUaClientSubscriptionIdService
1
+ "use strict";
2
+
3
+ const { ClientSubscription } = require("node-opcua");
4
+
5
+ class OpcUaClientSubscriptionIdService {
6
+ async execute(node) {
7
+ const session = await node.connection.getSession();
8
+ const subscription = ClientSubscription.create(session, {
9
+ requestedPublishingInterval: 1000,
10
+ requestedLifetimeCount: 100,
11
+ requestedMaxKeepAliveCount: 10,
12
+ maxNotificationsPerPublish: 100,
13
+ publishingEnabled: true,
14
+ priority: 10
15
+ });
16
+
17
+ const subscriptionId = subscription.subscriptionId;
18
+ await subscription.terminate();
19
+ return subscriptionId;
20
+ }
21
+ }
22
+
23
+ module.exports = {
24
+ OpcUaClientSubscriptionIdService
25
25
  };
@@ -1,171 +1,176 @@
1
- "use strict";
2
-
3
- const {
4
- ClientMonitoredItem,
5
- ClientSubscription,
6
- TimestampsToReturn,
7
- AttributeIds,
8
- constructEventFilter
9
- } = require("node-opcua");
10
-
11
- const {
12
- dataValueToItemResult,
13
- dataValueToItemResultEvent,
14
- resolveName,
15
- resolveNodeId,
16
- statusCodeToString
17
- } = require("../opcua-client-utils");
18
-
19
- class OpcUaClientSubscriptionService {
20
- async startDataSubscription(node, msg, itemsResolver) {
21
- const items = itemsResolver.ensureClientItems(node, msg, "OPC UA subscription");
22
- await this.stop(node);
23
-
24
- const session = await node.connection.getSession();
25
- const subscription = ClientSubscription.create(session, {
26
- requestedPublishingInterval: node.publishingInterval,
27
- requestedLifetimeCount: 60,
28
- requestedMaxKeepAliveCount: 10,
29
- maxNotificationsPerPublish: 100,
30
- publishingEnabled: true,
31
- priority: 1
32
- });
33
-
34
- subscription.on("error", (error) => {
35
- node.status({ fill: "red", shape: "ring", text: "subscription error" });
36
- node.error(error);
37
- });
38
-
39
- node.subscription = subscription;
40
- node.monitoredItems = items.map((item) => {
41
- const monitoredItem = ClientMonitoredItem.create(
42
- subscription,
43
- { nodeId: resolveNodeId(item) },
44
- {
45
- samplingInterval: node.samplingInterval,
46
- discardOldest: true,
47
- queueSize: 1
48
- },
49
- TimestampsToReturn.Both
50
- );
51
-
52
- monitoredItem.on("changed", (dataValue) => {
53
- const payload = dataValueToItemResult(item, dataValue);
54
- node.status({
55
- fill: "blue",
56
- shape: "dot",
57
- text: resolveName(item, payload.nodeID) + " changed"
58
- });
59
- node.send({
60
- topic: payload.name,
61
- payload,
62
- opcua: {
63
- mode: "subscription",
64
- nodeID: payload.nodeID,
65
- status: payload.status
66
- }
67
- });
68
- });
69
-
70
- monitoredItem.on("err", (message) => {
71
- node.status({ fill: "red", shape: "ring", text: statusCodeToString(message) });
72
- });
73
-
74
- return monitoredItem;
75
- });
76
-
77
- return items;
78
- }
79
-
80
- async startEventSubscription(node, msg, itemsResolver) {
81
- const items = itemsResolver.ensureClientItems(node, msg, "OPC UA subscription");
82
- await this.stop(node);
83
-
84
- const session = await node.connection.getSession();
85
- const subscription = ClientSubscription.create(session, {
86
- requestedPublishingInterval: node.publishingInterval,
87
- requestedLifetimeCount: 60,
88
- requestedMaxKeepAliveCount: 10,
89
- maxNotificationsPerPublish: 100,
90
- publishingEnabled: true,
91
- priority: 2
92
- });
93
-
94
- subscription.on("error", (error) => {
95
- node.status({ fill: "red", shape: "ring", text: "subscription error" });
96
- node.error(error);
97
- });
98
-
99
- node.subscription = subscription;
100
-
101
- const eventFilter = constructEventFilter([
102
- "EventId",
103
- "EventType",
104
- "SourceName",
105
- "SourceNode",
106
- "Message",
107
- "Severity",
108
- "ActiveState",
109
- "AckedState",
110
- "ConfirmedState",
111
- "Time"
112
- ]);
113
-
114
- node.monitoredItems = items.map((item) => {
115
- const monitoredItem = ClientMonitoredItem.create(
116
- subscription,
117
- {
118
- nodeId: resolveNodeId(item),
119
- attributeId: AttributeIds.EventNotifier
120
- },
121
- {
122
- samplingInterval: 0,
123
- queueSize: 100,
124
- discardOldest: true,
125
- filter: eventFilter
126
- },
127
- TimestampsToReturn.Both
128
- );
129
-
130
- monitoredItem.on("changed", async (eventFields) => {
131
- const payload = await dataValueToItemResultEvent(item, eventFields, session);
132
- node.status({
133
- fill: "blue",
134
- shape: "dot",
135
- text: resolveName(item, payload.nodeID) + " changed"
136
- });
137
- node.send({
138
- topic: payload.name,
139
- payload,
140
- opcua: {
141
- mode: "subscription",
142
- nodeID: payload.nodeID,
143
- status: payload.status
144
- }
145
- });
146
- });
147
-
148
- monitoredItem.on("err", (message) => {
149
- node.status({ fill: "red", shape: "ring", text: statusCodeToString(message) });
150
- });
151
-
152
- return monitoredItem;
153
- });
154
-
155
- return items;
156
- }
157
-
158
- async stop(node) {
159
- const subscription = node.subscription;
160
- node.monitoredItems = [];
161
- node.subscription = null;
162
-
163
- if (subscription) {
164
- await subscription.terminate();
165
- }
166
- }
167
- }
168
-
169
- module.exports = {
170
- OpcUaClientSubscriptionService
1
+ "use strict";
2
+
3
+ const {
4
+ ClientMonitoredItem,
5
+ ClientSubscription,
6
+ TimestampsToReturn,
7
+ AttributeIds,
8
+ constructEventFilter
9
+ } = require("node-opcua");
10
+
11
+ const {
12
+ dataValueToItemResult,
13
+ dataValueToItemResultEvent,
14
+ enrichItemResultWithEnumeration,
15
+ resolveName,
16
+ resolveNodeId,
17
+ statusCodeToString
18
+ } = require("../opcua-client-utils");
19
+
20
+ class OpcUaClientSubscriptionService {
21
+ async startDataSubscription(node, msg, itemsResolver) {
22
+ const items = itemsResolver.ensureClientItems(node, msg, "OPC UA subscription");
23
+ await this.stop(node);
24
+
25
+ const session = await node.connection.getSession();
26
+ const subscription = ClientSubscription.create(session, {
27
+ requestedPublishingInterval: node.publishingInterval,
28
+ requestedLifetimeCount: 60,
29
+ requestedMaxKeepAliveCount: 10,
30
+ maxNotificationsPerPublish: 100,
31
+ publishingEnabled: true,
32
+ priority: 1
33
+ });
34
+
35
+ subscription.on("error", (error) => {
36
+ node.status({ fill: "red", shape: "ring", text: "subscription error" });
37
+ node.error(error);
38
+ });
39
+
40
+ node.subscription = subscription;
41
+ node.monitoredItems = items.map((item) => {
42
+ const monitoredItem = ClientMonitoredItem.create(
43
+ subscription,
44
+ { nodeId: resolveNodeId(item) },
45
+ {
46
+ samplingInterval: node.samplingInterval,
47
+ discardOldest: true,
48
+ queueSize: 1
49
+ },
50
+ TimestampsToReturn.Both
51
+ );
52
+
53
+ const cache = new Map();
54
+ monitoredItem.on("changed", async (dataValue) => {
55
+ let payload = dataValueToItemResult(item, dataValue);
56
+ payload = await enrichItemResultWithEnumeration(payload, session, cache, resolveNodeId(item));
57
+
58
+ node.status({
59
+ fill: "blue",
60
+ shape: "dot",
61
+ text: resolveName(item, payload.nodeID) + " changed"
62
+ });
63
+ node.send({
64
+ topic: payload.name,
65
+ payload,
66
+ opcua: {
67
+ mode: "subscription",
68
+ nodeID: payload.nodeID,
69
+ status: payload.status
70
+ }
71
+ });
72
+ });
73
+
74
+ monitoredItem.on("err", (message) => {
75
+ node.status({ fill: "red", shape: "ring", text: statusCodeToString(message) });
76
+ });
77
+
78
+ return monitoredItem;
79
+ });
80
+
81
+ return items;
82
+ }
83
+
84
+ async startEventSubscription(node, msg, itemsResolver) {
85
+ const items = itemsResolver.ensureClientItems(node, msg, "OPC UA subscription");
86
+ await this.stop(node);
87
+
88
+ const session = await node.connection.getSession();
89
+ const subscription = ClientSubscription.create(session, {
90
+ requestedPublishingInterval: node.publishingInterval,
91
+ requestedLifetimeCount: 60,
92
+ requestedMaxKeepAliveCount: 10,
93
+ maxNotificationsPerPublish: 100,
94
+ publishingEnabled: true,
95
+ priority: 2
96
+ });
97
+
98
+ subscription.on("error", (error) => {
99
+ node.status({ fill: "red", shape: "ring", text: "subscription error" });
100
+ node.error(error);
101
+ });
102
+
103
+ node.subscription = subscription;
104
+
105
+ const eventFilter = constructEventFilter([
106
+ "EventId",
107
+ "EventType",
108
+ "SourceName",
109
+ "SourceNode",
110
+ "Message",
111
+ "Severity",
112
+ "ActiveState",
113
+ "AckedState",
114
+ "ConfirmedState",
115
+ "Time",
116
+ "ConditionId"
117
+ ]);
118
+
119
+ node.monitoredItems = items.map((item) => {
120
+ const monitoredItem = ClientMonitoredItem.create(
121
+ subscription,
122
+ {
123
+ nodeId: resolveNodeId(item),
124
+ attributeId: AttributeIds.EventNotifier
125
+ },
126
+ {
127
+ samplingInterval: 0,
128
+ queueSize: 100,
129
+ discardOldest: true,
130
+ filter: eventFilter
131
+ },
132
+ TimestampsToReturn.Both
133
+ );
134
+
135
+ monitoredItem.on("changed", async (eventFields) => {
136
+ const payload = await dataValueToItemResultEvent(item, eventFields, session);
137
+ node.status({
138
+ fill: "blue",
139
+ shape: "dot",
140
+ text: resolveName(item, payload.nodeID) + " changed"
141
+ });
142
+ node.send({
143
+ topic: payload.name,
144
+ payload,
145
+ opcua: {
146
+ mode: "subscription",
147
+ nodeID: payload.nodeID,
148
+ status: payload.status
149
+ }
150
+ });
151
+ });
152
+
153
+ monitoredItem.on("err", (message) => {
154
+ node.status({ fill: "red", shape: "ring", text: statusCodeToString(message) });
155
+ });
156
+
157
+ return monitoredItem;
158
+ });
159
+
160
+ return items;
161
+ }
162
+
163
+ async stop(node) {
164
+ const subscription = node.subscription;
165
+ node.monitoredItems = [];
166
+ node.subscription = null;
167
+
168
+ if (subscription) {
169
+ await subscription.terminate();
170
+ }
171
+ }
172
+ }
173
+
174
+ module.exports = {
175
+ OpcUaClientSubscriptionService
171
176
  };