node-opcua-client-proxy 2.97.0 → 2.98.1
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/dist/common.d.ts +3 -3
- package/dist/common.js +4 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/dist/object_explorer.d.ts +20 -20
- package/dist/object_explorer.js +461 -461
- package/dist/proxy.d.ts +2 -2
- package/dist/proxy.js +18 -18
- package/dist/proxy_base_node.d.ts +83 -83
- package/dist/proxy_base_node.js +87 -87
- package/dist/proxy_manager.d.ts +50 -50
- package/dist/proxy_manager.js +261 -261
- package/dist/proxy_object.d.ts +6 -6
- package/dist/proxy_object.js +14 -14
- package/dist/proxy_state.d.ts +14 -14
- package/dist/proxy_state.js +27 -27
- package/dist/proxy_state_machine.d.ts +12 -12
- package/dist/proxy_state_machine.js +21 -21
- package/dist/proxy_transition.d.ts +24 -24
- package/dist/proxy_transition.js +29 -29
- package/dist/proxy_variable.d.ts +7 -7
- package/dist/proxy_variable.js +14 -14
- package/dist/state_machine_proxy.d.ts +8 -8
- package/dist/state_machine_proxy.js +43 -43
- package/package.json +22 -18
package/dist/object_explorer.js
CHANGED
|
@@ -1,462 +1,462 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readUAStructure = exports.ObjectExplorer = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @module node-opcua-client-proxy
|
|
6
|
-
*/
|
|
7
|
-
const async = require("async");
|
|
8
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
-
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
10
|
-
const node_opcua_service_call_1 = require("node-opcua-service-call");
|
|
11
|
-
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
12
|
-
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
13
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
14
|
-
const proxy_1 = require("./proxy");
|
|
15
|
-
const proxy_variable_1 = require("./proxy_variable");
|
|
16
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
17
|
-
const doDebug = false;
|
|
18
|
-
const errorLog = (0, node_opcua_debug_1.make_errorLog)("Proxy");
|
|
19
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)("Proxy");
|
|
20
|
-
const resultMask = (0, node_opcua_data_model_1.makeResultMask)("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition");
|
|
21
|
-
/**
|
|
22
|
-
* @method convertNodeIdToDataTypeAsync
|
|
23
|
-
*
|
|
24
|
-
* @param session
|
|
25
|
-
* @param dataTypeId
|
|
26
|
-
* @param callback
|
|
27
|
-
* @param callback.err
|
|
28
|
-
* @param callback.dataType
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
*
|
|
32
|
-
* const dataTypeId ="ns=0;i=11"; // Double
|
|
33
|
-
* convertNodeIdToDataTypeAsync(session,dataTypeId,function(err,dataType) {
|
|
34
|
-
* assert(!err && dataType === DataType.Double);
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* const dataTypeId ="ns=0;i=290"; // Duration => SubTypeOf Double
|
|
38
|
-
* convertNodeIdToDataTypeAsync(session,dataTypeId,function(err,dataType) {
|
|
39
|
-
* assert(!err && dataType === DataType.Double);
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* see also AddressSpace#findCorrespondingBasicDataType
|
|
43
|
-
*
|
|
44
|
-
* for an enumeration dataType will be DataType.Int32
|
|
45
|
-
*/
|
|
46
|
-
function convertNodeIdToDataTypeAsync(session, dataTypeId, callback) {
|
|
47
|
-
const nodeToRead = {
|
|
48
|
-
attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
|
|
49
|
-
nodeId: dataTypeId
|
|
50
|
-
};
|
|
51
|
-
session.read(nodeToRead, (err, dataValue) => {
|
|
52
|
-
// istanbul ignore next
|
|
53
|
-
if (err) {
|
|
54
|
-
setImmediate(() => {
|
|
55
|
-
callback(err);
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
dataValue = dataValue;
|
|
60
|
-
let dataType;
|
|
61
|
-
// istanbul ignore next
|
|
62
|
-
if (dataValue.statusCode.isNotGood()) {
|
|
63
|
-
dataType = node_opcua_variant_1.DataType.Null;
|
|
64
|
-
setImmediate(() => {
|
|
65
|
-
callback(null, dataType);
|
|
66
|
-
});
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const dataTypeName = dataValue.value.value;
|
|
70
|
-
if (dataTypeId.namespace === 0 && dataTypeId.value === node_opcua_constants_1.DataTypeIds.Enumeration) {
|
|
71
|
-
dataType = node_opcua_variant_1.DataType.Int32;
|
|
72
|
-
setImmediate(() => {
|
|
73
|
-
callback(null, dataType);
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (dataTypeId.namespace === 0 && node_opcua_variant_1.DataType[dataTypeId.value]) {
|
|
78
|
-
dataType = node_opcua_variant_1.DataType[dataTypeId.value];
|
|
79
|
-
setImmediate(() => {
|
|
80
|
-
callback(null, dataType);
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
/// example => Duration (i=290) => Double (i=11)
|
|
85
|
-
// read subTypeOf
|
|
86
|
-
const nodeToBrowse = {
|
|
87
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
|
|
88
|
-
includeSubtypes: false,
|
|
89
|
-
nodeId: dataTypeId,
|
|
90
|
-
// BrowseDescription
|
|
91
|
-
referenceTypeId: (0, proxy_1.makeRefId)("HasSubtype"),
|
|
92
|
-
// xx nodeClassMask: makeNodeClassMask("ObjectType"),
|
|
93
|
-
resultMask
|
|
94
|
-
};
|
|
95
|
-
// tslint:disable:no-shadowed-variable
|
|
96
|
-
session.browse(nodeToBrowse, (err, browseResult) => {
|
|
97
|
-
// istanbul ignore next
|
|
98
|
-
if (err) {
|
|
99
|
-
return callback(err);
|
|
100
|
-
}
|
|
101
|
-
const references = browseResult.references;
|
|
102
|
-
if (!references || references.length !== 1) {
|
|
103
|
-
return callback(new Error("cannot find SuperType of " + dataTypeName.toString()));
|
|
104
|
-
}
|
|
105
|
-
const nodeId = references[0].nodeId;
|
|
106
|
-
return convertNodeIdToDataTypeAsync(session, nodeId, callback);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
function convertToVariant(value, arg, propName) {
|
|
111
|
-
const dataType = arg._basicDataType || node_opcua_variant_1.DataType.Null;
|
|
112
|
-
const arrayType = arg.valueRank === 1 ? node_opcua_variant_1.VariantArrayType.Array : arg.valueRank === -1 ? node_opcua_variant_1.VariantArrayType.Scalar : node_opcua_variant_1.VariantArrayType.Matrix;
|
|
113
|
-
if (value === undefined) {
|
|
114
|
-
throw new Error("expecting input argument ");
|
|
115
|
-
}
|
|
116
|
-
if (arrayType === node_opcua_variant_1.VariantArrayType.Array) {
|
|
117
|
-
if (!Array.isArray(value)) {
|
|
118
|
-
throw new Error("expecting value to be an Array or a TypedArray");
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return new node_opcua_variant_1.Variant({ arrayType, dataType, value });
|
|
122
|
-
}
|
|
123
|
-
function convertToVariantArray(inputArgsDef, inputArgs) {
|
|
124
|
-
const inputArguments = inputArgsDef.map((arg) => {
|
|
125
|
-
const propName = (0, node_opcua_utils_1.lowerFirstLetter)(arg.name || "");
|
|
126
|
-
const value = inputArgs[propName];
|
|
127
|
-
return convertToVariant(value, arg, propName);
|
|
128
|
-
});
|
|
129
|
-
return inputArguments;
|
|
130
|
-
}
|
|
131
|
-
const thenify = require("thenify");
|
|
132
|
-
function makeFunction(obj, methodName) {
|
|
133
|
-
return thenify.withCallback(function functionCaller(inputArgs, callback) {
|
|
134
|
-
const session = this.proxyManager.session;
|
|
135
|
-
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
136
|
-
const methodDef = this.$methods[methodName];
|
|
137
|
-
// convert input arguments into Variants
|
|
138
|
-
const inputArgsDef = methodDef.inputArguments || [];
|
|
139
|
-
const inputArguments = convertToVariantArray(inputArgsDef, inputArgs);
|
|
140
|
-
const methodToCall = new node_opcua_service_call_1.CallMethodRequest({
|
|
141
|
-
inputArguments,
|
|
142
|
-
methodId: methodDef.nodeId,
|
|
143
|
-
objectId: obj.nodeId
|
|
144
|
-
});
|
|
145
|
-
session.call(methodToCall, (err, callResult) => {
|
|
146
|
-
// istanbul ignore next
|
|
147
|
-
if (err) {
|
|
148
|
-
return callback(err);
|
|
149
|
-
}
|
|
150
|
-
callResult = callResult;
|
|
151
|
-
if (callResult.statusCode.isNotGood()) {
|
|
152
|
-
return callback(new Error("Error " + callResult.statusCode.toString()));
|
|
153
|
-
}
|
|
154
|
-
callResult.outputArguments = callResult.outputArguments || [];
|
|
155
|
-
if (callResult.outputArguments.length !== methodDef.outputArguments.length) {
|
|
156
|
-
return callback(new Error("Internal error callResult.outputArguments.length " +
|
|
157
|
-
callResult.outputArguments.length +
|
|
158
|
-
" " +
|
|
159
|
-
obj[methodName].outputArguments.length));
|
|
160
|
-
}
|
|
161
|
-
const output = {};
|
|
162
|
-
methodDef.outputArguments.map((arg, index) => {
|
|
163
|
-
const variant = callResult.outputArguments[index];
|
|
164
|
-
const propName = (0, node_opcua_utils_1.lowerFirstLetter)(arg.name);
|
|
165
|
-
output[propName] = variant.value;
|
|
166
|
-
});
|
|
167
|
-
callback(err, output);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
function extractDataType(session, arg, callback) {
|
|
172
|
-
if (arg.dataType && arg._basicDataType) {
|
|
173
|
-
setImmediate(callback); // already converted
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
convertNodeIdToDataTypeAsync(session, arg.dataType, (err, dataType) => {
|
|
177
|
-
if (!err) {
|
|
178
|
-
arg._basicDataType = dataType;
|
|
179
|
-
}
|
|
180
|
-
callback(err || undefined);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* @method add_method
|
|
185
|
-
* @private
|
|
186
|
-
*/
|
|
187
|
-
function add_method(proxyManager, obj, reference, outerCallback) {
|
|
188
|
-
const session = proxyManager.session;
|
|
189
|
-
const methodName = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name);
|
|
190
|
-
let inputArguments = [];
|
|
191
|
-
let outputArguments = [];
|
|
192
|
-
// tslint:disable:no-shadowed-variable
|
|
193
|
-
async.series([
|
|
194
|
-
(callback) => {
|
|
195
|
-
session.getArgumentDefinition(reference.nodeId, (err, argumentDefinition) => {
|
|
196
|
-
// istanbul ignore next
|
|
197
|
-
if (err) {
|
|
198
|
-
errorLog("getArgumentDefinition failed ", err);
|
|
199
|
-
return callback(err);
|
|
200
|
-
}
|
|
201
|
-
// istanbul ignore next
|
|
202
|
-
if (!argumentDefinition) {
|
|
203
|
-
return callback(new Error("Internal Error"));
|
|
204
|
-
}
|
|
205
|
-
inputArguments = argumentDefinition.inputArguments || [];
|
|
206
|
-
outputArguments = argumentDefinition.outputArguments || [];
|
|
207
|
-
const _extractDataType = extractDataType.bind(null, session);
|
|
208
|
-
async.series([
|
|
209
|
-
(innerCallback) => async.eachSeries(inputArguments, _extractDataType, innerCallback),
|
|
210
|
-
(innerCallback) => async.eachSeries(outputArguments, _extractDataType, innerCallback)
|
|
211
|
-
], (err) => callback(err));
|
|
212
|
-
});
|
|
213
|
-
},
|
|
214
|
-
(callback) => {
|
|
215
|
-
const methodObj = {
|
|
216
|
-
browseName: methodName,
|
|
217
|
-
executableFlag: false,
|
|
218
|
-
func: makeFunction(obj, methodName),
|
|
219
|
-
nodeId: reference.nodeId,
|
|
220
|
-
inputArguments,
|
|
221
|
-
outputArguments
|
|
222
|
-
};
|
|
223
|
-
obj.$methods[methodName] = methodObj;
|
|
224
|
-
obj[methodName] = methodObj.func;
|
|
225
|
-
obj[methodName].inputArguments = inputArguments;
|
|
226
|
-
obj[methodName].outputArguments = outputArguments;
|
|
227
|
-
doDebug && debugLog("installing method name", methodName);
|
|
228
|
-
proxyManager._monitor_execution_flag(methodObj, () => {
|
|
229
|
-
callback();
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
], (err) => {
|
|
233
|
-
if (err) {
|
|
234
|
-
errorLog("Error =>", err);
|
|
235
|
-
}
|
|
236
|
-
outerCallback(err);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
function add_component(proxyManager, obj, reference, callback) {
|
|
240
|
-
const session = proxyManager.session;
|
|
241
|
-
const name = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name || "");
|
|
242
|
-
proxyManager.getObject(reference.nodeId, (err, childObj) => {
|
|
243
|
-
// istanbul ignore else
|
|
244
|
-
if (!err) {
|
|
245
|
-
childObj = new ObjectExplorer({
|
|
246
|
-
name,
|
|
247
|
-
nodeId: reference.nodeId,
|
|
248
|
-
parent: obj,
|
|
249
|
-
proxyManager
|
|
250
|
-
});
|
|
251
|
-
obj[name] = childObj;
|
|
252
|
-
obj.$components.push(childObj);
|
|
253
|
-
childObj.$resolve(callback);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
callback(err);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
function addFolderElement(proxyManager, obj, reference, callback) {
|
|
261
|
-
const session = proxyManager.session;
|
|
262
|
-
const name = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name || "");
|
|
263
|
-
const childObj = new ObjectExplorer({
|
|
264
|
-
name,
|
|
265
|
-
nodeId: reference.nodeId,
|
|
266
|
-
parent: obj,
|
|
267
|
-
proxyManager
|
|
268
|
-
});
|
|
269
|
-
obj[name] = childObj;
|
|
270
|
-
obj.$organizes.push(childObj);
|
|
271
|
-
childObj.$resolve(callback);
|
|
272
|
-
}
|
|
273
|
-
function add_property(proxyManager, obj, reference, callback) {
|
|
274
|
-
const session = proxyManager.session;
|
|
275
|
-
const name = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name || "");
|
|
276
|
-
obj[name] = new proxy_variable_1.ProxyVariable(proxyManager, reference.nodeId, reference);
|
|
277
|
-
obj.$properties[name] = obj[name];
|
|
278
|
-
setImmediate(callback);
|
|
279
|
-
}
|
|
280
|
-
function add_typeDefinition(proxyManager, obj, references, callback) {
|
|
281
|
-
const session = proxyManager.session;
|
|
282
|
-
references = references || [];
|
|
283
|
-
if (references.length !== 1) {
|
|
284
|
-
setImmediate(callback);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const reference = references[0];
|
|
288
|
-
(0, node_opcua_assert_1.assert)(!obj.typeDefinition, "type definition can only be set once");
|
|
289
|
-
obj.typeDefinition = reference.browseName.name || "";
|
|
290
|
-
setImmediate(callback);
|
|
291
|
-
}
|
|
292
|
-
function addFromState(proxyManager, obj, reference, callback) {
|
|
293
|
-
proxyManager.getObject(reference.nodeId, (err, childObj) => {
|
|
294
|
-
if (err) {
|
|
295
|
-
callback(err);
|
|
296
|
-
}
|
|
297
|
-
obj.$fromState = childObj;
|
|
298
|
-
callback();
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
function addToState(proxyManager, obj, reference, callback) {
|
|
302
|
-
proxyManager.getObject(reference.nodeId, (err, childObj) => {
|
|
303
|
-
if (err) {
|
|
304
|
-
callback(err);
|
|
305
|
-
}
|
|
306
|
-
obj.$toState = childObj;
|
|
307
|
-
callback();
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
class ObjectExplorer {
|
|
311
|
-
constructor(options) {
|
|
312
|
-
this.proxyManager = options.proxyManager;
|
|
313
|
-
this.name = options.name;
|
|
314
|
-
this.nodeId = options.nodeId;
|
|
315
|
-
this.parent = options.parent;
|
|
316
|
-
}
|
|
317
|
-
$resolve(callback) {
|
|
318
|
-
this.proxyManager.getObject(this.nodeId, (err, childObj) => {
|
|
319
|
-
// istanbul ignore next
|
|
320
|
-
if (err) {
|
|
321
|
-
return callback(err);
|
|
322
|
-
}
|
|
323
|
-
this.parent[this.name] = childObj;
|
|
324
|
-
this.parent.$components.push(childObj);
|
|
325
|
-
callback();
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
exports.ObjectExplorer = ObjectExplorer;
|
|
330
|
-
function t(references) {
|
|
331
|
-
if (!references)
|
|
332
|
-
return "";
|
|
333
|
-
return references.map((r) => r.browseName.name + " " + r.nodeId.toString());
|
|
334
|
-
}
|
|
335
|
-
function readUAStructure(proxyManager, obj, callback) {
|
|
336
|
-
const session = proxyManager.session;
|
|
337
|
-
// 0 Object
|
|
338
|
-
// 1 Variable
|
|
339
|
-
// 2 Method
|
|
340
|
-
const nodeId = obj.nodeId;
|
|
341
|
-
const nodesToBrowse = [
|
|
342
|
-
// Components (except Methods)
|
|
343
|
-
{
|
|
344
|
-
// BrowseDescription
|
|
345
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
346
|
-
includeSubtypes: true,
|
|
347
|
-
nodeClassMask: (0, node_opcua_data_model_1.makeNodeClassMask)("Object | Variable"),
|
|
348
|
-
nodeId,
|
|
349
|
-
referenceTypeId: (0, proxy_1.makeRefId)("HasComponent"),
|
|
350
|
-
resultMask
|
|
351
|
-
},
|
|
352
|
-
// Properties
|
|
353
|
-
{
|
|
354
|
-
// BrowseDescription
|
|
355
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
356
|
-
includeSubtypes: true,
|
|
357
|
-
// nodeClassMask: makeNodeClassMask("Variable"),
|
|
358
|
-
nodeId,
|
|
359
|
-
referenceTypeId: (0, proxy_1.makeRefId)("HasProperty"),
|
|
360
|
-
resultMask
|
|
361
|
-
},
|
|
362
|
-
// Methods
|
|
363
|
-
{
|
|
364
|
-
// BrowseDescription
|
|
365
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
366
|
-
includeSubtypes: true,
|
|
367
|
-
nodeClassMask: (0, node_opcua_data_model_1.makeNodeClassMask)("Method"),
|
|
368
|
-
nodeId,
|
|
369
|
-
referenceTypeId: (0, proxy_1.makeRefId)("HasComponent"),
|
|
370
|
-
resultMask
|
|
371
|
-
},
|
|
372
|
-
// TypeDefinition
|
|
373
|
-
{
|
|
374
|
-
// BrowseDescription
|
|
375
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Both,
|
|
376
|
-
includeSubtypes: true,
|
|
377
|
-
nodeId,
|
|
378
|
-
referenceTypeId: (0, proxy_1.makeRefId)("HasTypeDefinition"),
|
|
379
|
-
resultMask
|
|
380
|
-
},
|
|
381
|
-
// FromState
|
|
382
|
-
{
|
|
383
|
-
// BrowseDescription
|
|
384
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
385
|
-
includeSubtypes: true,
|
|
386
|
-
nodeId,
|
|
387
|
-
referenceTypeId: (0, proxy_1.makeRefId)("FromState"),
|
|
388
|
-
resultMask
|
|
389
|
-
},
|
|
390
|
-
// ToState
|
|
391
|
-
{
|
|
392
|
-
// BrowseDescription
|
|
393
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
394
|
-
includeSubtypes: true,
|
|
395
|
-
nodeId,
|
|
396
|
-
referenceTypeId: (0, proxy_1.makeRefId)("ToState"),
|
|
397
|
-
resultMask
|
|
398
|
-
},
|
|
399
|
-
// (for folders ) Organizes
|
|
400
|
-
{
|
|
401
|
-
// BrowseDescription
|
|
402
|
-
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
403
|
-
includeSubtypes: true,
|
|
404
|
-
nodeId,
|
|
405
|
-
referenceTypeId: (0, proxy_1.makeRefId)("Organizes"),
|
|
406
|
-
resultMask
|
|
407
|
-
}
|
|
408
|
-
];
|
|
409
|
-
session.browse(nodesToBrowse, (err, browseResults) => {
|
|
410
|
-
browseResults = browseResults || [];
|
|
411
|
-
// istanbul ignore next
|
|
412
|
-
if (err) {
|
|
413
|
-
return callback(err);
|
|
414
|
-
}
|
|
415
|
-
if (doDebug) {
|
|
416
|
-
debugLog("Components", t(browseResults[0].references));
|
|
417
|
-
debugLog("Properties", t(browseResults[1].references));
|
|
418
|
-
debugLog("Methods", t(browseResults[2].references));
|
|
419
|
-
}
|
|
420
|
-
async.series([
|
|
421
|
-
(callback) => {
|
|
422
|
-
async.mapSeries(browseResults[0].references, (reference, innerCallback) => add_component(proxyManager, obj, reference, innerCallback), (err) => callback(err));
|
|
423
|
-
},
|
|
424
|
-
(callback) => {
|
|
425
|
-
async.mapSeries(browseResults[1].references, (reference, innerCallback) => add_property(proxyManager, obj, reference, innerCallback), (err) => callback(err));
|
|
426
|
-
},
|
|
427
|
-
// now enrich our object with nice callable async methods
|
|
428
|
-
(callback) => {
|
|
429
|
-
async.mapSeries(browseResults[2].references, (reference, innerCallback) => add_method(proxyManager, obj, reference, innerCallback), (err) => callback(err));
|
|
430
|
-
},
|
|
431
|
-
// now set typeDefinition
|
|
432
|
-
(callback) => {
|
|
433
|
-
add_typeDefinition(proxyManager, obj, browseResults[3].references, callback);
|
|
434
|
-
},
|
|
435
|
-
// FromState
|
|
436
|
-
(callback) => {
|
|
437
|
-
// fromState
|
|
438
|
-
const reference = browseResults[4].references ? browseResults[4].references[0] : null;
|
|
439
|
-
// fromState
|
|
440
|
-
if (reference) {
|
|
441
|
-
return addFromState(proxyManager, obj, reference, callback);
|
|
442
|
-
}
|
|
443
|
-
callback();
|
|
444
|
-
},
|
|
445
|
-
// ToState
|
|
446
|
-
(callback) => {
|
|
447
|
-
const reference = browseResults[5].references ? browseResults[5].references[0] : null;
|
|
448
|
-
// fromState
|
|
449
|
-
if (reference) {
|
|
450
|
-
return addToState(proxyManager, obj, reference, callback);
|
|
451
|
-
}
|
|
452
|
-
callback();
|
|
453
|
-
},
|
|
454
|
-
// Organizes
|
|
455
|
-
(callback) => {
|
|
456
|
-
async.mapSeries(browseResults[6].references, (reference, callback) => addFolderElement(proxyManager, obj, reference, callback), (err) => callback(err));
|
|
457
|
-
}
|
|
458
|
-
], (err) => callback(err));
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
exports.readUAStructure = readUAStructure;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUAStructure = exports.ObjectExplorer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-client-proxy
|
|
6
|
+
*/
|
|
7
|
+
const async = require("async");
|
|
8
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
+
const node_opcua_data_model_1 = require("node-opcua-data-model");
|
|
10
|
+
const node_opcua_service_call_1 = require("node-opcua-service-call");
|
|
11
|
+
const node_opcua_utils_1 = require("node-opcua-utils");
|
|
12
|
+
const node_opcua_variant_1 = require("node-opcua-variant");
|
|
13
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
14
|
+
const proxy_1 = require("./proxy");
|
|
15
|
+
const proxy_variable_1 = require("./proxy_variable");
|
|
16
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
17
|
+
const doDebug = false;
|
|
18
|
+
const errorLog = (0, node_opcua_debug_1.make_errorLog)("Proxy");
|
|
19
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)("Proxy");
|
|
20
|
+
const resultMask = (0, node_opcua_data_model_1.makeResultMask)("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition");
|
|
21
|
+
/**
|
|
22
|
+
* @method convertNodeIdToDataTypeAsync
|
|
23
|
+
*
|
|
24
|
+
* @param session
|
|
25
|
+
* @param dataTypeId
|
|
26
|
+
* @param callback
|
|
27
|
+
* @param callback.err
|
|
28
|
+
* @param callback.dataType
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
*
|
|
32
|
+
* const dataTypeId ="ns=0;i=11"; // Double
|
|
33
|
+
* convertNodeIdToDataTypeAsync(session,dataTypeId,function(err,dataType) {
|
|
34
|
+
* assert(!err && dataType === DataType.Double);
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const dataTypeId ="ns=0;i=290"; // Duration => SubTypeOf Double
|
|
38
|
+
* convertNodeIdToDataTypeAsync(session,dataTypeId,function(err,dataType) {
|
|
39
|
+
* assert(!err && dataType === DataType.Double);
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* see also AddressSpace#findCorrespondingBasicDataType
|
|
43
|
+
*
|
|
44
|
+
* for an enumeration dataType will be DataType.Int32
|
|
45
|
+
*/
|
|
46
|
+
function convertNodeIdToDataTypeAsync(session, dataTypeId, callback) {
|
|
47
|
+
const nodeToRead = {
|
|
48
|
+
attributeId: node_opcua_data_model_1.AttributeIds.BrowseName,
|
|
49
|
+
nodeId: dataTypeId
|
|
50
|
+
};
|
|
51
|
+
session.read(nodeToRead, (err, dataValue) => {
|
|
52
|
+
// istanbul ignore next
|
|
53
|
+
if (err) {
|
|
54
|
+
setImmediate(() => {
|
|
55
|
+
callback(err);
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
dataValue = dataValue;
|
|
60
|
+
let dataType;
|
|
61
|
+
// istanbul ignore next
|
|
62
|
+
if (dataValue.statusCode.isNotGood()) {
|
|
63
|
+
dataType = node_opcua_variant_1.DataType.Null;
|
|
64
|
+
setImmediate(() => {
|
|
65
|
+
callback(null, dataType);
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const dataTypeName = dataValue.value.value;
|
|
70
|
+
if (dataTypeId.namespace === 0 && dataTypeId.value === node_opcua_constants_1.DataTypeIds.Enumeration) {
|
|
71
|
+
dataType = node_opcua_variant_1.DataType.Int32;
|
|
72
|
+
setImmediate(() => {
|
|
73
|
+
callback(null, dataType);
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (dataTypeId.namespace === 0 && node_opcua_variant_1.DataType[dataTypeId.value]) {
|
|
78
|
+
dataType = node_opcua_variant_1.DataType[dataTypeId.value];
|
|
79
|
+
setImmediate(() => {
|
|
80
|
+
callback(null, dataType);
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
/// example => Duration (i=290) => Double (i=11)
|
|
85
|
+
// read subTypeOf
|
|
86
|
+
const nodeToBrowse = {
|
|
87
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Inverse,
|
|
88
|
+
includeSubtypes: false,
|
|
89
|
+
nodeId: dataTypeId,
|
|
90
|
+
// BrowseDescription
|
|
91
|
+
referenceTypeId: (0, proxy_1.makeRefId)("HasSubtype"),
|
|
92
|
+
// xx nodeClassMask: makeNodeClassMask("ObjectType"),
|
|
93
|
+
resultMask
|
|
94
|
+
};
|
|
95
|
+
// tslint:disable:no-shadowed-variable
|
|
96
|
+
session.browse(nodeToBrowse, (err, browseResult) => {
|
|
97
|
+
// istanbul ignore next
|
|
98
|
+
if (err) {
|
|
99
|
+
return callback(err);
|
|
100
|
+
}
|
|
101
|
+
const references = browseResult.references;
|
|
102
|
+
if (!references || references.length !== 1) {
|
|
103
|
+
return callback(new Error("cannot find SuperType of " + dataTypeName.toString()));
|
|
104
|
+
}
|
|
105
|
+
const nodeId = references[0].nodeId;
|
|
106
|
+
return convertNodeIdToDataTypeAsync(session, nodeId, callback);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function convertToVariant(value, arg, propName) {
|
|
111
|
+
const dataType = arg._basicDataType || node_opcua_variant_1.DataType.Null;
|
|
112
|
+
const arrayType = arg.valueRank === 1 ? node_opcua_variant_1.VariantArrayType.Array : arg.valueRank === -1 ? node_opcua_variant_1.VariantArrayType.Scalar : node_opcua_variant_1.VariantArrayType.Matrix;
|
|
113
|
+
if (value === undefined) {
|
|
114
|
+
throw new Error("expecting input argument ");
|
|
115
|
+
}
|
|
116
|
+
if (arrayType === node_opcua_variant_1.VariantArrayType.Array) {
|
|
117
|
+
if (!Array.isArray(value)) {
|
|
118
|
+
throw new Error("expecting value to be an Array or a TypedArray");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return new node_opcua_variant_1.Variant({ arrayType, dataType, value });
|
|
122
|
+
}
|
|
123
|
+
function convertToVariantArray(inputArgsDef, inputArgs) {
|
|
124
|
+
const inputArguments = inputArgsDef.map((arg) => {
|
|
125
|
+
const propName = (0, node_opcua_utils_1.lowerFirstLetter)(arg.name || "");
|
|
126
|
+
const value = inputArgs[propName];
|
|
127
|
+
return convertToVariant(value, arg, propName);
|
|
128
|
+
});
|
|
129
|
+
return inputArguments;
|
|
130
|
+
}
|
|
131
|
+
const thenify = require("thenify");
|
|
132
|
+
function makeFunction(obj, methodName) {
|
|
133
|
+
return thenify.withCallback(function functionCaller(inputArgs, callback) {
|
|
134
|
+
const session = this.proxyManager.session;
|
|
135
|
+
(0, node_opcua_assert_1.assert)(typeof callback === "function");
|
|
136
|
+
const methodDef = this.$methods[methodName];
|
|
137
|
+
// convert input arguments into Variants
|
|
138
|
+
const inputArgsDef = methodDef.inputArguments || [];
|
|
139
|
+
const inputArguments = convertToVariantArray(inputArgsDef, inputArgs);
|
|
140
|
+
const methodToCall = new node_opcua_service_call_1.CallMethodRequest({
|
|
141
|
+
inputArguments,
|
|
142
|
+
methodId: methodDef.nodeId,
|
|
143
|
+
objectId: obj.nodeId
|
|
144
|
+
});
|
|
145
|
+
session.call(methodToCall, (err, callResult) => {
|
|
146
|
+
// istanbul ignore next
|
|
147
|
+
if (err) {
|
|
148
|
+
return callback(err);
|
|
149
|
+
}
|
|
150
|
+
callResult = callResult;
|
|
151
|
+
if (callResult.statusCode.isNotGood()) {
|
|
152
|
+
return callback(new Error("Error " + callResult.statusCode.toString()));
|
|
153
|
+
}
|
|
154
|
+
callResult.outputArguments = callResult.outputArguments || [];
|
|
155
|
+
if (callResult.outputArguments.length !== methodDef.outputArguments.length) {
|
|
156
|
+
return callback(new Error("Internal error callResult.outputArguments.length " +
|
|
157
|
+
callResult.outputArguments.length +
|
|
158
|
+
" " +
|
|
159
|
+
obj[methodName].outputArguments.length));
|
|
160
|
+
}
|
|
161
|
+
const output = {};
|
|
162
|
+
methodDef.outputArguments.map((arg, index) => {
|
|
163
|
+
const variant = callResult.outputArguments[index];
|
|
164
|
+
const propName = (0, node_opcua_utils_1.lowerFirstLetter)(arg.name);
|
|
165
|
+
output[propName] = variant.value;
|
|
166
|
+
});
|
|
167
|
+
callback(err, output);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function extractDataType(session, arg, callback) {
|
|
172
|
+
if (arg.dataType && arg._basicDataType) {
|
|
173
|
+
setImmediate(callback); // already converted
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
convertNodeIdToDataTypeAsync(session, arg.dataType, (err, dataType) => {
|
|
177
|
+
if (!err) {
|
|
178
|
+
arg._basicDataType = dataType;
|
|
179
|
+
}
|
|
180
|
+
callback(err || undefined);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* @method add_method
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
function add_method(proxyManager, obj, reference, outerCallback) {
|
|
188
|
+
const session = proxyManager.session;
|
|
189
|
+
const methodName = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name);
|
|
190
|
+
let inputArguments = [];
|
|
191
|
+
let outputArguments = [];
|
|
192
|
+
// tslint:disable:no-shadowed-variable
|
|
193
|
+
async.series([
|
|
194
|
+
(callback) => {
|
|
195
|
+
session.getArgumentDefinition(reference.nodeId, (err, argumentDefinition) => {
|
|
196
|
+
// istanbul ignore next
|
|
197
|
+
if (err) {
|
|
198
|
+
errorLog("getArgumentDefinition failed ", err);
|
|
199
|
+
return callback(err);
|
|
200
|
+
}
|
|
201
|
+
// istanbul ignore next
|
|
202
|
+
if (!argumentDefinition) {
|
|
203
|
+
return callback(new Error("Internal Error"));
|
|
204
|
+
}
|
|
205
|
+
inputArguments = argumentDefinition.inputArguments || [];
|
|
206
|
+
outputArguments = argumentDefinition.outputArguments || [];
|
|
207
|
+
const _extractDataType = extractDataType.bind(null, session);
|
|
208
|
+
async.series([
|
|
209
|
+
(innerCallback) => async.eachSeries(inputArguments, _extractDataType, innerCallback),
|
|
210
|
+
(innerCallback) => async.eachSeries(outputArguments, _extractDataType, innerCallback)
|
|
211
|
+
], (err) => callback(err));
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
(callback) => {
|
|
215
|
+
const methodObj = {
|
|
216
|
+
browseName: methodName,
|
|
217
|
+
executableFlag: false,
|
|
218
|
+
func: makeFunction(obj, methodName),
|
|
219
|
+
nodeId: reference.nodeId,
|
|
220
|
+
inputArguments,
|
|
221
|
+
outputArguments
|
|
222
|
+
};
|
|
223
|
+
obj.$methods[methodName] = methodObj;
|
|
224
|
+
obj[methodName] = methodObj.func;
|
|
225
|
+
obj[methodName].inputArguments = inputArguments;
|
|
226
|
+
obj[methodName].outputArguments = outputArguments;
|
|
227
|
+
doDebug && debugLog("installing method name", methodName);
|
|
228
|
+
proxyManager._monitor_execution_flag(methodObj, () => {
|
|
229
|
+
callback();
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
], (err) => {
|
|
233
|
+
if (err) {
|
|
234
|
+
errorLog("Error =>", err);
|
|
235
|
+
}
|
|
236
|
+
outerCallback(err);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function add_component(proxyManager, obj, reference, callback) {
|
|
240
|
+
const session = proxyManager.session;
|
|
241
|
+
const name = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name || "");
|
|
242
|
+
proxyManager.getObject(reference.nodeId, (err, childObj) => {
|
|
243
|
+
// istanbul ignore else
|
|
244
|
+
if (!err) {
|
|
245
|
+
childObj = new ObjectExplorer({
|
|
246
|
+
name,
|
|
247
|
+
nodeId: reference.nodeId,
|
|
248
|
+
parent: obj,
|
|
249
|
+
proxyManager
|
|
250
|
+
});
|
|
251
|
+
obj[name] = childObj;
|
|
252
|
+
obj.$components.push(childObj);
|
|
253
|
+
childObj.$resolve(callback);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
callback(err);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function addFolderElement(proxyManager, obj, reference, callback) {
|
|
261
|
+
const session = proxyManager.session;
|
|
262
|
+
const name = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name || "");
|
|
263
|
+
const childObj = new ObjectExplorer({
|
|
264
|
+
name,
|
|
265
|
+
nodeId: reference.nodeId,
|
|
266
|
+
parent: obj,
|
|
267
|
+
proxyManager
|
|
268
|
+
});
|
|
269
|
+
obj[name] = childObj;
|
|
270
|
+
obj.$organizes.push(childObj);
|
|
271
|
+
childObj.$resolve(callback);
|
|
272
|
+
}
|
|
273
|
+
function add_property(proxyManager, obj, reference, callback) {
|
|
274
|
+
const session = proxyManager.session;
|
|
275
|
+
const name = (0, node_opcua_utils_1.lowerFirstLetter)(reference.browseName.name || "");
|
|
276
|
+
obj[name] = new proxy_variable_1.ProxyVariable(proxyManager, reference.nodeId, reference);
|
|
277
|
+
obj.$properties[name] = obj[name];
|
|
278
|
+
setImmediate(callback);
|
|
279
|
+
}
|
|
280
|
+
function add_typeDefinition(proxyManager, obj, references, callback) {
|
|
281
|
+
const session = proxyManager.session;
|
|
282
|
+
references = references || [];
|
|
283
|
+
if (references.length !== 1) {
|
|
284
|
+
setImmediate(callback);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const reference = references[0];
|
|
288
|
+
(0, node_opcua_assert_1.assert)(!obj.typeDefinition, "type definition can only be set once");
|
|
289
|
+
obj.typeDefinition = reference.browseName.name || "";
|
|
290
|
+
setImmediate(callback);
|
|
291
|
+
}
|
|
292
|
+
function addFromState(proxyManager, obj, reference, callback) {
|
|
293
|
+
proxyManager.getObject(reference.nodeId, (err, childObj) => {
|
|
294
|
+
if (err) {
|
|
295
|
+
callback(err);
|
|
296
|
+
}
|
|
297
|
+
obj.$fromState = childObj;
|
|
298
|
+
callback();
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function addToState(proxyManager, obj, reference, callback) {
|
|
302
|
+
proxyManager.getObject(reference.nodeId, (err, childObj) => {
|
|
303
|
+
if (err) {
|
|
304
|
+
callback(err);
|
|
305
|
+
}
|
|
306
|
+
obj.$toState = childObj;
|
|
307
|
+
callback();
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
class ObjectExplorer {
|
|
311
|
+
constructor(options) {
|
|
312
|
+
this.proxyManager = options.proxyManager;
|
|
313
|
+
this.name = options.name;
|
|
314
|
+
this.nodeId = options.nodeId;
|
|
315
|
+
this.parent = options.parent;
|
|
316
|
+
}
|
|
317
|
+
$resolve(callback) {
|
|
318
|
+
this.proxyManager.getObject(this.nodeId, (err, childObj) => {
|
|
319
|
+
// istanbul ignore next
|
|
320
|
+
if (err) {
|
|
321
|
+
return callback(err);
|
|
322
|
+
}
|
|
323
|
+
this.parent[this.name] = childObj;
|
|
324
|
+
this.parent.$components.push(childObj);
|
|
325
|
+
callback();
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
exports.ObjectExplorer = ObjectExplorer;
|
|
330
|
+
function t(references) {
|
|
331
|
+
if (!references)
|
|
332
|
+
return "";
|
|
333
|
+
return references.map((r) => r.browseName.name + " " + r.nodeId.toString());
|
|
334
|
+
}
|
|
335
|
+
function readUAStructure(proxyManager, obj, callback) {
|
|
336
|
+
const session = proxyManager.session;
|
|
337
|
+
// 0 Object
|
|
338
|
+
// 1 Variable
|
|
339
|
+
// 2 Method
|
|
340
|
+
const nodeId = obj.nodeId;
|
|
341
|
+
const nodesToBrowse = [
|
|
342
|
+
// Components (except Methods)
|
|
343
|
+
{
|
|
344
|
+
// BrowseDescription
|
|
345
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
346
|
+
includeSubtypes: true,
|
|
347
|
+
nodeClassMask: (0, node_opcua_data_model_1.makeNodeClassMask)("Object | Variable"),
|
|
348
|
+
nodeId,
|
|
349
|
+
referenceTypeId: (0, proxy_1.makeRefId)("HasComponent"),
|
|
350
|
+
resultMask
|
|
351
|
+
},
|
|
352
|
+
// Properties
|
|
353
|
+
{
|
|
354
|
+
// BrowseDescription
|
|
355
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
356
|
+
includeSubtypes: true,
|
|
357
|
+
// nodeClassMask: makeNodeClassMask("Variable"),
|
|
358
|
+
nodeId,
|
|
359
|
+
referenceTypeId: (0, proxy_1.makeRefId)("HasProperty"),
|
|
360
|
+
resultMask
|
|
361
|
+
},
|
|
362
|
+
// Methods
|
|
363
|
+
{
|
|
364
|
+
// BrowseDescription
|
|
365
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
366
|
+
includeSubtypes: true,
|
|
367
|
+
nodeClassMask: (0, node_opcua_data_model_1.makeNodeClassMask)("Method"),
|
|
368
|
+
nodeId,
|
|
369
|
+
referenceTypeId: (0, proxy_1.makeRefId)("HasComponent"),
|
|
370
|
+
resultMask
|
|
371
|
+
},
|
|
372
|
+
// TypeDefinition
|
|
373
|
+
{
|
|
374
|
+
// BrowseDescription
|
|
375
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Both,
|
|
376
|
+
includeSubtypes: true,
|
|
377
|
+
nodeId,
|
|
378
|
+
referenceTypeId: (0, proxy_1.makeRefId)("HasTypeDefinition"),
|
|
379
|
+
resultMask
|
|
380
|
+
},
|
|
381
|
+
// FromState
|
|
382
|
+
{
|
|
383
|
+
// BrowseDescription
|
|
384
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
385
|
+
includeSubtypes: true,
|
|
386
|
+
nodeId,
|
|
387
|
+
referenceTypeId: (0, proxy_1.makeRefId)("FromState"),
|
|
388
|
+
resultMask
|
|
389
|
+
},
|
|
390
|
+
// ToState
|
|
391
|
+
{
|
|
392
|
+
// BrowseDescription
|
|
393
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
394
|
+
includeSubtypes: true,
|
|
395
|
+
nodeId,
|
|
396
|
+
referenceTypeId: (0, proxy_1.makeRefId)("ToState"),
|
|
397
|
+
resultMask
|
|
398
|
+
},
|
|
399
|
+
// (for folders ) Organizes
|
|
400
|
+
{
|
|
401
|
+
// BrowseDescription
|
|
402
|
+
browseDirection: node_opcua_data_model_1.BrowseDirection.Forward,
|
|
403
|
+
includeSubtypes: true,
|
|
404
|
+
nodeId,
|
|
405
|
+
referenceTypeId: (0, proxy_1.makeRefId)("Organizes"),
|
|
406
|
+
resultMask
|
|
407
|
+
}
|
|
408
|
+
];
|
|
409
|
+
session.browse(nodesToBrowse, (err, browseResults) => {
|
|
410
|
+
browseResults = browseResults || [];
|
|
411
|
+
// istanbul ignore next
|
|
412
|
+
if (err) {
|
|
413
|
+
return callback(err);
|
|
414
|
+
}
|
|
415
|
+
if (doDebug) {
|
|
416
|
+
debugLog("Components", t(browseResults[0].references));
|
|
417
|
+
debugLog("Properties", t(browseResults[1].references));
|
|
418
|
+
debugLog("Methods", t(browseResults[2].references));
|
|
419
|
+
}
|
|
420
|
+
async.series([
|
|
421
|
+
(callback) => {
|
|
422
|
+
async.mapSeries(browseResults[0].references, (reference, innerCallback) => add_component(proxyManager, obj, reference, innerCallback), (err) => callback(err));
|
|
423
|
+
},
|
|
424
|
+
(callback) => {
|
|
425
|
+
async.mapSeries(browseResults[1].references, (reference, innerCallback) => add_property(proxyManager, obj, reference, innerCallback), (err) => callback(err));
|
|
426
|
+
},
|
|
427
|
+
// now enrich our object with nice callable async methods
|
|
428
|
+
(callback) => {
|
|
429
|
+
async.mapSeries(browseResults[2].references, (reference, innerCallback) => add_method(proxyManager, obj, reference, innerCallback), (err) => callback(err));
|
|
430
|
+
},
|
|
431
|
+
// now set typeDefinition
|
|
432
|
+
(callback) => {
|
|
433
|
+
add_typeDefinition(proxyManager, obj, browseResults[3].references, callback);
|
|
434
|
+
},
|
|
435
|
+
// FromState
|
|
436
|
+
(callback) => {
|
|
437
|
+
// fromState
|
|
438
|
+
const reference = browseResults[4].references ? browseResults[4].references[0] : null;
|
|
439
|
+
// fromState
|
|
440
|
+
if (reference) {
|
|
441
|
+
return addFromState(proxyManager, obj, reference, callback);
|
|
442
|
+
}
|
|
443
|
+
callback();
|
|
444
|
+
},
|
|
445
|
+
// ToState
|
|
446
|
+
(callback) => {
|
|
447
|
+
const reference = browseResults[5].references ? browseResults[5].references[0] : null;
|
|
448
|
+
// fromState
|
|
449
|
+
if (reference) {
|
|
450
|
+
return addToState(proxyManager, obj, reference, callback);
|
|
451
|
+
}
|
|
452
|
+
callback();
|
|
453
|
+
},
|
|
454
|
+
// Organizes
|
|
455
|
+
(callback) => {
|
|
456
|
+
async.mapSeries(browseResults[6].references, (reference, callback) => addFolderElement(proxyManager, obj, reference, callback), (err) => callback(err));
|
|
457
|
+
}
|
|
458
|
+
], (err) => callback(err));
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
exports.readUAStructure = readUAStructure;
|
|
462
462
|
//# sourceMappingURL=object_explorer.js.map
|