opcua-webapi-ts 1.1.5 → 1.1.7
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/UaDataTypeDictionary.js +38 -91
- package/dist/cjs/client/utils/UaNodeReader.js +459 -530
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +37 -29
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +37 -29
- 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/UaDataTypeDictionary.d.ts +3 -6
- package/dist/client/utils/UaDataTypeDictionary.js +38 -91
- package/dist/client/utils/UaNodeReader.d.ts +45 -73
- package/dist/client/utils/UaNodeReader.js +459 -530
- package/dist/client/utils/UaObjectTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaObjectTypeDictionary.js +37 -29
- package/dist/client/utils/UaReferenceTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaReferenceTypeDictionary.js +37 -29
- 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,179 +9,356 @@ 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
|
+
});
|
|
181
341
|
}
|
|
182
|
-
|
|
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
|
+
});
|
|
357
|
+
}
|
|
358
|
+
_readTypes(references, nodes, client) {
|
|
183
359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
360
|
let typesToRead = [];
|
|
361
|
+
let needReadAttributes = this._returnAttributes || this._returnDescription;
|
|
185
362
|
for (let item of references) {
|
|
186
363
|
if (item.nodeClass != opcua_webapi_1.NodeClass.ObjectType &&
|
|
187
364
|
item.nodeClass != opcua_webapi_1.NodeClass.DataType &&
|
|
@@ -192,42 +369,50 @@ class UaNodeReaderBase {
|
|
|
192
369
|
}
|
|
193
370
|
if (0 == typesToRead.length)
|
|
194
371
|
return;
|
|
195
|
-
let
|
|
196
|
-
|
|
197
|
-
nodesToRead
|
|
198
|
-
|
|
199
|
-
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.
|
|
200
|
-
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
|
|
201
|
-
}
|
|
202
|
-
if (this._returnDescription) {
|
|
372
|
+
let dataValues = [];
|
|
373
|
+
if (needReadAttributes) {
|
|
374
|
+
let nodesToRead = [];
|
|
375
|
+
for (let item of typesToRead) {
|
|
376
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
|
|
203
377
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
378
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
379
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
|
|
380
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
|
|
381
|
+
}
|
|
204
382
|
}
|
|
383
|
+
dataValues = yield client.read(nodesToRead);
|
|
205
384
|
}
|
|
206
|
-
let dataValues = yield client.read(nodesToRead);
|
|
207
385
|
for (let i = 0; i < typesToRead.length; ++i) {
|
|
208
|
-
let
|
|
209
|
-
|
|
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
|
-
}
|
|
215
|
-
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
216
|
-
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
217
|
-
let isAbstract = dataValues[dataIndex].value.toBoolean();
|
|
218
|
-
if (null == isAbstract)
|
|
219
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
386
|
+
let isAbstract = false;
|
|
387
|
+
let description = undefined;
|
|
220
388
|
let dataType = common_1.UaNodeId.nullNodeId;
|
|
221
389
|
let valueRank = -1;
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
valueRank = dataValues[dataIndex + 2].value.toNumber();
|
|
229
|
-
if (null == dataType || null == valueRank)
|
|
390
|
+
if (needReadAttributes) {
|
|
391
|
+
let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
|
|
392
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
393
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
394
|
+
isAbstract = dataValues[dataIndex].value.toBoolean();
|
|
395
|
+
if (null == isAbstract)
|
|
230
396
|
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
397
|
+
dataIndex++;
|
|
398
|
+
if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
|
|
399
|
+
description = dataValues[dataIndex].value.toLocalizedText();
|
|
400
|
+
if (null == description)
|
|
401
|
+
description = undefined;
|
|
402
|
+
}
|
|
403
|
+
dataIndex++;
|
|
404
|
+
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
405
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
406
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
407
|
+
dataType = dataValues[dataIndex].value.toNodeId();
|
|
408
|
+
dataIndex++;
|
|
409
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
410
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
411
|
+
valueRank = dataValues[dataIndex].value.toNumber();
|
|
412
|
+
dataIndex++;
|
|
413
|
+
if (null == dataType || null == valueRank)
|
|
414
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
415
|
+
}
|
|
231
416
|
}
|
|
232
417
|
let typeNode;
|
|
233
418
|
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ObjectType) {
|
|
@@ -242,23 +427,15 @@ class UaNodeReaderBase {
|
|
|
242
427
|
else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
243
428
|
typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
|
|
244
429
|
}
|
|
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
|
-
}
|
|
430
|
+
if (this._returnDescription && description) {
|
|
431
|
+
typeNode.description = description;
|
|
252
432
|
}
|
|
253
433
|
typeNode.refToParent = typesToRead[i].referenceTypeId;
|
|
254
|
-
|
|
255
|
-
parentId: typesToRead[i].fromNodeId,
|
|
256
|
-
node: typeNode
|
|
257
|
-
});
|
|
434
|
+
nodes.set(typeNode.nodeId.toString(), typeNode);
|
|
258
435
|
}
|
|
259
436
|
});
|
|
260
437
|
}
|
|
261
|
-
_readObjects(references, client) {
|
|
438
|
+
_readObjects(references, nodes, client) {
|
|
262
439
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
440
|
let objectsToRead = [];
|
|
264
441
|
for (let item of references) {
|
|
@@ -270,38 +447,43 @@ class UaNodeReaderBase {
|
|
|
270
447
|
return;
|
|
271
448
|
let nodesToRead = [];
|
|
272
449
|
for (let item of objectsToRead) {
|
|
273
|
-
|
|
450
|
+
if (this._returnAttributes) {
|
|
451
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier));
|
|
452
|
+
}
|
|
274
453
|
if (this._returnDescription) {
|
|
275
454
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
276
455
|
}
|
|
277
456
|
}
|
|
278
|
-
let dataValues =
|
|
457
|
+
let dataValues = [];
|
|
458
|
+
if (nodesToRead.length != 0) {
|
|
459
|
+
dataValues = yield client.read(nodesToRead);
|
|
460
|
+
}
|
|
279
461
|
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;
|
|
462
|
+
let dataIndex = (this._returnAttributes && this._returnDescription) ? i * 2 : i;
|
|
283
463
|
let eventNotifier = 0;
|
|
284
|
-
|
|
464
|
+
let description = undefined;
|
|
465
|
+
if (this._returnAttributes && dataValues[dataIndex].statusCode.isGood()) {
|
|
285
466
|
eventNotifier = dataValues[dataIndex].value.toNumber();
|
|
467
|
+
if (null == eventNotifier)
|
|
468
|
+
eventNotifier = 0;
|
|
469
|
+
dataIndex++;
|
|
470
|
+
}
|
|
471
|
+
if (this._returnDescription && dataValues[dataIndex].statusCode.isGood()) {
|
|
472
|
+
description = dataValues[dataIndex].value.toLocalizedText();
|
|
473
|
+
if (null == description)
|
|
474
|
+
description = undefined;
|
|
475
|
+
dataIndex++;
|
|
286
476
|
}
|
|
287
477
|
let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
|
|
288
478
|
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
|
-
}
|
|
479
|
+
if (this._returnDescription && description) {
|
|
480
|
+
objectNode.description = description;
|
|
296
481
|
}
|
|
297
|
-
|
|
298
|
-
parentId: objectsToRead[i].fromNodeId,
|
|
299
|
-
node: objectNode
|
|
300
|
-
});
|
|
482
|
+
nodes.set(objectNode.nodeId.toString(), objectNode);
|
|
301
483
|
}
|
|
302
484
|
});
|
|
303
485
|
}
|
|
304
|
-
_readVariables(references, client) {
|
|
486
|
+
_readVariables(references, nodes, client) {
|
|
305
487
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
488
|
let variablesToRead = [];
|
|
307
489
|
let nodeIds = [];
|
|
@@ -313,418 +495,165 @@ class UaNodeReaderBase {
|
|
|
313
495
|
}
|
|
314
496
|
if (0 == nodeIds.length)
|
|
315
497
|
return;
|
|
316
|
-
let results =
|
|
317
|
-
|
|
498
|
+
let results = [];
|
|
499
|
+
if (this._returnAttributes) {
|
|
500
|
+
results = yield client.readVariableAttributes(nodeIds);
|
|
501
|
+
}
|
|
502
|
+
let variablesToReadValue = [];
|
|
318
503
|
for (let i = 0; i < variablesToRead.length; ++i) {
|
|
319
|
-
let variableNode
|
|
320
|
-
this.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
504
|
+
let variableNode;
|
|
505
|
+
if (this._returnAttributes) {
|
|
506
|
+
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);
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
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);
|
|
510
|
+
}
|
|
511
|
+
nodes.set(variableNode.nodeId.toString(), variableNode);
|
|
512
|
+
if (this._returnValue || (UaNodeReader.s_variablesNameToRead.has(variableNode.browseName))) {
|
|
513
|
+
variablesToReadValue.push(variableNode);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (variablesToReadValue.length != 0) {
|
|
517
|
+
let valuesToRead = [];
|
|
518
|
+
for (let item of variablesToReadValue) {
|
|
519
|
+
valuesToRead.push(item.nodeId);
|
|
520
|
+
}
|
|
328
521
|
let values = yield client.readValues(valuesToRead);
|
|
329
522
|
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;
|
|
523
|
+
let variableNode = nodes.get(valuesToRead[i].toString());
|
|
524
|
+
variableNode.dataValue = values[i];
|
|
334
525
|
}
|
|
335
526
|
}
|
|
336
527
|
});
|
|
337
528
|
}
|
|
338
|
-
_readMethods(references, client) {
|
|
529
|
+
_readMethods(references, nodes, client) {
|
|
339
530
|
return __awaiter(this, void 0, void 0, function* () {
|
|
531
|
+
let methodsToRead = [];
|
|
340
532
|
for (let item of references) {
|
|
341
533
|
if (item.nodeClass != opcua_webapi_1.NodeClass.Method)
|
|
342
534
|
continue;
|
|
343
|
-
|
|
344
|
-
this._readResults.set(methodNode.nodeId.toString(), {
|
|
345
|
-
parentId: item.fromNodeId,
|
|
346
|
-
node: methodNode
|
|
347
|
-
});
|
|
535
|
+
methodsToRead.push(item);
|
|
348
536
|
}
|
|
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())
|
|
537
|
+
if (0 == methodsToRead.length)
|
|
392
538
|
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);
|
|
403
|
-
}
|
|
404
|
-
else if (this._continuationPointToBrowse.length != 0) {
|
|
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)
|
|
433
|
-
return;
|
|
434
|
-
let nodeIds = [];
|
|
435
539
|
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
|
-
});
|
|
540
|
+
if (this._returnDescription) {
|
|
541
|
+
for (let item of methodsToRead) {
|
|
542
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
464
543
|
}
|
|
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
544
|
}
|
|
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);
|
|
545
|
+
let dataValues = [];
|
|
546
|
+
if (nodesToRead.length != 0) {
|
|
547
|
+
dataValues = yield client.read(nodesToRead);
|
|
484
548
|
}
|
|
485
|
-
|
|
486
|
-
let
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
continue;
|
|
495
|
-
browseResult.typeDefinitionId = results[i].references[0].nodeId.getNodeId();
|
|
549
|
+
for (let i = 0; i < methodsToRead.length; ++i) {
|
|
550
|
+
let methodNode = new common_1.UaMethod(methodsToRead[i].nodeId, methodsToRead[i].browseName, methodsToRead[i].displayName);
|
|
551
|
+
if (this._returnDescription) {
|
|
552
|
+
if (dataValues[i].statusCode.isGood()) {
|
|
553
|
+
let description = dataValues[i].value.toLocalizedText();
|
|
554
|
+
if (null == description)
|
|
555
|
+
description = undefined;
|
|
556
|
+
methodNode.description = description;
|
|
557
|
+
}
|
|
496
558
|
}
|
|
559
|
+
nodes.set(methodNode.nodeId.toString(), methodNode);
|
|
497
560
|
}
|
|
498
|
-
this._browseResults = Array.from(browseResults.values());
|
|
499
|
-
this._isRootNodeRead = true;
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
exports.UaNodeReader = UaNodeReader;
|
|
504
|
-
class UaNodeChildReader extends UaNodeReaderBase {
|
|
505
|
-
constructor(nodeIds, returnDescription, returnVariables, returnMethod) {
|
|
506
|
-
super((returnDescription) ? returnDescription : false, (returnVariables) ? returnVariables : false, (returnMethod) ? returnMethod : false);
|
|
507
|
-
if (nodeIds.length == 0)
|
|
508
|
-
this._finished = true;
|
|
509
|
-
this._nodeIds = new Set;
|
|
510
|
-
for (let item of nodeIds) {
|
|
511
|
-
this._nodeIds.add(item.toString());
|
|
512
|
-
this._nodesToBrowse.push({
|
|
513
|
-
nodeId: item,
|
|
514
|
-
nodeClassToReturn: opcua_webapi_1.NodeClass.Object | opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType
|
|
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
561
|
});
|
|
525
562
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
563
|
+
_buildNodeTree(referenceResult, nodes) {
|
|
564
|
+
let parentNode = nodes.get(referenceResult.nodeId.toString());
|
|
565
|
+
if (null == parentNode)
|
|
566
|
+
return;
|
|
567
|
+
for (let item of referenceResult.references) {
|
|
568
|
+
let childNode = nodes.get(item.nodeId.toString());
|
|
569
|
+
if (!childNode)
|
|
570
|
+
continue;
|
|
571
|
+
if (opcua_webapi_1.NodeClass.Object == parentNode.nodeClass) {
|
|
572
|
+
let parent = parentNode;
|
|
573
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass ||
|
|
574
|
+
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
575
|
+
parent.addMember(childNode);
|
|
576
|
+
}
|
|
532
577
|
}
|
|
533
|
-
else if (
|
|
534
|
-
|
|
578
|
+
else if (opcua_webapi_1.NodeClass.Variable == parentNode.nodeClass) {
|
|
579
|
+
let parent = parentNode;
|
|
580
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
581
|
+
parent.addMember(childNode);
|
|
582
|
+
}
|
|
535
583
|
}
|
|
536
|
-
else if (
|
|
537
|
-
|
|
584
|
+
else if (opcua_webapi_1.NodeClass.Method == parentNode.nodeClass) {
|
|
585
|
+
let parent = parentNode;
|
|
586
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
587
|
+
parent.addMember(childNode);
|
|
588
|
+
}
|
|
538
589
|
}
|
|
539
|
-
else {
|
|
540
|
-
|
|
590
|
+
else if (opcua_webapi_1.NodeClass.ObjectType == parentNode.nodeClass) {
|
|
591
|
+
let parent = parentNode;
|
|
592
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass ||
|
|
593
|
+
opcua_webapi_1.NodeClass.Method == childNode.nodeClass) {
|
|
594
|
+
parent.addMember(childNode);
|
|
595
|
+
}
|
|
541
596
|
}
|
|
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);
|
|
597
|
+
else if (opcua_webapi_1.NodeClass.VariableType == parentNode.nodeClass) {
|
|
598
|
+
let parent = parentNode;
|
|
599
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
600
|
+
parent.addMember(childNode);
|
|
601
|
+
}
|
|
556
602
|
}
|
|
557
|
-
else {
|
|
558
|
-
|
|
559
|
-
|
|
603
|
+
else if (opcua_webapi_1.NodeClass.DataType == parentNode.nodeClass) {
|
|
604
|
+
let parent = parentNode;
|
|
605
|
+
if (opcua_webapi_1.NodeClass.Variable == childNode.nodeClass) {
|
|
606
|
+
parent.setEnumVariable(childNode);
|
|
607
|
+
}
|
|
560
608
|
}
|
|
561
|
-
result.children.push(item[1].node);
|
|
562
609
|
}
|
|
563
|
-
return [...ret.values()];
|
|
564
610
|
}
|
|
565
611
|
}
|
|
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 : [];
|
|
612
|
+
exports.UaNodeReader = UaNodeReader;
|
|
613
|
+
UaNodeReader.s_variableTypeWithoutMember = null;
|
|
614
|
+
UaNodeReader.s_variablesNameToRead = null;
|
|
615
|
+
class UaObjectReader extends UaNodeReader {
|
|
616
|
+
constructor(returnDescription, returnValue) {
|
|
617
|
+
super(returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, true, true, true, returnValue !== null && returnValue !== void 0 ? returnValue : false);
|
|
604
618
|
}
|
|
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
|
-
}
|
|
619
|
+
read(nodeIds, client) {
|
|
620
|
+
const _super = Object.create(null, {
|
|
621
|
+
read: { get: () => super.read }
|
|
645
622
|
});
|
|
646
|
-
}
|
|
647
|
-
_browseContinuationPoints(client) {
|
|
648
623
|
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
|
-
});
|
|
624
|
+
let nodes = yield _super.read.call(this, nodeIds, client);
|
|
625
|
+
let objectNodes = [];
|
|
626
|
+
for (let item of nodes) {
|
|
627
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
|
|
628
|
+
objectNodes.push(item);
|
|
682
629
|
}
|
|
683
630
|
}
|
|
631
|
+
return objectNodes;
|
|
684
632
|
});
|
|
685
633
|
}
|
|
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());
|
|
634
|
+
}
|
|
635
|
+
exports.UaObjectReader = UaObjectReader;
|
|
636
|
+
class UaTypeReader extends UaNodeReader {
|
|
637
|
+
constructor() {
|
|
638
|
+
super(true, true, true, true, false);
|
|
703
639
|
}
|
|
704
|
-
|
|
640
|
+
read(nodeIds, client) {
|
|
641
|
+
const _super = Object.create(null, {
|
|
642
|
+
read: { get: () => super.read }
|
|
643
|
+
});
|
|
705
644
|
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();
|
|
645
|
+
let nodes = yield _super.read.call(this, nodeIds, client);
|
|
646
|
+
let typeNodes = [];
|
|
647
|
+
for (let item of nodes) {
|
|
648
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
|
|
649
|
+
item.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
|
|
650
|
+
item.nodeClass == opcua_webapi_1.NodeClass.DataType ||
|
|
651
|
+
item.nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
652
|
+
typeNodes.push(item);
|
|
725
653
|
}
|
|
726
654
|
}
|
|
655
|
+
return typeNodes;
|
|
727
656
|
});
|
|
728
657
|
}
|
|
729
658
|
}
|
|
730
|
-
exports.
|
|
659
|
+
exports.UaTypeReader = UaTypeReader;
|