opcua-webapi-ts 1.1.5 → 1.1.6
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/cjs/client/utils/UaNodeReader.js +439 -517
- package/dist/cjs/common/nodes/UaDataType.js +35 -34
- package/dist/cjs/common/nodes/UaMethod.js +2 -2
- package/dist/cjs/common/nodes/UaObject.js +1 -1
- package/dist/cjs/common/nodes/UaVariable.js +10 -6
- package/dist/cjs/common/types/UaReference.js +59 -0
- package/dist/cjs/common/types/index.js +1 -1
- package/dist/client/utils/UaNodeReader.d.ts +45 -73
- package/dist/client/utils/UaNodeReader.js +439 -517
- package/dist/common/nodes/UaDataType.d.ts +2 -2
- package/dist/common/nodes/UaDataType.js +35 -34
- package/dist/common/nodes/UaMethod.js +2 -2
- package/dist/common/nodes/UaObject.js +1 -1
- package/dist/common/nodes/UaVariable.d.ts +5 -4
- package/dist/common/nodes/UaVariable.js +10 -6
- package/dist/common/types/UaReference.d.ts +23 -0
- package/dist/common/types/UaReference.js +59 -0
- package/dist/common/types/index.d.ts +1 -1
- package/dist/common/types/index.js +1 -1
- package/package.json +1 -1
|
@@ -9,177 +9,353 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = exports.UaLinkBrowser = exports.UaChildBrowser = exports.UaNodeReferenceBrowser = void 0;
|
|
13
13
|
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
|
-
class
|
|
16
|
-
constructor(returnDescription,
|
|
17
|
-
this._finished = false;
|
|
15
|
+
class UaNodeReferenceBrowser {
|
|
16
|
+
constructor(nodeIds, referenceType, nodeClassToReturn, returnDescription, maxNodesPerBrowse, maxReferencesPerNode) {
|
|
18
17
|
this._nodesToBrowse = [];
|
|
18
|
+
this._referenceType = referenceType;
|
|
19
|
+
this._nodeClassToReturn = nodeClassToReturn;
|
|
19
20
|
this._continuationPointToBrowse = [];
|
|
20
|
-
this._browseResults = [];
|
|
21
|
-
this._readResults = new Map;
|
|
22
21
|
this._returnDescription = returnDescription;
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
this._maxNodesPerBrowse = (null == maxNodesPerBrowse || maxNodesPerBrowse <= 0) ? 50 : maxNodesPerBrowse;
|
|
23
|
+
this._maxReferencesPerNode = (null == maxReferencesPerNode || maxReferencesPerNode < 0) ? 50 : maxReferencesPerNode;
|
|
24
|
+
this._readResults = new Map();
|
|
25
|
+
if (this._nodeClassToReturn != 0) {
|
|
26
|
+
let nodeIdSet = new Set;
|
|
27
|
+
for (let item of nodeIds) {
|
|
28
|
+
if (nodeIdSet.has(item.toString()))
|
|
29
|
+
continue;
|
|
30
|
+
nodeIdSet.add(item.toString());
|
|
31
|
+
this._nodesToBrowse.push(item);
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
}
|
|
35
|
+
browse(client) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (this.isFinish())
|
|
38
|
+
return;
|
|
39
|
+
yield this.browseOnce(client);
|
|
40
|
+
yield this.browse(client);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
browseOnce(client) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (this._nodesToBrowse.length != 0) {
|
|
46
|
+
yield this._browseNodes(client);
|
|
47
|
+
}
|
|
48
|
+
else if (this._continuationPointToBrowse.length != 0) {
|
|
49
|
+
yield this._browseContinuationPoints(client);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
results() {
|
|
54
|
+
let results = [];
|
|
55
|
+
for (let item of this._readResults) {
|
|
56
|
+
results.push({
|
|
57
|
+
nodeId: (0, common_1.parseUaNodeId)(item[0]),
|
|
58
|
+
references: item[1]
|
|
59
|
+
});
|
|
40
60
|
}
|
|
61
|
+
this._readResults.clear();
|
|
62
|
+
return results;
|
|
63
|
+
}
|
|
64
|
+
isFinish() {
|
|
65
|
+
return (this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0);
|
|
41
66
|
}
|
|
42
67
|
_browseNodes(client) {
|
|
43
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
69
|
var _a;
|
|
45
|
-
|
|
70
|
+
if (this._nodesToBrowse.length == 0)
|
|
71
|
+
return;
|
|
72
|
+
let nodesToBrowse = this._nodesToBrowse.splice(0, this._maxNodesPerBrowse);
|
|
46
73
|
let browseDescriptions = [];
|
|
47
74
|
for (let item of nodesToBrowse) {
|
|
48
|
-
let browseDescription = new common_1.UaBrowseDescription(item
|
|
75
|
+
let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, this._referenceType, true, this._nodeClassToReturn, 63);
|
|
49
76
|
browseDescriptions.push(browseDescription);
|
|
50
77
|
}
|
|
51
|
-
let results = yield client.browse(browseDescriptions,
|
|
78
|
+
let results = yield client.browse(browseDescriptions, this._maxReferencesPerNode);
|
|
52
79
|
for (let i = 0; i < nodesToBrowse.length; ++i) {
|
|
53
|
-
let
|
|
80
|
+
let currentNodeId = nodesToBrowse[i];
|
|
54
81
|
let currentResult = results[i];
|
|
55
82
|
if (currentResult.statusCode.isNotGood())
|
|
56
83
|
throw new common_1.UaError(currentResult.statusCode);
|
|
84
|
+
let currentReferences = this._readResults.get(currentNodeId.toString());
|
|
85
|
+
if (!currentReferences) {
|
|
86
|
+
currentReferences = [];
|
|
87
|
+
this._readResults.set(currentNodeId.toString(), currentReferences);
|
|
88
|
+
}
|
|
89
|
+
let newReferences = [];
|
|
57
90
|
for (let item of currentResult.references) {
|
|
58
91
|
let nodeId = item.nodeId.getNodeId();
|
|
59
92
|
let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
|
|
60
93
|
if (null == nodeId || null === typeDefinition)
|
|
61
94
|
continue;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
nodeClass: (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified,
|
|
66
|
-
browseName: item.browseName ? item.browseName : "",
|
|
67
|
-
displayName: item.displayName ? item.displayName : common_1.UaLocalizedText.nullText,
|
|
68
|
-
referenceTypeId: item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId,
|
|
69
|
-
isForward: (item.isForward) ? item.isForward : false,
|
|
70
|
-
typeDefinitionId: (typeDefinition) ? typeDefinition : undefined
|
|
71
|
-
});
|
|
72
|
-
this._updateNodesToBrowse(item);
|
|
95
|
+
let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
|
|
96
|
+
currentReferences.push(reference);
|
|
97
|
+
newReferences.push(reference);
|
|
73
98
|
}
|
|
74
99
|
if (currentResult.continuationPoint) {
|
|
75
100
|
this._continuationPointToBrowse.push({
|
|
76
|
-
nodeId:
|
|
101
|
+
nodeId: currentNodeId,
|
|
77
102
|
continuationPoint: currentResult.continuationPoint
|
|
78
103
|
});
|
|
79
104
|
}
|
|
105
|
+
if (this._returnDescription)
|
|
106
|
+
yield this._readDescriptions(client, newReferences);
|
|
80
107
|
}
|
|
81
108
|
});
|
|
82
109
|
}
|
|
83
110
|
_browseContinuationPoints(client) {
|
|
84
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
|
|
112
|
+
var _a;
|
|
113
|
+
let cpsToBrowse = this._continuationPointToBrowse.splice(0, this._maxNodesPerBrowse);
|
|
86
114
|
let continuationPoints = [];
|
|
87
115
|
for (let item of cpsToBrowse) {
|
|
88
116
|
continuationPoints.push(item.continuationPoint);
|
|
89
117
|
}
|
|
90
118
|
let results = yield client.browseNext(continuationPoints, false);
|
|
91
119
|
for (let i = 0; i < cpsToBrowse.length; ++i) {
|
|
92
|
-
let
|
|
120
|
+
let currentNodeId = cpsToBrowse[i].nodeId;
|
|
93
121
|
let currentResult = results[i];
|
|
94
122
|
if (currentResult.statusCode.isNotGood())
|
|
95
123
|
throw new common_1.UaError(currentResult.statusCode);
|
|
124
|
+
let newReferences = [];
|
|
96
125
|
for (let item of currentResult.references) {
|
|
97
126
|
let nodeId = item.nodeId.getNodeId();
|
|
98
|
-
let typeDefinition = item.typeDefinition ?
|
|
99
|
-
if (null == nodeId)
|
|
127
|
+
let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
|
|
128
|
+
if (null == nodeId || null === typeDefinition)
|
|
100
129
|
continue;
|
|
101
|
-
this.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
typeDefinitionId: (typeDefinition) ? typeDefinition : undefined
|
|
110
|
-
});
|
|
111
|
-
this._updateNodesToBrowse(item);
|
|
130
|
+
let currentReferences = this._readResults.get(currentNodeId.toString());
|
|
131
|
+
if (!currentReferences) {
|
|
132
|
+
currentReferences = [];
|
|
133
|
+
this._readResults.set(currentNodeId.toString(), currentReferences);
|
|
134
|
+
}
|
|
135
|
+
let reference = new common_1.UaReference(nodeId, (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified, item.browseName ? item.browseName : "", item.displayName ? item.displayName : common_1.UaLocalizedText.nullText, item.referenceTypeId ? item.referenceTypeId : common_1.UaNodeId.nullNodeId, (typeDefinition) ? typeDefinition : common_1.UaNodeId.nullNodeId);
|
|
136
|
+
currentReferences.push(reference);
|
|
137
|
+
newReferences.push(reference);
|
|
112
138
|
}
|
|
113
|
-
if (currentResult.continuationPoint
|
|
139
|
+
if (currentResult.continuationPoint) {
|
|
114
140
|
this._continuationPointToBrowse.push({
|
|
115
|
-
nodeId:
|
|
141
|
+
nodeId: currentNodeId,
|
|
116
142
|
continuationPoint: currentResult.continuationPoint
|
|
117
143
|
});
|
|
118
144
|
}
|
|
145
|
+
if (this._returnDescription)
|
|
146
|
+
yield this._readDescriptions(client, newReferences);
|
|
119
147
|
}
|
|
120
148
|
});
|
|
121
149
|
}
|
|
122
|
-
|
|
150
|
+
_readDescriptions(client, references) {
|
|
123
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
if (
|
|
152
|
+
if (references.length === 0)
|
|
125
153
|
return;
|
|
126
|
-
let nodesToRead =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
yield
|
|
154
|
+
let nodesToRead = [];
|
|
155
|
+
for (let item of references) {
|
|
156
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
157
|
+
}
|
|
158
|
+
let dataValues = yield client.read(nodesToRead);
|
|
159
|
+
for (let i = 0; i < references.length; ++i) {
|
|
160
|
+
if (dataValues[i].statusCode.isGood()) {
|
|
161
|
+
let description = dataValues[i].value.toLocalizedText();
|
|
162
|
+
if (description)
|
|
163
|
+
references[i].description = description;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
131
166
|
});
|
|
132
167
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
168
|
+
}
|
|
169
|
+
exports.UaNodeReferenceBrowser = UaNodeReferenceBrowser;
|
|
170
|
+
class UaChildBrowser extends UaNodeReferenceBrowser {
|
|
171
|
+
constructor(nodeIds, returnDescription) {
|
|
172
|
+
super(nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Object | opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType | opcua_webapi_1.NodeClass.ReferenceType, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.UaChildBrowser = UaChildBrowser;
|
|
176
|
+
class UaLinkBrowser extends UaNodeReferenceBrowser {
|
|
177
|
+
constructor(nodeIds, returnDescription) {
|
|
178
|
+
super(nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.NonHierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.UaLinkBrowser = UaLinkBrowser;
|
|
182
|
+
class UaNodeReader {
|
|
183
|
+
constructor(returnDescription, returnVariable, returnMethod, returnAttributes, returnValue) {
|
|
184
|
+
this._returnDescription = (returnDescription) ? returnDescription : false;
|
|
185
|
+
this._returnAttributes = (returnAttributes) ? returnAttributes : false;
|
|
186
|
+
this._returnValue = (returnValue) ? returnValue : false;
|
|
187
|
+
this._nodeClassToReturn = 0;
|
|
188
|
+
if (returnVariable)
|
|
189
|
+
this._nodeClassToReturn += opcua_webapi_1.NodeClass.Variable;
|
|
190
|
+
if (returnMethod)
|
|
191
|
+
this._nodeClassToReturn += opcua_webapi_1.NodeClass.Method;
|
|
192
|
+
if (null == UaNodeReader.s_variableTypeWithoutMember) {
|
|
193
|
+
UaNodeReader.s_variableTypeWithoutMember = new Set;
|
|
194
|
+
UaNodeReader.s_variableTypeWithoutMember.add(new common_1.UaNodeId(common_1.VariableTypeIds.BaseVariableType).toString());
|
|
195
|
+
UaNodeReader.s_variableTypeWithoutMember.add(new common_1.UaNodeId(common_1.VariableTypeIds.PropertyType).toString());
|
|
196
|
+
UaNodeReader.s_variableTypeWithoutMember.add(new common_1.UaNodeId(common_1.VariableTypeIds.BaseDataVariableType).toString());
|
|
197
|
+
}
|
|
198
|
+
if (null == UaNodeReader.s_variablesNameToRead) {
|
|
199
|
+
UaNodeReader.s_variablesNameToRead = new Set;
|
|
200
|
+
UaNodeReader.s_variablesNameToRead.add("InputArguments");
|
|
201
|
+
UaNodeReader.s_variablesNameToRead.add("OutputArguments");
|
|
202
|
+
UaNodeReader.s_variablesNameToRead.add("EnumStrings");
|
|
203
|
+
UaNodeReader.s_variablesNameToRead.add("EnumValues");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
read(nodeIds, client) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
if (nodeIds.length == 0)
|
|
209
|
+
return [];
|
|
210
|
+
let nodeIdsToRead = [];
|
|
211
|
+
let nodeIdsSet = new Set();
|
|
212
|
+
for (let item of nodeIds) {
|
|
213
|
+
if (nodeIdsSet.has(item.toString()))
|
|
214
|
+
continue;
|
|
215
|
+
nodeIdsToRead.push(item);
|
|
216
|
+
nodeIdsSet.add(item.toString());
|
|
147
217
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
218
|
+
let rootReferences = yield this._readRootNodes(nodeIdsToRead, client);
|
|
219
|
+
return yield this.readByReferences(rootReferences, client);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
readByReferences(references, client) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
if (references.length == 0)
|
|
225
|
+
return [];
|
|
226
|
+
let referencesToRead = [];
|
|
227
|
+
let nodeIdsToBrowse = [];
|
|
228
|
+
let nodeIdsSet = new Set();
|
|
229
|
+
for (let item of references) {
|
|
230
|
+
if (nodeIdsSet.has(item.nodeId.toString()))
|
|
231
|
+
continue;
|
|
232
|
+
referencesToRead.push(item);
|
|
233
|
+
nodeIdsToBrowse.push(item.nodeId);
|
|
234
|
+
nodeIdsSet.add(item.nodeId.toString());
|
|
235
|
+
}
|
|
236
|
+
let nodeReferenceBrowser = new UaNodeReferenceBrowser(nodeIdsToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), this._nodeClassToReturn, false);
|
|
237
|
+
yield nodeReferenceBrowser.browse(client);
|
|
238
|
+
let childReferences = nodeReferenceBrowser.results();
|
|
239
|
+
let childNodesToBrowse = [];
|
|
240
|
+
for (let item of childReferences) {
|
|
241
|
+
for (let reference of item.references) {
|
|
242
|
+
if (opcua_webapi_1.NodeClass.Variable == reference.nodeClass &&
|
|
243
|
+
!UaNodeReader.s_variableTypeWithoutMember.has(reference.typeDefinitionId.toString())) {
|
|
244
|
+
childNodesToBrowse.push(reference.nodeId);
|
|
245
|
+
}
|
|
246
|
+
if (opcua_webapi_1.NodeClass.Method == reference.nodeClass) {
|
|
247
|
+
childNodesToBrowse.push(reference.nodeId);
|
|
248
|
+
}
|
|
152
249
|
}
|
|
153
250
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
251
|
+
let variableReferences = [];
|
|
252
|
+
if (childNodesToBrowse.length != 0) {
|
|
253
|
+
let childReferenceBrowser = new UaNodeReferenceBrowser(childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Variable, false);
|
|
254
|
+
yield childReferenceBrowser.browse(client);
|
|
255
|
+
variableReferences = childReferenceBrowser.results();
|
|
256
|
+
}
|
|
257
|
+
let allReferences = [];
|
|
258
|
+
for (let item of references) {
|
|
259
|
+
allReferences.push(item);
|
|
260
|
+
}
|
|
261
|
+
for (let item of childReferences) {
|
|
262
|
+
for (let reference of item.references) {
|
|
263
|
+
allReferences.push(reference);
|
|
158
264
|
}
|
|
159
265
|
}
|
|
160
|
-
|
|
161
|
-
let
|
|
162
|
-
|
|
163
|
-
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
164
|
-
parent.addMember(childNode);
|
|
266
|
+
for (let item of variableReferences) {
|
|
267
|
+
for (let reference of item.references) {
|
|
268
|
+
allReferences.push(reference);
|
|
165
269
|
}
|
|
270
|
+
;
|
|
166
271
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
272
|
+
let nodesMap = new Map();
|
|
273
|
+
yield this._readNodes(allReferences, nodesMap, client);
|
|
274
|
+
for (let item of variableReferences) {
|
|
275
|
+
this._buildNodeTree(item, nodesMap);
|
|
276
|
+
}
|
|
277
|
+
for (let item of childReferences) {
|
|
278
|
+
this._buildNodeTree(item, nodesMap);
|
|
279
|
+
}
|
|
280
|
+
let rootNodes = [];
|
|
281
|
+
for (let item of references) {
|
|
282
|
+
let node = nodesMap.get(item.nodeId.toString());
|
|
283
|
+
if (node)
|
|
284
|
+
rootNodes.push(node);
|
|
285
|
+
}
|
|
286
|
+
return rootNodes;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
_readRootNodes(nodeIds, client) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
let nodesToRead = [];
|
|
292
|
+
for (let item of nodeIds) {
|
|
293
|
+
nodesToRead.push(new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.NodeClass));
|
|
294
|
+
nodesToRead.push(new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.BrowseName));
|
|
295
|
+
nodesToRead.push(new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.DisplayName));
|
|
296
|
+
}
|
|
297
|
+
let dataValues = yield client.read(nodesToRead);
|
|
298
|
+
let references = [];
|
|
299
|
+
let typeDefinitionsToRead = [];
|
|
300
|
+
for (let i = 0; i < nodeIds.length; ++i) {
|
|
301
|
+
let dataIndex = i * 3;
|
|
302
|
+
let currentNodeId = nodeIds[i];
|
|
303
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
304
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
305
|
+
let nodeClass = dataValues[dataIndex].value.toNumber();
|
|
306
|
+
dataIndex++;
|
|
307
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
308
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
309
|
+
let browseName = dataValues[dataIndex].value.toString();
|
|
310
|
+
dataIndex++;
|
|
311
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
312
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
313
|
+
let displayName = dataValues[dataIndex].value.toLocalizedText();
|
|
314
|
+
dataIndex++;
|
|
315
|
+
if (null == nodeClass || null == browseName || null == displayName)
|
|
316
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
317
|
+
if (opcua_webapi_1.NodeClass.Unspecified != this._nodeClassToReturn) {
|
|
318
|
+
let newReference = new common_1.UaReference(currentNodeId, nodeClass, browseName, displayName);
|
|
319
|
+
references.push(newReference);
|
|
320
|
+
if (opcua_webapi_1.NodeClass.Object == nodeClass)
|
|
321
|
+
typeDefinitionsToRead.push(newReference);
|
|
171
322
|
}
|
|
172
323
|
}
|
|
173
|
-
|
|
174
|
-
let
|
|
175
|
-
|
|
176
|
-
|
|
324
|
+
if (typeDefinitionsToRead.length != 0) {
|
|
325
|
+
let browseDescriptions = [];
|
|
326
|
+
for (let item of typeDefinitionsToRead) {
|
|
327
|
+
let browseDescription = new common_1.UaBrowseDescription(item.nodeId, opcua_webapi_1.BrowseDirection.Forward, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasTypeDefinition), false, opcua_webapi_1.NodeClass.ObjectType, 0);
|
|
328
|
+
browseDescriptions.push(browseDescription);
|
|
329
|
+
}
|
|
330
|
+
let results = yield client.browse(browseDescriptions);
|
|
331
|
+
for (let i = 0; i < browseDescriptions.length; ++i) {
|
|
332
|
+
if (results[i].statusCode.isNotGood())
|
|
333
|
+
throw new common_1.UaError(results[i].statusCode);
|
|
334
|
+
if (results[i].references.length != 1)
|
|
335
|
+
continue;
|
|
336
|
+
typeDefinitionsToRead[i].typeDefinitionId = results[i].references[0].nodeId.getNodeId();
|
|
177
337
|
}
|
|
178
338
|
}
|
|
179
|
-
|
|
180
|
-
|
|
339
|
+
return references;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
_readNodes(references, nodes, client) {
|
|
343
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
if (references.length == 0)
|
|
345
|
+
return;
|
|
346
|
+
let refrencesToRead = [];
|
|
347
|
+
while (references.length != 0) {
|
|
348
|
+
refrencesToRead.push(references.splice(0, 100));
|
|
349
|
+
}
|
|
350
|
+
for (let item of refrencesToRead) {
|
|
351
|
+
yield this._readTypes(item, nodes, client);
|
|
352
|
+
yield this._readObjects(item, nodes, client);
|
|
353
|
+
yield this._readVariables(item, nodes, client);
|
|
354
|
+
yield this._readMethods(item, nodes, client);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
181
357
|
}
|
|
182
|
-
_readTypes(references, client) {
|
|
358
|
+
_readTypes(references, nodes, client) {
|
|
183
359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
360
|
let typesToRead = [];
|
|
185
361
|
for (let item of references) {
|
|
@@ -195,37 +371,39 @@ class UaNodeReaderBase {
|
|
|
195
371
|
let nodesToRead = [];
|
|
196
372
|
for (let item of typesToRead) {
|
|
197
373
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
|
|
374
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
198
375
|
if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
199
376
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
|
|
200
377
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
|
|
201
378
|
}
|
|
202
|
-
if (this._returnDescription) {
|
|
203
|
-
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
204
|
-
}
|
|
205
379
|
}
|
|
206
380
|
let dataValues = yield client.read(nodesToRead);
|
|
207
381
|
for (let i = 0; i < typesToRead.length; ++i) {
|
|
208
|
-
let dataIndex;
|
|
209
|
-
if (this._returnDescription) {
|
|
210
|
-
dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 3 : i;
|
|
214
|
-
}
|
|
382
|
+
let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
|
|
215
383
|
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
216
384
|
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
217
385
|
let isAbstract = dataValues[dataIndex].value.toBoolean();
|
|
218
386
|
if (null == isAbstract)
|
|
219
387
|
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
388
|
+
dataIndex++;
|
|
389
|
+
let description = undefined;
|
|
390
|
+
if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
|
|
391
|
+
description = dataValues[dataIndex].value.toLocalizedText();
|
|
392
|
+
if (null == description)
|
|
393
|
+
description = undefined;
|
|
394
|
+
}
|
|
395
|
+
dataIndex++;
|
|
220
396
|
let dataType = common_1.UaNodeId.nullNodeId;
|
|
221
397
|
let valueRank = -1;
|
|
222
398
|
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
223
|
-
if (dataValues[dataIndex
|
|
224
|
-
throw new common_1.UaError(dataValues[dataIndex
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
399
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
400
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
401
|
+
dataType = dataValues[dataIndex].value.toNodeId();
|
|
402
|
+
dataIndex++;
|
|
403
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
404
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
405
|
+
valueRank = dataValues[dataIndex].value.toNumber();
|
|
406
|
+
dataIndex++;
|
|
229
407
|
if (null == dataType || null == valueRank)
|
|
230
408
|
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
231
409
|
}
|
|
@@ -242,23 +420,15 @@ class UaNodeReaderBase {
|
|
|
242
420
|
else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
243
421
|
typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
|
|
244
422
|
}
|
|
245
|
-
if (this._returnDescription) {
|
|
246
|
-
|
|
247
|
-
if (dataValues[descriptionIndex].statusCode.isGood()) {
|
|
248
|
-
let descriptionValue = dataValues[descriptionIndex].value.toLocalizedText();
|
|
249
|
-
if (null != descriptionValue)
|
|
250
|
-
typeNode.description = descriptionValue;
|
|
251
|
-
}
|
|
423
|
+
if (this._returnDescription && description) {
|
|
424
|
+
typeNode.description = description;
|
|
252
425
|
}
|
|
253
426
|
typeNode.refToParent = typesToRead[i].referenceTypeId;
|
|
254
|
-
|
|
255
|
-
parentId: typesToRead[i].fromNodeId,
|
|
256
|
-
node: typeNode
|
|
257
|
-
});
|
|
427
|
+
nodes.set(typeNode.nodeId.toString(), typeNode);
|
|
258
428
|
}
|
|
259
429
|
});
|
|
260
430
|
}
|
|
261
|
-
_readObjects(references, client) {
|
|
431
|
+
_readObjects(references, nodes, client) {
|
|
262
432
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
433
|
let objectsToRead = [];
|
|
264
434
|
for (let item of references) {
|
|
@@ -270,38 +440,43 @@ class UaNodeReaderBase {
|
|
|
270
440
|
return;
|
|
271
441
|
let nodesToRead = [];
|
|
272
442
|
for (let item of objectsToRead) {
|
|
273
|
-
|
|
443
|
+
if (this._returnAttributes) {
|
|
444
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier));
|
|
445
|
+
}
|
|
274
446
|
if (this._returnDescription) {
|
|
275
447
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
276
448
|
}
|
|
277
449
|
}
|
|
278
|
-
let dataValues =
|
|
450
|
+
let dataValues = [];
|
|
451
|
+
if (nodesToRead.length != 0) {
|
|
452
|
+
dataValues = yield client.read(nodesToRead);
|
|
453
|
+
}
|
|
279
454
|
for (let i = 0; i < objectsToRead.length; ++i) {
|
|
280
|
-
|
|
281
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
282
|
-
let dataIndex = (this._returnDescription) ? i * 2 : i;
|
|
455
|
+
let dataIndex = (this._returnAttributes && this._returnDescription) ? i * 2 : i;
|
|
283
456
|
let eventNotifier = 0;
|
|
284
|
-
|
|
457
|
+
let description = undefined;
|
|
458
|
+
if (this._returnAttributes && dataValues[dataIndex].statusCode.isGood()) {
|
|
285
459
|
eventNotifier = dataValues[dataIndex].value.toNumber();
|
|
460
|
+
if (null == eventNotifier)
|
|
461
|
+
eventNotifier = 0;
|
|
462
|
+
dataIndex++;
|
|
463
|
+
}
|
|
464
|
+
if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
|
|
465
|
+
description = dataValues[dataIndex].value.toLocalizedText();
|
|
466
|
+
if (null == description)
|
|
467
|
+
description = undefined;
|
|
468
|
+
dataIndex++;
|
|
286
469
|
}
|
|
287
470
|
let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
|
|
288
471
|
objectNode.refToParent = objectsToRead[i].referenceTypeId;
|
|
289
|
-
if (this._returnDescription) {
|
|
290
|
-
|
|
291
|
-
if (dataValues[descriptionIndex].statusCode.isGood()) {
|
|
292
|
-
let descriptionValue = dataValues[descriptionIndex].value.toLocalizedText();
|
|
293
|
-
if (null != descriptionValue)
|
|
294
|
-
objectNode.description = descriptionValue;
|
|
295
|
-
}
|
|
472
|
+
if (this._returnDescription && description) {
|
|
473
|
+
objectNode.description = description;
|
|
296
474
|
}
|
|
297
|
-
|
|
298
|
-
parentId: objectsToRead[i].fromNodeId,
|
|
299
|
-
node: objectNode
|
|
300
|
-
});
|
|
475
|
+
nodes.set(objectNode.nodeId.toString(), objectNode);
|
|
301
476
|
}
|
|
302
477
|
});
|
|
303
478
|
}
|
|
304
|
-
_readVariables(references, client) {
|
|
479
|
+
_readVariables(references, nodes, client) {
|
|
305
480
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
481
|
let variablesToRead = [];
|
|
307
482
|
let nodeIds = [];
|
|
@@ -313,418 +488,165 @@ class UaNodeReaderBase {
|
|
|
313
488
|
}
|
|
314
489
|
if (0 == nodeIds.length)
|
|
315
490
|
return;
|
|
316
|
-
let results =
|
|
317
|
-
|
|
491
|
+
let results = [];
|
|
492
|
+
if (this._returnAttributes) {
|
|
493
|
+
results = yield client.readVariableAttributes(nodeIds);
|
|
494
|
+
}
|
|
495
|
+
let variablesToReadValue = [];
|
|
318
496
|
for (let i = 0; i < variablesToRead.length; ++i) {
|
|
319
|
-
let variableNode
|
|
320
|
-
this.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
497
|
+
let variableNode;
|
|
498
|
+
if (this._returnAttributes) {
|
|
499
|
+
variableNode = new common_1.UaVariable(variablesToRead[i].nodeId, variablesToRead[i].browseName, variablesToRead[i].displayName, results[i].dataType, results[i].valueRank, results[i].accessLevel, results[i].userAccessLevel, results[i].historizing, variablesToRead[i].typeDefinitionId);
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
variableNode = new common_1.UaVariable(variablesToRead[i].nodeId, variablesToRead[i].browseName, variablesToRead[i].displayName, common_1.UaNodeId.nullNodeId, -1, 0, 0, false, variablesToRead[i].typeDefinitionId);
|
|
503
|
+
}
|
|
504
|
+
nodes.set(variableNode.nodeId.toString(), variableNode);
|
|
505
|
+
if (this._returnValue || (UaNodeReader.s_variablesNameToRead.has(variableNode.browseName))) {
|
|
506
|
+
variablesToReadValue.push(variableNode);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (variablesToReadValue.length != 0) {
|
|
510
|
+
let valuesToRead = [];
|
|
511
|
+
for (let item of variablesToReadValue) {
|
|
512
|
+
valuesToRead.push(item.nodeId);
|
|
513
|
+
}
|
|
328
514
|
let values = yield client.readValues(valuesToRead);
|
|
329
515
|
for (let i = 0; i < valuesToRead.length; ++i) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
let variableNode = this._readResults.get(valuesToRead[i].toString());
|
|
333
|
-
variableNode.node.value = values[i].value;
|
|
516
|
+
let variableNode = nodes.get(valuesToRead[i].toString());
|
|
517
|
+
variableNode.dataValue = values[i];
|
|
334
518
|
}
|
|
335
519
|
}
|
|
336
520
|
});
|
|
337
521
|
}
|
|
338
|
-
_readMethods(references, client) {
|
|
522
|
+
_readMethods(references, nodes, client) {
|
|
339
523
|
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
+
let methodsToRead = [];
|
|
340
525
|
for (let item of references) {
|
|
341
526
|
if (item.nodeClass != opcua_webapi_1.NodeClass.Method)
|
|
342
527
|
continue;
|
|
343
|
-
|
|
344
|
-
this._readResults.set(methodNode.nodeId.toString(), {
|
|
345
|
-
parentId: item.fromNodeId,
|
|
346
|
-
node: methodNode
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
_updateNodesToBrowse(reference) {
|
|
352
|
-
let nodeClassToReturn = opcua_webapi_1.NodeClass.Unspecified;
|
|
353
|
-
if (reference.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
|
|
354
|
-
reference.nodeClass == opcua_webapi_1.NodeClass.Object) {
|
|
355
|
-
nodeClassToReturn = this._nodeClassToReturn;
|
|
356
|
-
}
|
|
357
|
-
else if (reference.nodeClass == opcua_webapi_1.NodeClass.Variable) {
|
|
358
|
-
if (reference.typeDefinition &&
|
|
359
|
-
!UaNodeReaderBase.s_variableTypeWithoutMember.has(reference.typeDefinition.toString())) {
|
|
360
|
-
nodeClassToReturn = opcua_webapi_1.NodeClass.Variable;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
else if (reference.nodeClass == opcua_webapi_1.NodeClass.Method ||
|
|
364
|
-
reference.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
|
|
365
|
-
reference.nodeClass == opcua_webapi_1.NodeClass.DataType) {
|
|
366
|
-
nodeClassToReturn = opcua_webapi_1.NodeClass.Variable;
|
|
367
|
-
}
|
|
368
|
-
if (opcua_webapi_1.NodeClass.Unspecified != nodeClassToReturn) {
|
|
369
|
-
this._nodesToBrowse.push({
|
|
370
|
-
nodeId: reference.nodeId.getNodeId(),
|
|
371
|
-
nodeClassToReturn: nodeClassToReturn
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
exports.UaNodeReaderBase = UaNodeReaderBase;
|
|
377
|
-
UaNodeReaderBase.s_variableTypeWithoutMember = null;
|
|
378
|
-
UaNodeReaderBase.s_variableNameToReadValue = null;
|
|
379
|
-
class UaNodeReader extends UaNodeReaderBase {
|
|
380
|
-
constructor(nodeIds, returnDescription, returnVariables, returnMethod) {
|
|
381
|
-
super(returnDescription ? returnDescription : false, returnVariables ? returnVariables : false, returnMethod ? returnMethod : false);
|
|
382
|
-
if (nodeIds.length == 0)
|
|
383
|
-
this._finished = true;
|
|
384
|
-
this._nodeIds = new Set;
|
|
385
|
-
for (let item of nodeIds) {
|
|
386
|
-
this._nodeIds.add(item.toString());
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
readAll(client) {
|
|
390
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
391
|
-
if (this.isFinish())
|
|
392
|
-
return;
|
|
393
|
-
yield this.read(client);
|
|
394
|
-
yield this.readAll(client);
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
read(client) {
|
|
398
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
-
if (this._finished)
|
|
400
|
-
return;
|
|
401
|
-
if (!this._isRootNodeRead) {
|
|
402
|
-
yield this._readRootNodes(client);
|
|
528
|
+
methodsToRead.push(item);
|
|
403
529
|
}
|
|
404
|
-
|
|
405
|
-
yield this._browseContinuationPoints(client);
|
|
406
|
-
}
|
|
407
|
-
else if (this._nodesToBrowse.length != 0) {
|
|
408
|
-
yield this._browseNodes(client);
|
|
409
|
-
}
|
|
410
|
-
else if (this._browseResults.length != 0) {
|
|
411
|
-
yield this._readNodes(client);
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
this._buildNodeTree();
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
isFinish() {
|
|
419
|
-
return this._finished;
|
|
420
|
-
}
|
|
421
|
-
getResults() {
|
|
422
|
-
let ret = [];
|
|
423
|
-
for (let item of this._readResults) {
|
|
424
|
-
if (!this._nodeIds.has(item[1].node.nodeId.toString()))
|
|
425
|
-
continue;
|
|
426
|
-
ret.push(item[1].node);
|
|
427
|
-
}
|
|
428
|
-
return [...ret.values()];
|
|
429
|
-
}
|
|
430
|
-
_readRootNodes(client) {
|
|
431
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
-
if (this._isRootNodeRead)
|
|
530
|
+
if (0 == methodsToRead.length)
|
|
433
531
|
return;
|
|
434
|
-
let nodeIds = [];
|
|
435
532
|
let nodesToRead = [];
|
|
436
|
-
|
|
437
|
-
let
|
|
438
|
-
|
|
439
|
-
nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.NodeClass));
|
|
440
|
-
nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.BrowseName));
|
|
441
|
-
nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.DisplayName));
|
|
442
|
-
}
|
|
443
|
-
let dataValues = yield client.read(nodesToRead);
|
|
444
|
-
let browseResults = new Map;
|
|
445
|
-
for (let i = 0; i < nodeIds.length; ++i) {
|
|
446
|
-
let dataIndex = i * 3;
|
|
447
|
-
let currentNodeId = nodeIds[i];
|
|
448
|
-
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
449
|
-
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
450
|
-
if (dataValues[dataIndex + 1].statusCode.isNotGood())
|
|
451
|
-
throw new common_1.UaError(dataValues[dataIndex + 1].statusCode);
|
|
452
|
-
if (dataValues[dataIndex + 2].statusCode.isNotGood())
|
|
453
|
-
throw new common_1.UaError(dataValues[dataIndex + 2].statusCode);
|
|
454
|
-
let nodeClass = dataValues[dataIndex].value.toNumber();
|
|
455
|
-
let browseName = dataValues[dataIndex + 1].value.toString();
|
|
456
|
-
let displayName = dataValues[dataIndex + 2].value.toLocalizedText();
|
|
457
|
-
if (null == nodeClass || null == browseName || null == displayName)
|
|
458
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
459
|
-
if (opcua_webapi_1.NodeClass.Unspecified != this._nodeClassToReturn) {
|
|
460
|
-
this._nodesToBrowse.push({
|
|
461
|
-
nodeId: currentNodeId,
|
|
462
|
-
nodeClassToReturn: this._nodeClassToReturn
|
|
463
|
-
});
|
|
533
|
+
if (this._returnDescription) {
|
|
534
|
+
for (let item of methodsToRead) {
|
|
535
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
464
536
|
}
|
|
465
|
-
browseResults.set(currentNodeId.toString(), {
|
|
466
|
-
fromNodeId: common_1.UaNodeId.nullNodeId,
|
|
467
|
-
nodeId: currentNodeId,
|
|
468
|
-
nodeClass: nodeClass,
|
|
469
|
-
browseName: browseName,
|
|
470
|
-
displayName: displayName,
|
|
471
|
-
referenceTypeId: common_1.UaNodeId.nullNodeId,
|
|
472
|
-
isForward: true,
|
|
473
|
-
typeDefinitionId: common_1.UaNodeId.nullNodeId
|
|
474
|
-
});
|
|
475
537
|
}
|
|
476
|
-
let
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (currentNode.nodeClass != opcua_webapi_1.NodeClass.Object &&
|
|
480
|
-
currentNode.nodeClass != opcua_webapi_1.NodeClass.Variable)
|
|
481
|
-
continue;
|
|
482
|
-
let browseDescription = new common_1.UaBrowseDescription(currentNode.nodeId, opcua_webapi_1.BrowseDirection.Forward, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasTypeDefinition), false, opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType, 0);
|
|
483
|
-
browseDescriptions.push(browseDescription);
|
|
538
|
+
let dataValues = [];
|
|
539
|
+
if (nodesToRead.length != 0) {
|
|
540
|
+
dataValues = yield client.read(nodesToRead);
|
|
484
541
|
}
|
|
485
|
-
|
|
486
|
-
let
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
continue;
|
|
495
|
-
browseResult.typeDefinitionId = results[i].references[0].nodeId.getNodeId();
|
|
542
|
+
for (let i = 0; i < methodsToRead.length; ++i) {
|
|
543
|
+
let methodNode = new common_1.UaMethod(methodsToRead[i].nodeId, methodsToRead[i].browseName, methodsToRead[i].displayName);
|
|
544
|
+
if (this._returnDescription) {
|
|
545
|
+
if (dataValues[i].statusCode.isGood()) {
|
|
546
|
+
let description = dataValues[i].value.toLocalizedText();
|
|
547
|
+
if (null == description)
|
|
548
|
+
description = undefined;
|
|
549
|
+
methodNode.description = description;
|
|
550
|
+
}
|
|
496
551
|
}
|
|
552
|
+
nodes.set(methodNode.nodeId.toString(), methodNode);
|
|
497
553
|
}
|
|
498
|
-
this._browseResults = Array.from(browseResults.values());
|
|
499
|
-
this._isRootNodeRead = true;
|
|
500
554
|
});
|
|
501
555
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
readAll(client) {
|
|
519
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
520
|
-
if (this.isFinish())
|
|
521
|
-
return;
|
|
522
|
-
yield this.read(client);
|
|
523
|
-
yield this.readAll(client);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
read(client) {
|
|
527
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
528
|
-
if (this._finished)
|
|
529
|
-
return;
|
|
530
|
-
if (this._continuationPointToBrowse.length != 0) {
|
|
531
|
-
yield this._browseContinuationPoints(client);
|
|
556
|
+
_buildNodeTree(referenceResult, nodes) {
|
|
557
|
+
let parentNode = nodes.get(referenceResult.nodeId.toString());
|
|
558
|
+
if (null == parentNode)
|
|
559
|
+
return;
|
|
560
|
+
for (let item of referenceResult.references) {
|
|
561
|
+
let childNode = nodes.get(item.nodeId.toString());
|
|
562
|
+
if (!childNode)
|
|
563
|
+
continue;
|
|
564
|
+
if (opcua_webapi_1.NodeClass.Object == parentNode.nodeClass) {
|
|
565
|
+
let parent = parentNode;
|
|
566
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass ||
|
|
567
|
+
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
568
|
+
parent.addMember(childNode);
|
|
569
|
+
}
|
|
532
570
|
}
|
|
533
|
-
else if (
|
|
534
|
-
|
|
571
|
+
else if (opcua_webapi_1.NodeClass.Variable == parentNode.nodeClass) {
|
|
572
|
+
let parent = parentNode;
|
|
573
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
574
|
+
parent.addMember(childNode);
|
|
575
|
+
}
|
|
535
576
|
}
|
|
536
|
-
else if (
|
|
537
|
-
|
|
577
|
+
else if (opcua_webapi_1.NodeClass.Method == parentNode.nodeClass) {
|
|
578
|
+
let parent = parentNode;
|
|
579
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
580
|
+
parent.addMember(childNode);
|
|
581
|
+
}
|
|
538
582
|
}
|
|
539
|
-
else {
|
|
540
|
-
|
|
583
|
+
else if (opcua_webapi_1.NodeClass.ObjectType == parentNode.nodeClass) {
|
|
584
|
+
let parent = parentNode;
|
|
585
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass ||
|
|
586
|
+
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
587
|
+
parent.addMember(childNode);
|
|
588
|
+
}
|
|
541
589
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
getResults() {
|
|
548
|
-
let ret = new Map;
|
|
549
|
-
for (let item of this._readResults) {
|
|
550
|
-
if (!this._nodeIds.has(item[1].parentId.toString()))
|
|
551
|
-
continue;
|
|
552
|
-
let result;
|
|
553
|
-
let parentId = item[1].parentId.toString();
|
|
554
|
-
if (ret.has(parentId)) {
|
|
555
|
-
result = ret.get(parentId);
|
|
590
|
+
else if (opcua_webapi_1.NodeClass.VariableType == parentNode.nodeClass) {
|
|
591
|
+
let parent = parentNode;
|
|
592
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
593
|
+
parent.addMember(childNode);
|
|
594
|
+
}
|
|
556
595
|
}
|
|
557
|
-
else {
|
|
558
|
-
|
|
559
|
-
|
|
596
|
+
else if (opcua_webapi_1.NodeClass.DataType == parentNode.nodeClass) {
|
|
597
|
+
let parent = parentNode;
|
|
598
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
599
|
+
parent.setEnumVariable(childNode);
|
|
600
|
+
}
|
|
560
601
|
}
|
|
561
|
-
result.children.push(item[1].node);
|
|
562
602
|
}
|
|
563
|
-
return [...ret.values()];
|
|
564
603
|
}
|
|
565
604
|
}
|
|
566
|
-
exports.
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
this._returnDescription = (returnDescription) ? returnDescription : false;
|
|
573
|
-
this._readResults = null;
|
|
574
|
-
}
|
|
575
|
-
readAll(client) {
|
|
576
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
577
|
-
if (this.isFinish())
|
|
578
|
-
return;
|
|
579
|
-
yield this.read(client);
|
|
580
|
-
yield this.readAll(client);
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
read(client) {
|
|
584
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
585
|
-
if (this.isFinish())
|
|
586
|
-
return;
|
|
587
|
-
if (this._nodesToBrowse.length != 0) {
|
|
588
|
-
yield this._browseNodes(client);
|
|
589
|
-
}
|
|
590
|
-
else if (this._continuationPointToBrowse.length != 0) {
|
|
591
|
-
yield this._browseContinuationPoints(client);
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
this._buildResults();
|
|
595
|
-
yield this._readDescriptions(client);
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
isFinish() {
|
|
600
|
-
return null != this._readResults;
|
|
601
|
-
}
|
|
602
|
-
getResults() {
|
|
603
|
-
return (this._readResults) ? this._readResults : [];
|
|
605
|
+
exports.UaNodeReader = UaNodeReader;
|
|
606
|
+
UaNodeReader.s_variableTypeWithoutMember = null;
|
|
607
|
+
UaNodeReader.s_variablesNameToRead = null;
|
|
608
|
+
class UaObjectReader extends UaNodeReader {
|
|
609
|
+
constructor(returnDescription, returnValue) {
|
|
610
|
+
super(returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, true, true, true, returnValue !== null && returnValue !== void 0 ? returnValue : false);
|
|
604
611
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (this._nodesToBrowse.length == 0)
|
|
609
|
-
return;
|
|
610
|
-
let nodesToBrowse = this._nodesToBrowse.splice(0, 50);
|
|
611
|
-
let browseDescriptions = [];
|
|
612
|
-
for (let item of nodesToBrowse) {
|
|
613
|
-
let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Both, common_1.UaNodeId.from(common_1.ReferenceTypeIds.NonHierarchicalReferences), true, opcua_webapi_1.NodeClass.Object, 63);
|
|
614
|
-
browseDescriptions.push(browseDescription);
|
|
615
|
-
}
|
|
616
|
-
let results = yield client.browse(browseDescriptions, 50);
|
|
617
|
-
for (let i = 0; i < nodesToBrowse.length; ++i) {
|
|
618
|
-
let currentNodeId = nodesToBrowse[i];
|
|
619
|
-
let currentResult = results[i];
|
|
620
|
-
if (currentResult.statusCode.isNotGood())
|
|
621
|
-
throw new common_1.UaError(currentResult.statusCode);
|
|
622
|
-
for (let item of currentResult.references) {
|
|
623
|
-
let nodeId = item.nodeId.getNodeId();
|
|
624
|
-
let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
|
|
625
|
-
if (null == nodeId || null === typeDefinition)
|
|
626
|
-
continue;
|
|
627
|
-
this._browseResults.push({
|
|
628
|
-
fromNodeId: currentNodeId,
|
|
629
|
-
nodeId: nodeId,
|
|
630
|
-
nodeClass: (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified,
|
|
631
|
-
browseName: (item.browseName) ? item.browseName : "",
|
|
632
|
-
displayName: (item.displayName) ? item.displayName : common_1.UaLocalizedText.nullText,
|
|
633
|
-
referenceTypeId: (item.referenceTypeId) ? item.referenceTypeId : common_1.UaNodeId.nullNodeId,
|
|
634
|
-
isForward: item.isForward,
|
|
635
|
-
typeDefinitionId: typeDefinition
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
if (currentResult.continuationPoint) {
|
|
639
|
-
this._continuationPointToBrowse.push({
|
|
640
|
-
nodeId: currentNodeId,
|
|
641
|
-
continuationPoint: currentResult.continuationPoint
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
}
|
|
612
|
+
read(nodeIds, client) {
|
|
613
|
+
const _super = Object.create(null, {
|
|
614
|
+
read: { get: () => super.read }
|
|
645
615
|
});
|
|
646
|
-
}
|
|
647
|
-
_browseContinuationPoints(client) {
|
|
648
616
|
return __awaiter(this, void 0, void 0, function* () {
|
|
649
|
-
|
|
650
|
-
let
|
|
651
|
-
let
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
let results = yield client.browseNext(continuationPoints, false);
|
|
656
|
-
for (let i = 0; i < cpsToBrowse.length; ++i) {
|
|
657
|
-
let currentNodeId = cpsToBrowse[i].nodeId;
|
|
658
|
-
let currentResult = results[i];
|
|
659
|
-
if (currentResult.statusCode.isNotGood())
|
|
660
|
-
throw new common_1.UaError(currentResult.statusCode);
|
|
661
|
-
for (let item of currentResult.references) {
|
|
662
|
-
let nodeId = item.nodeId.getNodeId();
|
|
663
|
-
let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
|
|
664
|
-
if (null == nodeId || null === typeDefinition)
|
|
665
|
-
continue;
|
|
666
|
-
this._browseResults.push({
|
|
667
|
-
fromNodeId: currentNodeId,
|
|
668
|
-
nodeId: nodeId,
|
|
669
|
-
nodeClass: (item.nodeClass) ? item.nodeClass : opcua_webapi_1.NodeClass.Unspecified,
|
|
670
|
-
browseName: (item.browseName) ? item.browseName : "",
|
|
671
|
-
displayName: (item.displayName) ? item.displayName : common_1.UaLocalizedText.nullText,
|
|
672
|
-
referenceTypeId: (item.referenceTypeId) ? item.referenceTypeId : common_1.UaNodeId.nullNodeId,
|
|
673
|
-
isForward: item.isForward,
|
|
674
|
-
typeDefinitionId: typeDefinition
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
if (currentResult.continuationPoint) {
|
|
678
|
-
this._continuationPointToBrowse.push({
|
|
679
|
-
nodeId: currentNodeId,
|
|
680
|
-
continuationPoint: currentResult.continuationPoint
|
|
681
|
-
});
|
|
617
|
+
let nodes = yield _super.read.call(this, nodeIds, client);
|
|
618
|
+
let objectNodes = [];
|
|
619
|
+
for (let item of nodes) {
|
|
620
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
|
|
621
|
+
objectNodes.push(item);
|
|
682
622
|
}
|
|
683
623
|
}
|
|
624
|
+
return objectNodes;
|
|
684
625
|
});
|
|
685
626
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
for (let item of this._browseResults) {
|
|
692
|
-
let result = ret.get(item.fromNodeId.toString());
|
|
693
|
-
if (!result) {
|
|
694
|
-
result = {
|
|
695
|
-
nodeId: item.fromNodeId,
|
|
696
|
-
links: []
|
|
697
|
-
};
|
|
698
|
-
ret.set(item.fromNodeId.toString(), result);
|
|
699
|
-
}
|
|
700
|
-
result.links.push(new common_1.UaLink(item.nodeId, item.nodeClass, item.browseName, item.displayName, item.referenceTypeId, item.isForward));
|
|
701
|
-
}
|
|
702
|
-
this._readResults = Array.from(ret.values());
|
|
627
|
+
}
|
|
628
|
+
exports.UaObjectReader = UaObjectReader;
|
|
629
|
+
class UaTypeReader extends UaNodeReader {
|
|
630
|
+
constructor() {
|
|
631
|
+
super(true, true, true, true, false);
|
|
703
632
|
}
|
|
704
|
-
|
|
633
|
+
read(nodeIds, client) {
|
|
634
|
+
const _super = Object.create(null, {
|
|
635
|
+
read: { get: () => super.read }
|
|
636
|
+
});
|
|
705
637
|
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
let
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}
|
|
715
|
-
if (linkedNodesToRead.length == 0)
|
|
716
|
-
return;
|
|
717
|
-
let nodesToRead = [];
|
|
718
|
-
for (let item of linkedNodesToRead) {
|
|
719
|
-
nodesToRead.push(new common_1.UaReadValueId(item.targetId, opcua_webapi_1.Attributes.Description));
|
|
720
|
-
}
|
|
721
|
-
let dataValues = yield client.read(nodesToRead);
|
|
722
|
-
for (let i = 0; i < linkedNodesToRead.length; ++i) {
|
|
723
|
-
if (dataValues[i].statusCode.isGood()) {
|
|
724
|
-
linkedNodesToRead[i].description = dataValues[i].value.toLocalizedText();
|
|
638
|
+
let nodes = yield _super.read.call(this, nodeIds, client);
|
|
639
|
+
let typeNodes = [];
|
|
640
|
+
for (let item of nodes) {
|
|
641
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
|
|
642
|
+
item.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
|
|
643
|
+
item.nodeClass == opcua_webapi_1.NodeClass.DataType ||
|
|
644
|
+
item.nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
645
|
+
typeNodes.push(item);
|
|
725
646
|
}
|
|
726
647
|
}
|
|
648
|
+
return typeNodes;
|
|
727
649
|
});
|
|
728
650
|
}
|
|
729
651
|
}
|
|
730
|
-
exports.
|
|
652
|
+
exports.UaTypeReader = UaTypeReader;
|