@tier0/opcua-client 0.6.2 → 0.6.4

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.
package/nodes/write.html CHANGED
@@ -80,7 +80,7 @@
80
80
  </script>
81
81
  <script type="text/javascript">
82
82
  RED.nodes.registerType('tier0-opcua-write', {
83
- category: 'OPC UA', color: '#c7e9f1', inputs: 1, outputs: 2, outputLabels: ['Data', 'Status / errors'], icon: 'bridge.png',
83
+ category: 'OPC UA', color: '#c7e9f1', inputs: 1, outputs: 2, outputLabels: ['Data', 'Status / errors'], icon: 'font-awesome/fa-pencil',
84
84
  defaults: {
85
85
  connection: { value: '', type: 'tier0-opcua-connection', required: true },
86
86
  nodeId: { value: '' }, dataType: { value: 'String' },
package/nodes/write.js CHANGED
@@ -1,67 +1,72 @@
1
- 'use strict';
2
-
3
- const { createDiagnostics } = require('../lib/diagnostics');
4
-
5
- const { messageWritePoints } = require('../lib/points');
6
-
7
- module.exports = function registerWriteNode(RED) {
8
- function OpcUaWriteNode(config) {
9
- RED.nodes.createNode(this, config);
10
- const node = this;
11
- node.connection = RED.nodes.getNode(config.connection);
12
- const diagnostics = createDiagnostics(node, config, 'write');
13
- const consumer = node.connection?.registerConsumer?.('write', {
14
- nodeId: config.id, name: config.name,
15
- });
16
-
17
- node.on('input', async (msg, send, done) => {
18
- if (!node.connection) {
19
- const error = new Error('OPCUA_CONNECTION_NOT_CONFIGURED');
20
- diagnostics.failure(error, send);
21
- return done(error);
22
- }
23
-
24
- try {
25
- consumer?.markUsed('write');
26
- const points = messageWritePoints(msg, config);
27
- node.status({ fill: 'blue', shape: 'dot', text: `writing ${points.length}` });
28
- const results = await node.connection.client.writeMany(
29
- points,
30
- Number(config.batchSize) || 500
31
- );
32
-
33
- const failed = diagnostics.results(results, send, new Map(points.map((point) => [point.nodeId, point])));
34
- if ((config.outputMode || 'batch') === 'split') {
35
- results.forEach((result) => send({ ...msg, topic: result.nodeId, opcua: result }));
36
- } else {
37
- msg.payload = results;
38
- msg.opcua = {
39
- ...(msg.opcua || {}),
40
- operation: 'write',
41
- total: results.length,
42
- good: results.filter((item) => item.statusCode === 'Good').length,
43
- clientDiagnostics: node.connection.getDiagnostics?.() ||
44
- node.connection.client.getDiagnostics(),
45
- };
46
- send(msg);
47
- }
48
-
49
- node.status({ fill: failed ? 'yellow' : 'green', shape: failed ? 'ring' : 'dot',
50
- text: `${results.length - failed}/${results.length} written` + (failed ? ` / ${failed} failed` : '') });
51
- done();
52
- } catch (error) {
53
- node.status({ fill: 'red', shape: 'ring', text: error.message });
54
- diagnostics.failure(error, send);
55
- done(error);
56
- }
57
- });
58
-
59
- node.on('close', (removed, done) => {
60
- if (typeof removed === 'function') done = removed;
61
- consumer?.release();
62
- done?.();
63
- });
64
- }
65
-
66
- RED.nodes.registerType('tier0-opcua-write', OpcUaWriteNode);
67
- };
1
+ 'use strict';
2
+
3
+ const { createDiagnostics } = require('../lib/diagnostics');
4
+
5
+ const { messageWritePoints } = require('../lib/points');
6
+
7
+ module.exports = function registerWriteNode(RED) {
8
+ function OpcUaWriteNode(config) {
9
+ RED.nodes.createNode(this, config);
10
+ const node = this;
11
+ node.connection = RED.nodes.getNode(config.connection);
12
+ const diagnostics = createDiagnostics(node, config, 'write');
13
+ const consumer = node.connection?.registerConsumer?.('write', {
14
+ nodeId: config.id, name: config.name,
15
+ });
16
+
17
+ node.on('input', async (msg, send, done) => {
18
+ if (!node.connection) {
19
+ const error = new Error('OPCUA_CONNECTION_NOT_CONFIGURED');
20
+ diagnostics.failure(error, send);
21
+ return done(error);
22
+ }
23
+
24
+ diagnostics.beginInput();
25
+ let inputError;
26
+ try {
27
+ consumer?.markUsed('write');
28
+ const points = messageWritePoints(msg, config);
29
+ node.status({ fill: 'blue', shape: 'dot', text: `writing ${points.length}` });
30
+ const results = await node.connection.client.writeMany(
31
+ points,
32
+ Number(config.batchSize) || 500
33
+ );
34
+
35
+ const failed = diagnostics.results(results, send, new Map(points.map((point) => [point.nodeId, point])));
36
+ if ((config.outputMode || 'batch') === 'split') {
37
+ results.forEach((result) => send({ ...msg, topic: result.nodeId, opcua: result }));
38
+ } else {
39
+ msg.payload = results;
40
+ msg.opcua = {
41
+ ...(msg.opcua || {}),
42
+ operation: 'write',
43
+ total: results.length,
44
+ good: results.filter((item) => item.statusCode === 'Good').length,
45
+ clientDiagnostics: node.connection.getDiagnostics?.() ||
46
+ node.connection.client.getDiagnostics(),
47
+ };
48
+ send(msg);
49
+ }
50
+
51
+ node.status({ fill: failed ? 'yellow' : 'green', shape: failed ? 'ring' : 'dot',
52
+ text: `${results.length - failed}/${results.length} written` + (failed ? ` / ${failed} failed` : '') });
53
+ done();
54
+ } catch (error) {
55
+ inputError = error;
56
+ node.status({ fill: 'red', shape: 'ring', text: error.message });
57
+ diagnostics.failure(error, send);
58
+ done(error);
59
+ } finally {
60
+ diagnostics.endInput(inputError);
61
+ }
62
+ });
63
+
64
+ node.on('close', (removed, done) => {
65
+ if (typeof removed === 'function') done = removed;
66
+ consumer?.release();
67
+ done?.();
68
+ });
69
+ }
70
+
71
+ RED.nodes.registerType('tier0-opcua-write', OpcUaWriteNode);
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tier0/opcua-client",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "High-scale OPC UA client nodes for Node-RED powered by open62541",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {