opcua-webapi-ts 1.1.22 → 1.1.24
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 +1 -1
- package/dist/cjs/client/utils/UaModelling.js +2 -2
- package/dist/cjs/client/utils/UaNodeBrowser.js +7 -36
- package/dist/cjs/client/utils/UaNodeReader.js +120 -76
- package/dist/cjs/client/utils/UaNodeSerializer.js +166 -0
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +1 -1
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +1 -1
- package/dist/cjs/client/utils/index.js +1 -0
- package/dist/cjs/common/nodes/UaMethod.js +22 -0
- package/dist/cjs/common/nodes/UaNode.js +0 -13
- package/dist/cjs/common/nodes/UaObject.js +4 -4
- package/dist/cjs/common/nodes/UaObjectType.js +3 -5
- package/dist/cjs/common/nodes/UaVariable.js +14 -7
- package/dist/client/utils/UaDataTypeDictionary.js +1 -1
- package/dist/client/utils/UaModelling.js +2 -2
- package/dist/client/utils/UaNodeBrowser.d.ts +3 -8
- package/dist/client/utils/UaNodeBrowser.js +7 -36
- package/dist/client/utils/UaNodeReader.d.ts +15 -8
- package/dist/client/utils/UaNodeReader.js +120 -76
- package/dist/client/utils/UaNodeSerializer.d.ts +14 -0
- package/dist/client/utils/UaNodeSerializer.js +166 -0
- package/dist/client/utils/UaObjectTypeDictionary.js +1 -1
- package/dist/client/utils/UaReferenceTypeDictionary.js +1 -1
- package/dist/client/utils/index.d.ts +1 -0
- package/dist/client/utils/index.js +1 -0
- package/dist/common/nodes/UaMethod.d.ts +1 -0
- package/dist/common/nodes/UaMethod.js +22 -0
- package/dist/common/nodes/UaNode.d.ts +0 -5
- package/dist/common/nodes/UaNode.js +0 -13
- package/dist/common/nodes/UaObject.js +4 -4
- package/dist/common/nodes/UaObjectType.js +3 -5
- package/dist/common/nodes/UaVariable.d.ts +4 -1
- package/dist/common/nodes/UaVariable.js +14 -7
- package/package.json +1 -1
|
@@ -50,7 +50,7 @@ class UaDataTypeDictionary {
|
|
|
50
50
|
return;
|
|
51
51
|
// Read child type
|
|
52
52
|
let nodeIdsToBrowse = [];
|
|
53
|
-
let nodeReader = new __1.UaNodeReader(this._client, false, needToReadEnumValue, false, false,
|
|
53
|
+
let nodeReader = new __1.UaNodeReader(this._client, false, needToReadEnumValue, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasProperty), false, false, false, false, false);
|
|
54
54
|
let nodes = yield nodeReader.readByReferences(referencesToRead);
|
|
55
55
|
for (let node of nodes) {
|
|
56
56
|
if (opcua_webapi_1.NodeClass.DataType != node.nodeClass)
|
|
@@ -98,7 +98,7 @@ class UaModelling {
|
|
|
98
98
|
return null;
|
|
99
99
|
if (objectType.isObjectMemberRead)
|
|
100
100
|
return objectType;
|
|
101
|
-
let typeMemberBrowser = new __1.UaNodeBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object
|
|
101
|
+
let typeMemberBrowser = new __1.UaNodeBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object);
|
|
102
102
|
yield typeMemberBrowser.browse();
|
|
103
103
|
let browseMemberResults = typeMemberBrowser.results();
|
|
104
104
|
let instanceNodes = new Map();
|
|
@@ -113,7 +113,7 @@ class UaModelling {
|
|
|
113
113
|
for (let node of instanceNodes) {
|
|
114
114
|
memberObjectIds.push(node[1].nodeId);
|
|
115
115
|
}
|
|
116
|
-
let modellingRuleBrowser = new __1.UaNodeBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object
|
|
116
|
+
let modellingRuleBrowser = new __1.UaNodeBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object);
|
|
117
117
|
yield modellingRuleBrowser.browse();
|
|
118
118
|
let browseModellingRuleResults = modellingRuleBrowser.results();
|
|
119
119
|
for (let item of browseModellingRuleResults) {
|
|
@@ -9,17 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UaTypeBrowser = exports.
|
|
12
|
+
exports.UaTypeBrowser = exports.UaObjectBrowser = exports.UaNodeBrowser = void 0;
|
|
13
13
|
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
15
|
class UaNodeBrowser {
|
|
16
|
-
constructor(client, nodeIds, referenceType, nodeClassToReturn,
|
|
16
|
+
constructor(client, nodeIds, referenceType, nodeClassToReturn, maxNodesPerBrowse, maxReferencesPerNode) {
|
|
17
17
|
this._client = client;
|
|
18
18
|
this._nodesToBrowse = [];
|
|
19
19
|
this._referenceType = referenceType;
|
|
20
20
|
this._nodeClassToReturn = nodeClassToReturn;
|
|
21
21
|
this._continuationPointToBrowse = [];
|
|
22
|
-
this._returnDescription = returnDescription !== null && returnDescription !== void 0 ? returnDescription : false;
|
|
23
22
|
this._maxNodesPerBrowse = (null == maxNodesPerBrowse || maxNodesPerBrowse <= 0) ? 50 : maxNodesPerBrowse;
|
|
24
23
|
this._maxReferencesPerNode = (null == maxReferencesPerNode || maxReferencesPerNode < 0) ? 50 : maxReferencesPerNode;
|
|
25
24
|
this._readResults = new Map();
|
|
@@ -63,7 +62,7 @@ class UaNodeBrowser {
|
|
|
63
62
|
return results;
|
|
64
63
|
}
|
|
65
64
|
isFinish() {
|
|
66
|
-
return (this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0);
|
|
65
|
+
return ((this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0)) || 0 == this._nodeClassToReturn;
|
|
67
66
|
}
|
|
68
67
|
_browseNodes() {
|
|
69
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -101,8 +100,6 @@ class UaNodeBrowser {
|
|
|
101
100
|
continuationPoint: currentResult.continuationPoint
|
|
102
101
|
});
|
|
103
102
|
}
|
|
104
|
-
if (this._returnDescription)
|
|
105
|
-
yield this._readDescriptions(newReferences);
|
|
106
103
|
}
|
|
107
104
|
});
|
|
108
105
|
}
|
|
@@ -141,46 +138,20 @@ class UaNodeBrowser {
|
|
|
141
138
|
continuationPoint: currentResult.continuationPoint
|
|
142
139
|
});
|
|
143
140
|
}
|
|
144
|
-
if (this._returnDescription)
|
|
145
|
-
yield this._readDescriptions(newReferences);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
_readDescriptions(references) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
if (references.length === 0)
|
|
152
|
-
return;
|
|
153
|
-
let nodesToRead = [];
|
|
154
|
-
for (let item of references) {
|
|
155
|
-
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
156
|
-
}
|
|
157
|
-
let dataValues = yield this._client.read(nodesToRead);
|
|
158
|
-
for (let i = 0; i < references.length; ++i) {
|
|
159
|
-
if (dataValues[i].statusCode.isGood()) {
|
|
160
|
-
let description = dataValues[i].value.toLocalizedText();
|
|
161
|
-
if (description)
|
|
162
|
-
references[i].description = description;
|
|
163
|
-
}
|
|
164
141
|
}
|
|
165
142
|
});
|
|
166
143
|
}
|
|
167
144
|
}
|
|
168
145
|
exports.UaNodeBrowser = UaNodeBrowser;
|
|
169
146
|
class UaObjectBrowser extends UaNodeBrowser {
|
|
170
|
-
constructor(client, nodeIds,
|
|
171
|
-
super(client, nodeIds,
|
|
147
|
+
constructor(client, nodeIds, referenceType = common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences)) {
|
|
148
|
+
super(client, nodeIds, referenceType, opcua_webapi_1.NodeClass.Object, 20);
|
|
172
149
|
}
|
|
173
150
|
}
|
|
174
151
|
exports.UaObjectBrowser = UaObjectBrowser;
|
|
175
|
-
class UaLinkBrowser extends UaNodeBrowser {
|
|
176
|
-
constructor(client, nodeIds, returnDescription) {
|
|
177
|
-
super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.NonHierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.UaLinkBrowser = UaLinkBrowser;
|
|
181
152
|
class UaTypeBrowser extends UaNodeBrowser {
|
|
182
|
-
constructor(client, nodeIds
|
|
183
|
-
super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType | opcua_webapi_1.NodeClass.ReferenceType,
|
|
153
|
+
constructor(client, nodeIds) {
|
|
154
|
+
super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.ObjectType | opcua_webapi_1.NodeClass.VariableType | opcua_webapi_1.NodeClass.DataType | opcua_webapi_1.NodeClass.ReferenceType, 20);
|
|
184
155
|
}
|
|
185
156
|
}
|
|
186
157
|
exports.UaTypeBrowser = UaTypeBrowser;
|
|
@@ -9,17 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UaTypeReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
|
|
12
|
+
exports.UaTypeReader = exports.UaFullObjectReader = exports.UaObjectReader = exports.UaNodeReader = void 0;
|
|
13
13
|
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
15
|
const UaNodeBrowser_1 = require("./UaNodeBrowser");
|
|
16
16
|
class UaNodeReader {
|
|
17
|
-
constructor(client, returnDescription, returnVariable, returnMethod,
|
|
17
|
+
constructor(client, returnDescription, returnVariable, returnMethod, referenceTypeToReturn, returnObjectAttributes, returnVariableAttributes, returnVariableValue, returnPropertyAttributes, returnPropertyValue) {
|
|
18
18
|
this._client = client;
|
|
19
|
-
this._returnDescription =
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
19
|
+
this._returnDescription = returnDescription;
|
|
20
|
+
this._referenceTypeToReturn = referenceTypeToReturn;
|
|
21
|
+
this._returnObjectAttributes = returnObjectAttributes;
|
|
22
|
+
this._returnVariableAttributes = returnVariableAttributes;
|
|
23
|
+
this._returnVariableValue = returnVariableValue;
|
|
24
|
+
this._returnPropertyAttributes = returnPropertyAttributes;
|
|
25
|
+
this._returnPropertyValue = returnPropertyValue;
|
|
23
26
|
this._nodeClassToReturn = 0;
|
|
24
27
|
if (returnVariable)
|
|
25
28
|
this._nodeClassToReturn += opcua_webapi_1.NodeClass.Variable;
|
|
@@ -59,17 +62,15 @@ class UaNodeReader {
|
|
|
59
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
63
|
if (references.length == 0)
|
|
61
64
|
return [];
|
|
62
|
-
let referencesToRead = [];
|
|
63
65
|
let nodeIdsToBrowse = [];
|
|
64
66
|
let nodeIdsSet = new Set();
|
|
65
67
|
for (let item of references) {
|
|
66
68
|
if (nodeIdsSet.has(item.nodeId.toString()))
|
|
67
69
|
continue;
|
|
68
|
-
referencesToRead.push(item);
|
|
69
70
|
nodeIdsToBrowse.push(item.nodeId);
|
|
70
71
|
nodeIdsSet.add(item.nodeId.toString());
|
|
71
72
|
}
|
|
72
|
-
let nodeReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, nodeIdsToBrowse, this._referenceTypeToReturn, this._nodeClassToReturn
|
|
73
|
+
let nodeReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, nodeIdsToBrowse, this._referenceTypeToReturn, this._nodeClassToReturn);
|
|
73
74
|
yield nodeReferenceBrowser.browse();
|
|
74
75
|
let childReferences = nodeReferenceBrowser.results();
|
|
75
76
|
let childNodesToBrowse = [];
|
|
@@ -86,7 +87,7 @@ class UaNodeReader {
|
|
|
86
87
|
}
|
|
87
88
|
let variableReferences = [];
|
|
88
89
|
if (childNodesToBrowse.length != 0) {
|
|
89
|
-
let childReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.
|
|
90
|
+
let childReferenceBrowser = new UaNodeBrowser_1.UaNodeBrowser(this._client, childNodesToBrowse, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Variable);
|
|
90
91
|
yield childReferenceBrowser.browse();
|
|
91
92
|
variableReferences = childReferenceBrowser.results();
|
|
92
93
|
}
|
|
@@ -194,7 +195,6 @@ class UaNodeReader {
|
|
|
194
195
|
_readTypes(references, nodes) {
|
|
195
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
196
197
|
let typesToRead = [];
|
|
197
|
-
let needReadAttributes = this._returnAttributes || this._returnDescription;
|
|
198
198
|
for (let item of references) {
|
|
199
199
|
if (item.nodeClass != opcua_webapi_1.NodeClass.ObjectType &&
|
|
200
200
|
item.nodeClass != opcua_webapi_1.NodeClass.DataType &&
|
|
@@ -206,49 +206,45 @@ class UaNodeReader {
|
|
|
206
206
|
if (0 == typesToRead.length)
|
|
207
207
|
return;
|
|
208
208
|
let dataValues = [];
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
|
|
217
|
-
}
|
|
209
|
+
let nodesToRead = [];
|
|
210
|
+
for (let item of typesToRead) {
|
|
211
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.IsAbstract));
|
|
212
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.Description));
|
|
213
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
214
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.DataType));
|
|
215
|
+
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.ValueRank));
|
|
218
216
|
}
|
|
219
|
-
dataValues = yield this._client.read(nodesToRead);
|
|
220
217
|
}
|
|
218
|
+
dataValues = yield this._client.read(nodesToRead);
|
|
221
219
|
for (let i = 0; i < typesToRead.length; ++i) {
|
|
222
220
|
let isAbstract = false;
|
|
223
221
|
let description = undefined;
|
|
224
222
|
let dataType = common_1.UaNodeId.nullNodeId;
|
|
225
223
|
let valueRank = -1;
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
let dataIndex = (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) ? i * 4 : i * 2;
|
|
225
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
226
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
227
|
+
isAbstract = dataValues[dataIndex].value.toBoolean();
|
|
228
|
+
if (null == isAbstract)
|
|
229
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
230
|
+
dataIndex++;
|
|
231
|
+
if (dataValues[dataIndex].statusCode.isGood()) {
|
|
232
|
+
description = dataValues[dataIndex].value.toLocalizedText();
|
|
233
|
+
if (null == description)
|
|
234
|
+
description = undefined;
|
|
235
|
+
}
|
|
236
|
+
dataIndex++;
|
|
237
|
+
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.VariableType) {
|
|
228
238
|
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
229
239
|
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
230
|
-
|
|
231
|
-
if (null == isAbstract)
|
|
232
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
240
|
+
dataType = dataValues[dataIndex].value.toNodeId();
|
|
233
241
|
dataIndex++;
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
description = undefined;
|
|
238
|
-
}
|
|
242
|
+
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
243
|
+
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
244
|
+
valueRank = dataValues[dataIndex].value.toNumber();
|
|
239
245
|
dataIndex++;
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
243
|
-
dataType = dataValues[dataIndex].value.toNodeId();
|
|
244
|
-
dataIndex++;
|
|
245
|
-
if (dataValues[dataIndex].statusCode.isNotGood())
|
|
246
|
-
throw new common_1.UaError(dataValues[dataIndex].statusCode);
|
|
247
|
-
valueRank = dataValues[dataIndex].value.toNumber();
|
|
248
|
-
dataIndex++;
|
|
249
|
-
if (null == dataType || null == valueRank)
|
|
250
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
251
|
-
}
|
|
246
|
+
if (null == dataType || null == valueRank)
|
|
247
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
252
248
|
}
|
|
253
249
|
let typeNode;
|
|
254
250
|
if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ObjectType) {
|
|
@@ -263,10 +259,9 @@ class UaNodeReader {
|
|
|
263
259
|
else if (typesToRead[i].nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
264
260
|
typeNode = new common_1.UaReferenceType(typesToRead[i].nodeId, typesToRead[i].browseName, typesToRead[i].displayName, isAbstract, common_1.UaLocalizedText.nullText, false);
|
|
265
261
|
}
|
|
266
|
-
if (
|
|
262
|
+
if (description) {
|
|
267
263
|
typeNode.description = description;
|
|
268
264
|
}
|
|
269
|
-
typeNode.refToParent = typesToRead[i].referenceTypeId;
|
|
270
265
|
nodes.set(typeNode.nodeId.toString(), typeNode);
|
|
271
266
|
}
|
|
272
267
|
});
|
|
@@ -283,7 +278,7 @@ class UaNodeReader {
|
|
|
283
278
|
return;
|
|
284
279
|
let nodesToRead = [];
|
|
285
280
|
for (let item of objectsToRead) {
|
|
286
|
-
if (this.
|
|
281
|
+
if (this._returnObjectAttributes) {
|
|
287
282
|
nodesToRead.push(new common_1.UaReadValueId(item.nodeId, opcua_webapi_1.Attributes.EventNotifier));
|
|
288
283
|
}
|
|
289
284
|
if (this._returnDescription) {
|
|
@@ -295,10 +290,10 @@ class UaNodeReader {
|
|
|
295
290
|
dataValues = yield this._client.read(nodesToRead);
|
|
296
291
|
}
|
|
297
292
|
for (let i = 0; i < objectsToRead.length; ++i) {
|
|
298
|
-
let dataIndex = (this.
|
|
293
|
+
let dataIndex = (this._returnObjectAttributes && this._returnDescription) ? i * 2 : i;
|
|
299
294
|
let eventNotifier = 0;
|
|
300
295
|
let description = undefined;
|
|
301
|
-
if (this.
|
|
296
|
+
if (this._returnObjectAttributes && dataValues[dataIndex].statusCode.isGood()) {
|
|
302
297
|
eventNotifier = dataValues[dataIndex].value.toNumber();
|
|
303
298
|
if (null == eventNotifier)
|
|
304
299
|
eventNotifier = 0;
|
|
@@ -311,7 +306,6 @@ class UaNodeReader {
|
|
|
311
306
|
dataIndex++;
|
|
312
307
|
}
|
|
313
308
|
let objectNode = new common_1.UaObject(objectsToRead[i].nodeId, objectsToRead[i].browseName, objectsToRead[i].displayName, eventNotifier, objectsToRead[i].typeDefinitionId);
|
|
314
|
-
objectNode.refToParent = objectsToRead[i].referenceTypeId;
|
|
315
309
|
if (this._returnDescription && description) {
|
|
316
310
|
objectNode.description = description;
|
|
317
311
|
}
|
|
@@ -322,30 +316,56 @@ class UaNodeReader {
|
|
|
322
316
|
_readVariables(references, nodes) {
|
|
323
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
324
318
|
let variablesToRead = [];
|
|
325
|
-
let
|
|
319
|
+
let nodeIdsToReadAttributes = [];
|
|
320
|
+
let variablesToReadValue = [];
|
|
326
321
|
for (let item of references) {
|
|
327
322
|
if (item.nodeClass != opcua_webapi_1.NodeClass.Variable)
|
|
328
323
|
continue;
|
|
329
324
|
variablesToRead.push(item);
|
|
330
|
-
nodeIds.push(item.nodeId);
|
|
331
325
|
}
|
|
332
|
-
if (0 ==
|
|
326
|
+
if (0 == variablesToRead.length)
|
|
333
327
|
return;
|
|
328
|
+
let hasPropertyId = common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasProperty);
|
|
329
|
+
let attributeIndexMap = new Map();
|
|
330
|
+
for (let i = 0; i < variablesToRead.length; ++i) {
|
|
331
|
+
let item = variablesToRead[i];
|
|
332
|
+
if (item.referenceTypeId.equal(hasPropertyId)) {
|
|
333
|
+
if (this._returnPropertyAttributes) {
|
|
334
|
+
attributeIndexMap.set(i, nodeIdsToReadAttributes.length);
|
|
335
|
+
nodeIdsToReadAttributes.push(item.nodeId);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
if (this._returnVariableAttributes) {
|
|
340
|
+
attributeIndexMap.set(i, nodeIdsToReadAttributes.length);
|
|
341
|
+
nodeIdsToReadAttributes.push(item.nodeId);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
334
345
|
let results = [];
|
|
335
|
-
if (
|
|
336
|
-
results = yield this._client.readVariableAttributes(
|
|
346
|
+
if (nodeIdsToReadAttributes.length != 0) {
|
|
347
|
+
results = yield this._client.readVariableAttributes(nodeIdsToReadAttributes);
|
|
337
348
|
}
|
|
338
|
-
let variablesToReadValue = [];
|
|
339
349
|
for (let i = 0; i < variablesToRead.length; ++i) {
|
|
340
350
|
let variableNode;
|
|
341
|
-
|
|
342
|
-
|
|
351
|
+
let attributeIndex = attributeIndexMap.get(i);
|
|
352
|
+
if (null != attributeIndex) {
|
|
353
|
+
variableNode = new common_1.UaVariable(variablesToRead[i].nodeId, variablesToRead[i].browseName, variablesToRead[i].displayName, results[attributeIndex].dataType, results[attributeIndex].valueRank, results[attributeIndex].accessLevel, results[attributeIndex].userAccessLevel, results[attributeIndex].historizing, variablesToRead[i].typeDefinitionId);
|
|
343
354
|
}
|
|
344
355
|
else {
|
|
345
356
|
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);
|
|
346
357
|
}
|
|
347
358
|
nodes.set(variableNode.nodeId.toString(), variableNode);
|
|
348
|
-
if (
|
|
359
|
+
if (variablesToRead[i].referenceTypeId.equal(hasPropertyId)) {
|
|
360
|
+
variableNode.isProperty = true;
|
|
361
|
+
}
|
|
362
|
+
if (this._returnVariableValue && !variableNode.isProperty) {
|
|
363
|
+
variablesToReadValue.push(variableNode);
|
|
364
|
+
}
|
|
365
|
+
else if (this._returnPropertyValue && variableNode.isProperty) {
|
|
366
|
+
variablesToReadValue.push(variableNode);
|
|
367
|
+
}
|
|
368
|
+
else if (UaNodeReader.s_variablesNameToRead.has(variableNode.browseName)) {
|
|
349
369
|
variablesToReadValue.push(variableNode);
|
|
350
370
|
}
|
|
351
371
|
}
|
|
@@ -449,46 +469,70 @@ exports.UaNodeReader = UaNodeReader;
|
|
|
449
469
|
UaNodeReader.s_variableTypeWithoutMember = null;
|
|
450
470
|
UaNodeReader.s_variablesNameToRead = null;
|
|
451
471
|
class UaObjectReader extends UaNodeReader {
|
|
452
|
-
constructor(client,
|
|
453
|
-
super(client, returnDescription
|
|
472
|
+
constructor(client, returnVariable = true, returnMethod = true, returnDescription = false) {
|
|
473
|
+
super(client, returnDescription, returnVariable, returnMethod, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, true, false, false, true);
|
|
454
474
|
}
|
|
455
|
-
|
|
475
|
+
readByReferences(references) {
|
|
456
476
|
const _super = Object.create(null, {
|
|
457
|
-
|
|
477
|
+
readByReferences: { get: () => super.readByReferences }
|
|
458
478
|
});
|
|
459
479
|
return __awaiter(this, void 0, void 0, function* () {
|
|
460
|
-
let
|
|
461
|
-
let
|
|
462
|
-
for (let item of nodes) {
|
|
480
|
+
let objectReferences = [];
|
|
481
|
+
for (let item of references) {
|
|
463
482
|
if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
|
|
464
|
-
|
|
483
|
+
objectReferences.push(item);
|
|
465
484
|
}
|
|
466
485
|
}
|
|
467
|
-
|
|
486
|
+
if (0 == objectReferences.length)
|
|
487
|
+
return [];
|
|
488
|
+
return yield _super.readByReferences.call(this, objectReferences);
|
|
468
489
|
});
|
|
469
490
|
}
|
|
470
491
|
}
|
|
471
492
|
exports.UaObjectReader = UaObjectReader;
|
|
493
|
+
class UaFullObjectReader extends UaNodeReader {
|
|
494
|
+
constructor(client, returnDescription = true, returnValue = false) {
|
|
495
|
+
super(client, returnDescription, true, true, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), true, true, returnValue, true, returnValue);
|
|
496
|
+
}
|
|
497
|
+
readByReferences(references) {
|
|
498
|
+
const _super = Object.create(null, {
|
|
499
|
+
readByReferences: { get: () => super.readByReferences }
|
|
500
|
+
});
|
|
501
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
let objectReferences = [];
|
|
503
|
+
for (let item of references) {
|
|
504
|
+
if (item.nodeClass == opcua_webapi_1.NodeClass.Object) {
|
|
505
|
+
objectReferences.push(item);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (0 == objectReferences.length)
|
|
509
|
+
return [];
|
|
510
|
+
return yield _super.readByReferences.call(this, objectReferences);
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
exports.UaFullObjectReader = UaFullObjectReader;
|
|
472
515
|
class UaTypeReader extends UaNodeReader {
|
|
473
|
-
constructor(client) {
|
|
474
|
-
super(client, true, true, true, true, false);
|
|
516
|
+
constructor(client, returnDescription = false) {
|
|
517
|
+
super(client, returnDescription, true, true, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, true, false, true, false);
|
|
475
518
|
}
|
|
476
|
-
|
|
519
|
+
readByReferences(references) {
|
|
477
520
|
const _super = Object.create(null, {
|
|
478
|
-
|
|
521
|
+
readByReferences: { get: () => super.readByReferences }
|
|
479
522
|
});
|
|
480
523
|
return __awaiter(this, void 0, void 0, function* () {
|
|
481
|
-
let
|
|
482
|
-
let
|
|
483
|
-
for (let item of nodes) {
|
|
524
|
+
let typeReferences = [];
|
|
525
|
+
for (let item of references) {
|
|
484
526
|
if (item.nodeClass == opcua_webapi_1.NodeClass.ObjectType ||
|
|
485
527
|
item.nodeClass == opcua_webapi_1.NodeClass.VariableType ||
|
|
486
528
|
item.nodeClass == opcua_webapi_1.NodeClass.DataType ||
|
|
487
529
|
item.nodeClass == opcua_webapi_1.NodeClass.ReferenceType) {
|
|
488
|
-
|
|
530
|
+
typeReferences.push(item);
|
|
489
531
|
}
|
|
490
532
|
}
|
|
491
|
-
|
|
533
|
+
if (0 == typeReferences.length)
|
|
534
|
+
return [];
|
|
535
|
+
return yield _super.readByReferences.call(this, typeReferences);
|
|
492
536
|
});
|
|
493
537
|
}
|
|
494
538
|
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UaObjectTypeSerializer = exports.UaObjectSerializer = void 0;
|
|
4
|
+
class UaObjectSerializer {
|
|
5
|
+
constructor(objectDictionary, dataTypeDictionary) {
|
|
6
|
+
this._objectDictionary = objectDictionary;
|
|
7
|
+
this._dataTypeDictionary = dataTypeDictionary;
|
|
8
|
+
}
|
|
9
|
+
toJson(object) {
|
|
10
|
+
let variableMembers = object.variableMembers;
|
|
11
|
+
let methodMembers = object.methodMembers;
|
|
12
|
+
let objectType = this._objectDictionary.getObjectType(object.typeDefinitionId);
|
|
13
|
+
let variables = [];
|
|
14
|
+
let properties = [];
|
|
15
|
+
let methods = [];
|
|
16
|
+
for (let variable of variableMembers) {
|
|
17
|
+
if (variable.isProperty) {
|
|
18
|
+
let propertyJson = {
|
|
19
|
+
name: variable.browseName,
|
|
20
|
+
displayName: variable.displayName.text,
|
|
21
|
+
value: (variable.value) ? variable.value.value : null
|
|
22
|
+
};
|
|
23
|
+
properties.push(propertyJson);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
let dataType = this._dataTypeDictionary.getDataType(variable.dataType);
|
|
27
|
+
if (!dataType)
|
|
28
|
+
continue;
|
|
29
|
+
let variableJson = {
|
|
30
|
+
id: variable.nodeId.toString(),
|
|
31
|
+
name: variable.browseName,
|
|
32
|
+
displayName: variable.displayName.text,
|
|
33
|
+
dataType: dataType.browseName,
|
|
34
|
+
accessLevel: variable.accessLevel,
|
|
35
|
+
historizing: (variable.historizing) ? variable.historizing : undefined,
|
|
36
|
+
valueRank: (-1 != variable.valueRank) ? variable.valueRank : undefined
|
|
37
|
+
};
|
|
38
|
+
variables.push(variableJson);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (let method of methodMembers) {
|
|
42
|
+
let inputArguments = [];
|
|
43
|
+
let outputArguments = [];
|
|
44
|
+
if (method.inputArguments) {
|
|
45
|
+
for (let inputArgument of method.inputArguments) {
|
|
46
|
+
let dataType = this._dataTypeDictionary.getDataType(inputArgument.dataType);
|
|
47
|
+
if (!dataType)
|
|
48
|
+
continue;
|
|
49
|
+
let inputArgumentJson = {
|
|
50
|
+
name: inputArgument.name,
|
|
51
|
+
dataType: dataType.browseName
|
|
52
|
+
};
|
|
53
|
+
inputArguments.push(inputArgumentJson);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (method.outputArguments) {
|
|
57
|
+
for (let outputArgument of method.outputArguments) {
|
|
58
|
+
let dataType = this._dataTypeDictionary.getDataType(outputArgument.dataType);
|
|
59
|
+
if (!dataType)
|
|
60
|
+
continue;
|
|
61
|
+
let outputArgumentJson = {
|
|
62
|
+
name: outputArgument.name,
|
|
63
|
+
dataType: dataType.browseName
|
|
64
|
+
};
|
|
65
|
+
outputArguments.push(outputArgumentJson);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
let methodJson = {
|
|
69
|
+
id: method.nodeId.toString(),
|
|
70
|
+
name: method.browseName,
|
|
71
|
+
displayName: method.displayName.text,
|
|
72
|
+
inputArguments: (inputArguments.length > 0) ? inputArguments : undefined,
|
|
73
|
+
outputArguments: (outputArguments.length > 0) ? outputArguments : undefined
|
|
74
|
+
};
|
|
75
|
+
methods.push(methodJson);
|
|
76
|
+
}
|
|
77
|
+
let ret = {
|
|
78
|
+
id: object.nodeId.toString(),
|
|
79
|
+
name: object.browseName,
|
|
80
|
+
displayName: object.displayName.text,
|
|
81
|
+
description: (object.description) ? object.description.text : undefined,
|
|
82
|
+
objectType: objectType.browseName,
|
|
83
|
+
variables: (variables.length > 0) ? variables : undefined,
|
|
84
|
+
properties: (properties.length > 0) ? properties : undefined,
|
|
85
|
+
methods: (methods.length > 0) ? methods : undefined
|
|
86
|
+
};
|
|
87
|
+
return ret;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.UaObjectSerializer = UaObjectSerializer;
|
|
91
|
+
class UaObjectTypeSerializer {
|
|
92
|
+
constructor(dataTypeDictionary) {
|
|
93
|
+
this._dataTypeDictionary = dataTypeDictionary;
|
|
94
|
+
}
|
|
95
|
+
toJson(objectType) {
|
|
96
|
+
let variableMembers = objectType.variableMembers;
|
|
97
|
+
let methodMembers = objectType.methodMembers;
|
|
98
|
+
let variables = [];
|
|
99
|
+
let properties = [];
|
|
100
|
+
let methods = [];
|
|
101
|
+
for (let variable of variableMembers) {
|
|
102
|
+
let dataType = this._dataTypeDictionary.getDataType(variable.dataType);
|
|
103
|
+
if (!dataType)
|
|
104
|
+
continue;
|
|
105
|
+
let variableJson = {
|
|
106
|
+
id: variable.nodeId.toString(),
|
|
107
|
+
name: variable.browseName,
|
|
108
|
+
displayName: variable.displayName.text,
|
|
109
|
+
dataType: dataType.browseName,
|
|
110
|
+
accessLevel: variable.accessLevel,
|
|
111
|
+
historizing: (variable.historizing) ? variable.historizing : undefined,
|
|
112
|
+
valueRank: (-1 != variable.valueRank) ? variable.valueRank : undefined
|
|
113
|
+
};
|
|
114
|
+
if (variable.isProperty) {
|
|
115
|
+
properties.push(variableJson);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
variables.push(variableJson);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (let method of methodMembers) {
|
|
122
|
+
let inputArguments = [];
|
|
123
|
+
let outputArguments = [];
|
|
124
|
+
for (let inputArgument of method.inputArguments) {
|
|
125
|
+
let dataType = this._dataTypeDictionary.getDataType(inputArgument.dataType);
|
|
126
|
+
if (!dataType)
|
|
127
|
+
continue;
|
|
128
|
+
let inputArgumentJson = {
|
|
129
|
+
name: inputArgument.name,
|
|
130
|
+
dataType: dataType.browseName
|
|
131
|
+
};
|
|
132
|
+
inputArguments.push(inputArgumentJson);
|
|
133
|
+
}
|
|
134
|
+
for (let outputArgument of method.outputArguments) {
|
|
135
|
+
let dataType = this._dataTypeDictionary.getDataType(outputArgument.dataType);
|
|
136
|
+
if (!dataType)
|
|
137
|
+
continue;
|
|
138
|
+
let outputArgumentJson = {
|
|
139
|
+
name: outputArgument.name,
|
|
140
|
+
dataType: dataType.browseName
|
|
141
|
+
};
|
|
142
|
+
outputArguments.push(outputArgumentJson);
|
|
143
|
+
}
|
|
144
|
+
let methodJson = {
|
|
145
|
+
id: method.nodeId.toString(),
|
|
146
|
+
name: method.browseName,
|
|
147
|
+
displayName: method.displayName.text,
|
|
148
|
+
inputArguments: (inputArguments.length > 0) ? inputArguments : undefined,
|
|
149
|
+
outputArguments: (outputArguments.length > 0) ? outputArguments : undefined
|
|
150
|
+
};
|
|
151
|
+
methods.push(methodJson);
|
|
152
|
+
}
|
|
153
|
+
let ret = {
|
|
154
|
+
id: objectType.nodeId.toString(),
|
|
155
|
+
name: objectType.browseName,
|
|
156
|
+
displayName: objectType.displayName.text,
|
|
157
|
+
description: (objectType.description) ? objectType.description.text : undefined,
|
|
158
|
+
objectType: objectType.browseName,
|
|
159
|
+
variables: (variables.length > 0) ? variables : undefined,
|
|
160
|
+
properties: (properties.length > 0) ? properties : undefined,
|
|
161
|
+
methods: (methods.length > 0) ? methods : undefined
|
|
162
|
+
};
|
|
163
|
+
return ret;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.UaObjectTypeSerializer = UaObjectTypeSerializer;
|
|
@@ -48,7 +48,7 @@ class UaObjectTypeDictionary {
|
|
|
48
48
|
return;
|
|
49
49
|
// Read child type
|
|
50
50
|
let nodeIdsToBrowse = [];
|
|
51
|
-
let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, false, false);
|
|
51
|
+
let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, false, false, false, true);
|
|
52
52
|
let nodes = yield nodeReader.readByReferences(referencesToRead);
|
|
53
53
|
for (let node of nodes) {
|
|
54
54
|
if (opcua_webapi_1.NodeClass.ObjectType != node.nodeClass)
|
|
@@ -48,7 +48,7 @@ class UaReferenceTypeDictionary {
|
|
|
48
48
|
return;
|
|
49
49
|
// Read child type
|
|
50
50
|
let nodeIdsToBrowse = [];
|
|
51
|
-
let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, false, false);
|
|
51
|
+
let nodeReader = new UaNodeReader_1.UaNodeReader(this._client, false, false, false, common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), false, false, false, false, false);
|
|
52
52
|
let nodes = yield nodeReader.readByReferences(referencesToRead);
|
|
53
53
|
for (let node of nodes) {
|
|
54
54
|
if (opcua_webapi_1.NodeClass.ReferenceType != node.nodeClass)
|