node-opcua-samples 2.75.0 → 2.76.0
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/bin/di_server.js +2 -2
- package/bin/interactive_client.js +83 -125
- package/bin/opcua_interceptor.js +41 -54
- package/bin/simple_server.js +1 -2
- package/dist/get_endpoints.d.ts +2 -2
- package/dist/get_endpoints.js +141 -141
- package/dist/mini_server.d.ts +1 -1
- package/dist/mini_server.js +88 -88
- package/dist/server_with_changing_password.d.ts +1 -1
- package/dist/server_with_changing_password.js +100 -100
- package/dist/server_with_push_certificate.d.ts +2 -2
- package/dist/server_with_push_certificate.js +111 -111
- package/dist/simple_client_ts.d.ts +2 -2
- package/dist/simple_client_ts.js +660 -660
- package/dist/simple_findservers.d.ts +2 -2
- package/dist/simple_findservers.js +48 -48
- package/dist/simple_secure_server.d.ts +2 -2
- package/dist/simple_secure_server.js +125 -125
- package/dist/simple_server_with_custom_extension_objects.d.ts +2 -2
- package/dist/simple_server_with_custom_extension_objects.js +81 -81
- package/dist/stressing_client.d.ts +1 -1
- package/dist/stressing_client.js +36 -36
- package/dist/tiny_client.d.ts +1 -1
- package/dist/tiny_client.js +32 -32
- package/package.json +5 -5
package/bin/di_server.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const os = require("os");
|
|
5
|
+
const { hostname} = require("os");
|
|
5
6
|
const chalk = require("chalk");
|
|
6
7
|
const opcua = require("node-opcua");
|
|
7
|
-
|
|
8
8
|
Error.stackTraceLimit = Infinity;
|
|
9
9
|
|
|
10
10
|
function constructFilename(filename) {
|
|
@@ -101,7 +101,7 @@ const server = new OPCUAServer({
|
|
|
101
101
|
|
|
102
102
|
userManager: userManager,
|
|
103
103
|
registerServerMethod: opcua.RegisterServerMethod.LDS,
|
|
104
|
-
discoveryServerEndpointUrl: argv.discoveryServerEndpointUrl || "opc.tcp://" +
|
|
104
|
+
discoveryServerEndpointUrl: argv.discoveryServerEndpointUrl || "opc.tcp://" + hostname() + ":4840"
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
process.title = "Node OPCUA Server on port : " + port;
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
/* eslint-disable no-case-declarations */
|
|
3
3
|
/* eslint no-process-exit: 0 */
|
|
4
4
|
"use strict";
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const treeify = require("treeify");
|
|
7
|
-
const sprintf = require("sprintf-js").sprintf;
|
|
8
5
|
const util = require("util");
|
|
9
6
|
const fs = require("fs");
|
|
10
7
|
const path = require("path");
|
|
8
|
+
const os = require("os");
|
|
9
|
+
const chalk = require("chalk");
|
|
10
|
+
const treeify = require("treeify");
|
|
11
|
+
const { sprintf } = require("sprintf-js");
|
|
11
12
|
const _ = require("underscore");
|
|
12
13
|
|
|
13
14
|
const opcua = require("node-opcua");
|
|
14
15
|
const UAProxyManager = opcua.UAProxyManager;
|
|
15
16
|
const DataType = opcua.DataType;
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
18
|
const utils = opcua.utils;
|
|
20
19
|
|
|
21
20
|
const { assert } = require("node-opcua-assert");
|
|
@@ -60,8 +59,6 @@ function add_endpoint_to_history(endpoint) {
|
|
|
60
59
|
|
|
61
60
|
let lines = [];
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
62
|
if (fs.existsSync(endpoints_history_file)) {
|
|
66
63
|
lines = fs.readFileSync(endpoints_history_file, "utf-8");
|
|
67
64
|
endpoints_history = lines.split(/\r\n|\n/);
|
|
@@ -69,12 +66,10 @@ if (fs.existsSync(endpoints_history_file)) {
|
|
|
69
66
|
|
|
70
67
|
const history_file = path.join(__dirname, ".history");
|
|
71
68
|
|
|
72
|
-
|
|
73
69
|
function completer(line, callback) {
|
|
74
|
-
|
|
75
70
|
let completions, hits;
|
|
76
71
|
|
|
77
|
-
if (
|
|
72
|
+
if (line.trim() === "" && curNode) {
|
|
78
73
|
// console.log(" completions ",completions);
|
|
79
74
|
let c = [".."].concat(curNodeCompletion);
|
|
80
75
|
if (curNodeCompletion.length === 1) {
|
|
@@ -86,7 +81,6 @@ function completer(line, callback) {
|
|
|
86
81
|
if ("open".match(new RegExp("^" + line.trim()))) {
|
|
87
82
|
completions = ["open localhost:port"];
|
|
88
83
|
return callback(null, [completions, line]);
|
|
89
|
-
|
|
90
84
|
} else {
|
|
91
85
|
if (the_session === null) {
|
|
92
86
|
if (client._secureChannel) {
|
|
@@ -99,13 +93,12 @@ function completer(line, callback) {
|
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
assert(completions.length >= 0);
|
|
102
|
-
hits = completions.filter(function(c) {
|
|
96
|
+
hits = completions.filter(function (c) {
|
|
103
97
|
return c.indexOf(line) === 0;
|
|
104
98
|
});
|
|
105
99
|
return callback(null, [hits.length ? hits : completions, line]);
|
|
106
100
|
}
|
|
107
101
|
|
|
108
|
-
|
|
109
102
|
const rl = readline.createInterface({
|
|
110
103
|
input: process.stdin,
|
|
111
104
|
output: process.stdout,
|
|
@@ -123,7 +116,7 @@ function save_history(callback) {
|
|
|
123
116
|
}
|
|
124
117
|
|
|
125
118
|
function w(str, width) {
|
|
126
|
-
return str.padEnd(width," ").substring(0, width);
|
|
119
|
+
return str.padEnd(width, " ").substring(0, width);
|
|
127
120
|
}
|
|
128
121
|
/**
|
|
129
122
|
* @method toDate
|
|
@@ -183,7 +176,6 @@ function toDate(str) {
|
|
|
183
176
|
} else {
|
|
184
177
|
return new Date(str);
|
|
185
178
|
}
|
|
186
|
-
|
|
187
179
|
}
|
|
188
180
|
function log() {
|
|
189
181
|
rl.pause();
|
|
@@ -199,14 +191,12 @@ let nodePath = [];
|
|
|
199
191
|
let nodePathName = [];
|
|
200
192
|
const lowerFirstLetter = opcua.utils.lowerFirstLetter;
|
|
201
193
|
|
|
202
|
-
|
|
203
194
|
function setCurrentNode(node) {
|
|
204
|
-
|
|
205
195
|
curNode = node;
|
|
206
196
|
const curNodeBrowseName = lowerFirstLetter(curNode.browseName.name.toString());
|
|
207
197
|
nodePathName.push(curNodeBrowseName);
|
|
208
198
|
nodePath.push(node);
|
|
209
|
-
curNodeCompletion = node.$components.map(function(c) {
|
|
199
|
+
curNodeCompletion = node.$components.map(function (c) {
|
|
210
200
|
if (!c.browseName) {
|
|
211
201
|
return "???";
|
|
212
202
|
}
|
|
@@ -221,7 +211,6 @@ function setRootNode(node) {
|
|
|
221
211
|
setCurrentNode(node);
|
|
222
212
|
}
|
|
223
213
|
function moveToChild(browseName) {
|
|
224
|
-
|
|
225
214
|
if (browseName === "..") {
|
|
226
215
|
nodePathName.pop();
|
|
227
216
|
curNode = nodePath.splice(-1, 1)[0];
|
|
@@ -236,12 +225,9 @@ function moveToChild(browseName) {
|
|
|
236
225
|
setCurrentNode(child);
|
|
237
226
|
}
|
|
238
227
|
function get_root_folder(callback) {
|
|
239
|
-
|
|
240
228
|
if (!rootFolder) {
|
|
241
|
-
|
|
242
229
|
rl.pause();
|
|
243
|
-
proxyManager.getObject(opcua.makeNodeId(opcua.ObjectIds.RootFolder), function(err, data) {
|
|
244
|
-
|
|
230
|
+
proxyManager.getObject(opcua.makeNodeId(opcua.ObjectIds.RootFolder), function (err, data) {
|
|
245
231
|
if (!err) {
|
|
246
232
|
rootFolder = data;
|
|
247
233
|
assert(rootFolder, "expecting rootFolder");
|
|
@@ -256,27 +242,26 @@ function get_root_folder(callback) {
|
|
|
256
242
|
}
|
|
257
243
|
}
|
|
258
244
|
|
|
259
|
-
|
|
260
|
-
client.on("send_chunk", function(message_chunk) {
|
|
245
|
+
client.on("send_chunk", function (message_chunk) {
|
|
261
246
|
if (dumpMessageChunk) {
|
|
262
247
|
process.stdout.write(">> " + message_chunk.length + "\r");
|
|
263
248
|
}
|
|
264
249
|
});
|
|
265
250
|
|
|
266
|
-
client.on("receive_chunk", function(message_chunk) {
|
|
251
|
+
client.on("receive_chunk", function (message_chunk) {
|
|
267
252
|
if (dumpMessageChunk) {
|
|
268
253
|
process.stdout.write("<< " + message_chunk.length + "\r");
|
|
269
254
|
}
|
|
270
255
|
});
|
|
271
256
|
|
|
272
|
-
client.on("send_request", function(message) {
|
|
257
|
+
client.on("send_request", function (message) {
|
|
273
258
|
if (dumpPacket) {
|
|
274
259
|
log(chalk.red(" sending request"));
|
|
275
260
|
opcua.analyze_object_binary_encoding(message);
|
|
276
261
|
}
|
|
277
262
|
});
|
|
278
263
|
|
|
279
|
-
client.on("receive_response", function(message) {
|
|
264
|
+
client.on("receive_response", function (message) {
|
|
280
265
|
if (dumpPacket) {
|
|
281
266
|
assert(message);
|
|
282
267
|
log(chalk.cyan.bold(" receive response"));
|
|
@@ -284,24 +269,21 @@ client.on("receive_response", function(message) {
|
|
|
284
269
|
}
|
|
285
270
|
});
|
|
286
271
|
|
|
287
|
-
|
|
288
272
|
function dumpNodeResult(node) {
|
|
289
|
-
const str = sprintf(" %-30s%s%s", node.browseName.name,
|
|
273
|
+
const str = sprintf(" %-30s%s%s", node.browseName.name, node.isForward ? "->" : "<-", node.nodeId.displayText());
|
|
290
274
|
log(str);
|
|
291
275
|
}
|
|
292
276
|
function colorize(value) {
|
|
293
277
|
return chalk.yellow.bold("" + value);
|
|
294
278
|
}
|
|
295
279
|
|
|
296
|
-
|
|
297
280
|
if (rl.history) {
|
|
298
|
-
|
|
299
281
|
if (fs.existsSync(history_file)) {
|
|
300
282
|
lines = fs.readFileSync(history_file, "utf-8");
|
|
301
283
|
lines = lines.split(/\r\n|\n/);
|
|
302
284
|
}
|
|
303
285
|
if (lines.length === 0) {
|
|
304
|
-
let hostname =
|
|
286
|
+
let hostname = os.hostname();
|
|
305
287
|
hostname = hostname.toLowerCase();
|
|
306
288
|
rl.history.push("open opc.tcp://opcua.demo-this.com:51210/UA/SampleServer");
|
|
307
289
|
rl.history.push("open opc.tcp://" + hostname + ":51210/UA/SampleServer");
|
|
@@ -316,18 +298,15 @@ if (rl.history) {
|
|
|
316
298
|
}
|
|
317
299
|
}
|
|
318
300
|
|
|
319
|
-
process.on("uncaughtException", function(e) {
|
|
301
|
+
process.on("uncaughtException", function (e) {
|
|
320
302
|
util.puts(e.stack.red);
|
|
321
303
|
rl.prompt();
|
|
322
304
|
});
|
|
323
305
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
306
|
function apply_command(cmd, func, callback) {
|
|
328
|
-
callback = callback || function() {
|
|
307
|
+
callback = callback || function () {};
|
|
329
308
|
rl.pause();
|
|
330
|
-
func(function(err) {
|
|
309
|
+
func(function (err) {
|
|
331
310
|
callback();
|
|
332
311
|
rl.resume();
|
|
333
312
|
rl.prompt(the_prompt);
|
|
@@ -335,12 +314,11 @@ function apply_command(cmd, func, callback) {
|
|
|
335
314
|
}
|
|
336
315
|
|
|
337
316
|
function apply_on_valid_session(cmd, func, callback) {
|
|
338
|
-
|
|
339
317
|
assert(typeof func === "function");
|
|
340
318
|
assert(func.length === 2);
|
|
341
319
|
|
|
342
320
|
if (the_session) {
|
|
343
|
-
apply_command(cmd, function(callback) {
|
|
321
|
+
apply_command(cmd, function (callback) {
|
|
344
322
|
func(the_session, callback);
|
|
345
323
|
});
|
|
346
324
|
} else {
|
|
@@ -351,7 +329,7 @@ function apply_on_valid_session(cmd, func, callback) {
|
|
|
351
329
|
function dump_dataValues(nodesToRead, dataValues) {
|
|
352
330
|
for (let i = 0; i < dataValues.length; i++) {
|
|
353
331
|
const dataValue = dataValues[i];
|
|
354
|
-
log(" Node : ", chalk.cyan.bold(
|
|
332
|
+
log(" Node : ", chalk.cyan.bold(nodesToRead[i].nodeId.toString()), nodesToRead[i].attributeId.toString());
|
|
355
333
|
if (dataValue.value) {
|
|
356
334
|
log(" type : ", colorize(DataType[dataValue.value.dataType]));
|
|
357
335
|
log(" value: ", colorize(dataValue.value.value));
|
|
@@ -364,8 +342,7 @@ function dump_dataValues(nodesToRead, dataValues) {
|
|
|
364
342
|
}
|
|
365
343
|
|
|
366
344
|
function dump_historyDataValues(nodeToRead, startDate, endDate, historyReadResult) {
|
|
367
|
-
|
|
368
|
-
log(" Node : ", chalk.cyan.bold((nodeToRead.nodeId.toString())), nodeToRead.attributeId.toString());
|
|
345
|
+
log(" Node : ", chalk.cyan.bold(nodeToRead.nodeId.toString()), nodeToRead.attributeId.toString());
|
|
369
346
|
log(" startDate : ", startDate);
|
|
370
347
|
log(" endDate : ", endDate);
|
|
371
348
|
if (historyReadResult.statusCode !== opcua.StatusCodes.Good) {
|
|
@@ -392,7 +369,8 @@ function dump_historyDataValues(nodeToRead, startDate, endDate, historyReadResul
|
|
|
392
369
|
dataValue.sourceTimestamp,
|
|
393
370
|
w(dataValue.sourcePicoseconds, 4),
|
|
394
371
|
colorize(w(dataValue.value.value, 15)),
|
|
395
|
-
w(dataValue.statusCode.toString(16), 16)
|
|
372
|
+
w(dataValue.statusCode.toString(16), 16)
|
|
373
|
+
);
|
|
396
374
|
} else {
|
|
397
375
|
log(" value: <null>", dataValue.toString());
|
|
398
376
|
}
|
|
@@ -400,20 +378,15 @@ function dump_historyDataValues(nodeToRead, startDate, endDate, historyReadResul
|
|
|
400
378
|
}
|
|
401
379
|
|
|
402
380
|
function open_session(callback) {
|
|
403
|
-
|
|
404
|
-
|
|
405
381
|
if (the_session !== null) {
|
|
406
382
|
log(" a session exists already ! use closeSession First");
|
|
407
383
|
return callback();
|
|
408
|
-
|
|
409
384
|
} else {
|
|
410
|
-
|
|
411
385
|
client.requestedSessionTimeout = sessionTimeout;
|
|
412
|
-
client.createSession(function(err, session) {
|
|
386
|
+
client.createSession(function (err, session) {
|
|
413
387
|
if (err) {
|
|
414
388
|
log(chalk.red("Error : "), err);
|
|
415
389
|
} else {
|
|
416
|
-
|
|
417
390
|
the_session = session;
|
|
418
391
|
log("session created ", session.sessionId.toString());
|
|
419
392
|
proxyManager = new UAProxyManager(the_session);
|
|
@@ -424,11 +397,10 @@ function open_session(callback) {
|
|
|
424
397
|
assert(!crawler);
|
|
425
398
|
|
|
426
399
|
rl.prompt(the_prompt);
|
|
427
|
-
|
|
428
400
|
}
|
|
429
401
|
callback();
|
|
430
402
|
});
|
|
431
|
-
client.on("close", function() {
|
|
403
|
+
client.on("close", function () {
|
|
432
404
|
log(chalk.red(" Server has disconnected "));
|
|
433
405
|
the_session = null;
|
|
434
406
|
crawler = null;
|
|
@@ -437,8 +409,8 @@ function open_session(callback) {
|
|
|
437
409
|
}
|
|
438
410
|
|
|
439
411
|
function close_session(outer_callback) {
|
|
440
|
-
apply_on_valid_session("closeSession", function(session, inner_callback) {
|
|
441
|
-
session.close(function(err) {
|
|
412
|
+
apply_on_valid_session("closeSession", function (session, inner_callback) {
|
|
413
|
+
session.close(function (err) {
|
|
442
414
|
the_session = null;
|
|
443
415
|
crawler = null;
|
|
444
416
|
if (!outer_callback) {
|
|
@@ -474,7 +446,7 @@ function process_line(line) {
|
|
|
474
446
|
}
|
|
475
447
|
switch (cmd) {
|
|
476
448
|
case "debug":
|
|
477
|
-
const flag =
|
|
449
|
+
const flag = !args[1] ? true : ["ON", "TRUE", "1"].indexOf(args[1].toUpperCase()) >= 0;
|
|
478
450
|
set_debug(flag);
|
|
479
451
|
break;
|
|
480
452
|
case "open":
|
|
@@ -489,10 +461,8 @@ function process_line(line) {
|
|
|
489
461
|
log(" hostname : ", chalk.yellow(hostname || "<null>"));
|
|
490
462
|
log(" port : ", chalk.yellow(port.toString()));
|
|
491
463
|
|
|
492
|
-
apply_command(cmd, function(callback) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
client.connect(endpointUrl, function(err) {
|
|
464
|
+
apply_command(cmd, function (callback) {
|
|
465
|
+
client.connect(endpointUrl, function (err) {
|
|
496
466
|
if (err) {
|
|
497
467
|
log("client connected err=", err);
|
|
498
468
|
} else {
|
|
@@ -500,8 +470,7 @@ function process_line(line) {
|
|
|
500
470
|
|
|
501
471
|
add_endpoint_to_history(endpointUrl);
|
|
502
472
|
|
|
503
|
-
save_history(function() {
|
|
504
|
-
});
|
|
473
|
+
save_history(function () {});
|
|
505
474
|
}
|
|
506
475
|
callback(err);
|
|
507
476
|
});
|
|
@@ -510,8 +479,8 @@ function process_line(line) {
|
|
|
510
479
|
|
|
511
480
|
case "fs":
|
|
512
481
|
case "FindServers":
|
|
513
|
-
apply_command(cmd, function(callback) {
|
|
514
|
-
client.findServers({}, function(err, data) {
|
|
482
|
+
apply_command(cmd, function (callback) {
|
|
483
|
+
client.findServers({}, function (err, data) {
|
|
515
484
|
const { servers, endpoints } = data;
|
|
516
485
|
if (err) {
|
|
517
486
|
log(err.message);
|
|
@@ -523,8 +492,8 @@ function process_line(line) {
|
|
|
523
492
|
break;
|
|
524
493
|
case "gep":
|
|
525
494
|
case "getEndpoints":
|
|
526
|
-
apply_command(cmd, function(callback) {
|
|
527
|
-
client.getEndpoints(function(err, endpoints) {
|
|
495
|
+
apply_command(cmd, function (callback) {
|
|
496
|
+
client.getEndpoints(function (err, endpoints) {
|
|
528
497
|
if (err) {
|
|
529
498
|
log(err.message);
|
|
530
499
|
}
|
|
@@ -541,19 +510,19 @@ function process_line(line) {
|
|
|
541
510
|
break;
|
|
542
511
|
|
|
543
512
|
case "closeSession":
|
|
544
|
-
close_session(function() {
|
|
513
|
+
close_session(function () {});
|
|
545
514
|
break;
|
|
546
515
|
|
|
547
516
|
case "disconnect":
|
|
548
517
|
if (the_session) {
|
|
549
|
-
close_session(function(callback) {
|
|
550
|
-
client.disconnect(function() {
|
|
518
|
+
close_session(function (callback) {
|
|
519
|
+
client.disconnect(function () {
|
|
551
520
|
rl.write("client disconnected");
|
|
552
521
|
callback();
|
|
553
522
|
});
|
|
554
523
|
});
|
|
555
524
|
} else {
|
|
556
|
-
client.disconnect(function() {
|
|
525
|
+
client.disconnect(function () {
|
|
557
526
|
rl.write("client disconnected");
|
|
558
527
|
});
|
|
559
528
|
}
|
|
@@ -561,19 +530,15 @@ function process_line(line) {
|
|
|
561
530
|
|
|
562
531
|
case "b":
|
|
563
532
|
case "browse":
|
|
564
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
565
|
-
|
|
533
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
566
534
|
nodes = [args[1]];
|
|
567
535
|
|
|
568
|
-
the_session.browse(nodes, function(err, nodeResults) {
|
|
569
|
-
|
|
536
|
+
the_session.browse(nodes, function (err, nodeResults) {
|
|
570
537
|
if (err) {
|
|
571
538
|
log(err);
|
|
572
539
|
log(nodeResults);
|
|
573
540
|
} else {
|
|
574
|
-
|
|
575
|
-
save_history(function() {
|
|
576
|
-
});
|
|
541
|
+
save_history(function () {});
|
|
577
542
|
|
|
578
543
|
for (let i = 0; i < nodeResults.length; i++) {
|
|
579
544
|
log("Node: ", nodes[i]);
|
|
@@ -583,70 +548,74 @@ function process_line(line) {
|
|
|
583
548
|
}
|
|
584
549
|
callback();
|
|
585
550
|
});
|
|
586
|
-
|
|
587
551
|
});
|
|
588
552
|
|
|
589
553
|
break;
|
|
590
554
|
|
|
591
555
|
case "rootFolder":
|
|
592
|
-
|
|
593
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
594
|
-
|
|
556
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
595
557
|
get_root_folder(callback);
|
|
596
558
|
});
|
|
597
559
|
break;
|
|
598
560
|
|
|
599
561
|
case "hr":
|
|
600
562
|
case "readHistoryValue":
|
|
601
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
602
|
-
|
|
563
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
603
564
|
// example:
|
|
604
565
|
// hr ns=2;s=Demo.History.DoubleWithHistory 13:45 13:59
|
|
605
566
|
nodes = [args[1]];
|
|
606
567
|
|
|
607
|
-
let startTime = toDate(args[2])
|
|
608
|
-
let endTime = toDate(args[3]);
|
|
568
|
+
let startTime = toDate(args[2]); // "2015-06-10T09:00:00.000Z"
|
|
569
|
+
let endTime = toDate(args[3]); // "2015-06-10T09:01:00.000Z"
|
|
609
570
|
if (startTime > endTime) {
|
|
610
|
-
const tmp = endTime;
|
|
571
|
+
const tmp = endTime;
|
|
572
|
+
endTime = startTime;
|
|
573
|
+
startTime = tmp;
|
|
611
574
|
}
|
|
612
575
|
nodes = nodes.map(opcua.coerceNodeId);
|
|
613
576
|
|
|
614
|
-
the_session.readHistoryValue(nodes, startTime, endTime, function(err, historyReadResults) {
|
|
577
|
+
the_session.readHistoryValue(nodes, startTime, endTime, function (err, historyReadResults) {
|
|
615
578
|
if (err) {
|
|
616
579
|
log(err);
|
|
617
580
|
log(historyReadResults.toString());
|
|
618
581
|
} else {
|
|
619
|
-
save_history(function() {
|
|
582
|
+
save_history(function () {});
|
|
620
583
|
assert(historyReadResults.length === 1);
|
|
621
|
-
dump_historyDataValues(
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
584
|
+
dump_historyDataValues(
|
|
585
|
+
{
|
|
586
|
+
nodeId: nodes[0],
|
|
587
|
+
attributeId: 13
|
|
588
|
+
},
|
|
589
|
+
startTime,
|
|
590
|
+
endTime,
|
|
591
|
+
historyReadResults[0]
|
|
592
|
+
);
|
|
625
593
|
}
|
|
626
594
|
callback();
|
|
627
|
-
|
|
628
595
|
});
|
|
629
|
-
|
|
630
596
|
});
|
|
631
597
|
break;
|
|
632
598
|
case "r":
|
|
633
599
|
case "read":
|
|
634
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
635
|
-
|
|
600
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
636
601
|
nodes = [args[1]];
|
|
637
602
|
nodes = nodes.map(opcua.coerceNodeId);
|
|
638
603
|
|
|
639
|
-
the_session.readVariableValue(nodes, function(err, dataValues) {
|
|
604
|
+
the_session.readVariableValue(nodes, function (err, dataValues) {
|
|
640
605
|
if (err) {
|
|
641
606
|
log(err);
|
|
642
607
|
log(dataValues);
|
|
643
608
|
} else {
|
|
644
|
-
save_history(function() {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
609
|
+
save_history(function () {});
|
|
610
|
+
dump_dataValues(
|
|
611
|
+
[
|
|
612
|
+
{
|
|
613
|
+
nodeId: nodes[0],
|
|
614
|
+
attributeId: 13
|
|
615
|
+
}
|
|
616
|
+
],
|
|
617
|
+
dataValues
|
|
618
|
+
);
|
|
650
619
|
}
|
|
651
620
|
callback();
|
|
652
621
|
});
|
|
@@ -654,13 +623,12 @@ function process_line(line) {
|
|
|
654
623
|
break;
|
|
655
624
|
case "ra":
|
|
656
625
|
case "readall":
|
|
657
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
626
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
658
627
|
const node = args[1];
|
|
659
628
|
|
|
660
|
-
the_session.readAllAttributes(node, function(err, result/*,diagnosticInfos*/) {
|
|
629
|
+
the_session.readAllAttributes(node, function (err, result /*,diagnosticInfos*/) {
|
|
661
630
|
if (!err) {
|
|
662
|
-
save_history(function() {
|
|
663
|
-
});
|
|
631
|
+
save_history(function () {});
|
|
664
632
|
console.log(result);
|
|
665
633
|
//xx dump_dataValues(nodesToRead, dataValues);
|
|
666
634
|
}
|
|
@@ -670,10 +638,9 @@ function process_line(line) {
|
|
|
670
638
|
break;
|
|
671
639
|
|
|
672
640
|
case "tb":
|
|
673
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
674
|
-
|
|
641
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
675
642
|
const path = args[1];
|
|
676
|
-
the_session.translateBrowsePath(path, function(err, results) {
|
|
643
|
+
the_session.translateBrowsePath(path, function (err, results) {
|
|
677
644
|
if (err) {
|
|
678
645
|
log(err.message);
|
|
679
646
|
}
|
|
@@ -686,24 +653,22 @@ function process_line(line) {
|
|
|
686
653
|
break;
|
|
687
654
|
case "crawl":
|
|
688
655
|
{
|
|
689
|
-
apply_on_valid_session(cmd, function(the_session, callback) {
|
|
690
|
-
|
|
656
|
+
apply_on_valid_session(cmd, function (the_session, callback) {
|
|
691
657
|
if (!crawler) {
|
|
692
658
|
crawler = new opcua.NodeCrawler(the_session);
|
|
693
|
-
crawler.on("browsed", function(element) {
|
|
659
|
+
crawler.on("browsed", function (element) {
|
|
694
660
|
// log("->",element.browseName.name,element.nodeId.toString());
|
|
695
661
|
});
|
|
696
|
-
|
|
697
662
|
}
|
|
698
663
|
|
|
699
664
|
const nodeId = args[1] || "ObjectsFolder";
|
|
700
665
|
log("now crawling " + chalk.yellow(nodeId) + " ...please wait...");
|
|
701
|
-
crawler.read(nodeId, function(err, obj) {
|
|
666
|
+
crawler.read(nodeId, function (err, obj) {
|
|
702
667
|
if (!err) {
|
|
703
668
|
log(" crawling done ");
|
|
704
669
|
// todo : treeify.asTree performance is *very* slow on large object, replace with better implementation
|
|
705
670
|
//xx log(treeify.asTree(obj, true));
|
|
706
|
-
treeify.asLines(obj, true, true, function(line) {
|
|
671
|
+
treeify.asLines(obj, true, true, function (line) {
|
|
707
672
|
log(line);
|
|
708
673
|
});
|
|
709
674
|
} else {
|
|
@@ -717,7 +682,6 @@ function process_line(line) {
|
|
|
717
682
|
break;
|
|
718
683
|
|
|
719
684
|
case ".info":
|
|
720
|
-
|
|
721
685
|
log(" bytesRead ", client.bytesRead, " bytes");
|
|
722
686
|
log(" bytesWritten ", client.bytesWritten, " bytes");
|
|
723
687
|
log("transactionsPerformed ", client.transactionsPerformed, "");
|
|
@@ -738,13 +702,11 @@ function process_line(line) {
|
|
|
738
702
|
}
|
|
739
703
|
}
|
|
740
704
|
|
|
741
|
-
rl.on("line", function(line) {
|
|
742
|
-
|
|
705
|
+
rl.on("line", function (line) {
|
|
743
706
|
try {
|
|
744
707
|
process_line(line);
|
|
745
708
|
rl.prompt();
|
|
746
|
-
}
|
|
747
|
-
catch (err) {
|
|
709
|
+
} catch (err) {
|
|
748
710
|
log(chalk.red("------------------------------------------------"));
|
|
749
711
|
log(chalk.bgRed.yellow.bold(err.message));
|
|
750
712
|
log(err.stack);
|
|
@@ -752,7 +714,3 @@ rl.on("line", function(line) {
|
|
|
752
714
|
rl.resume();
|
|
753
715
|
}
|
|
754
716
|
});
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|