opcua-webapi-ts 1.1.16 → 1.1.18
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/UaWebClient.js +2 -92
- package/dist/cjs/client/utils/UaDataTypeDictionary.js +11 -11
- package/dist/cjs/client/utils/UaModelling.js +129 -0
- package/dist/cjs/client/utils/UaNodeReader.js +66 -60
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +11 -11
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +11 -11
- package/dist/cjs/common/nodes/UaDataType.js +2 -2
- package/dist/cjs/common/nodes/UaNode.js +27 -6
- package/dist/cjs/common/nodes/UaObjectType.js +7 -0
- package/dist/cjs/common/payload/UaDeleteNodesItem.js +1 -1
- package/dist/cjs/common/types/UaModellingRule.js +10 -0
- package/dist/cjs/common/types/index.js +1 -1
- package/dist/client/UaWebClient.d.ts +7 -5
- package/dist/client/UaWebClient.js +2 -92
- package/dist/client/utils/UaDataTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaDataTypeDictionary.js +11 -11
- package/dist/client/utils/UaModelling.d.ts +13 -0
- package/dist/client/utils/UaModelling.js +129 -0
- package/dist/client/utils/UaNodeReader.d.ts +17 -12
- package/dist/client/utils/UaNodeReader.js +66 -60
- package/dist/client/utils/UaObjectTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaObjectTypeDictionary.js +11 -11
- package/dist/client/utils/UaReferenceTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaReferenceTypeDictionary.js +11 -11
- package/dist/common/nodes/UaAttributes.d.ts +0 -4
- package/dist/common/nodes/UaDataType.d.ts +1 -1
- package/dist/common/nodes/UaDataType.js +2 -2
- package/dist/common/nodes/UaNode.d.ts +10 -6
- package/dist/common/nodes/UaNode.js +27 -6
- package/dist/common/nodes/UaObjectType.d.ts +3 -0
- package/dist/common/nodes/UaObjectType.js +7 -0
- package/dist/common/payload/UaDeleteNodesItem.d.ts +1 -1
- package/dist/common/payload/UaDeleteNodesItem.js +1 -1
- package/dist/common/types/UaModellingRule.d.ts +6 -0
- package/dist/common/types/UaModellingRule.js +10 -0
- package/dist/common/types/index.d.ts +1 -1
- package/dist/common/types/index.js +1 -1
- package/package.json +1 -1
|
@@ -95,7 +95,6 @@ class UaWebClient {
|
|
|
95
95
|
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.NodeClass),
|
|
96
96
|
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.BrowseName),
|
|
97
97
|
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.DisplayName),
|
|
98
|
-
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.WriteMask)
|
|
99
98
|
];
|
|
100
99
|
if (returnDescription) {
|
|
101
100
|
nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.Description));
|
|
@@ -114,16 +113,13 @@ class UaWebClient {
|
|
|
114
113
|
common_1.UaVariantType.QualifiedName != browseNameValue.type ||
|
|
115
114
|
common_1.UaVariantType.LocalizedText != displayNameValue.type)
|
|
116
115
|
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
117
|
-
let writeMaskValue = (results[3].statusCode.isGood() &&
|
|
118
|
-
results[3].value.type == common_1.UaVariantType.UInt32) ? results[3].value : undefined;
|
|
119
116
|
let descriptionValue = (returnDescription &&
|
|
120
|
-
results[
|
|
121
|
-
results[
|
|
117
|
+
results[3].statusCode.isGood() &&
|
|
118
|
+
results[3].value.type == common_1.UaVariantType.LocalizedText) ? results[3].value : undefined;
|
|
122
119
|
let ret = {
|
|
123
120
|
nodeClass: nodeClassValue.value,
|
|
124
121
|
browseName: browseNameValue.value,
|
|
125
122
|
displayName: displayNameValue.value,
|
|
126
|
-
writeMask: (writeMaskValue) ? writeMaskValue.value : 0,
|
|
127
123
|
description: (descriptionValue) ? descriptionValue.value : undefined
|
|
128
124
|
};
|
|
129
125
|
return ret;
|
|
@@ -183,72 +179,6 @@ class UaWebClient {
|
|
|
183
179
|
return ret;
|
|
184
180
|
});
|
|
185
181
|
}
|
|
186
|
-
readMethodArguments(nodeId) {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
let ret = { inputArguments: [], outputArguments: [] };
|
|
189
|
-
let browseResult = yield this.browseChild(nodeId, opcua_webapi_1.NodeClass.Variable);
|
|
190
|
-
let inputArgumentsId = null;
|
|
191
|
-
let outputArgumentsId = null;
|
|
192
|
-
for (let item of browseResult.results) {
|
|
193
|
-
if ("InputArguments" == item.browseName)
|
|
194
|
-
inputArgumentsId = item.nodeId.getNodeId();
|
|
195
|
-
if ("OutputArguments" == item.browseName)
|
|
196
|
-
outputArgumentsId = item.nodeId.getNodeId();
|
|
197
|
-
}
|
|
198
|
-
let nodesToRead = [];
|
|
199
|
-
if (inputArgumentsId)
|
|
200
|
-
nodesToRead.push(inputArgumentsId);
|
|
201
|
-
if (outputArgumentsId)
|
|
202
|
-
nodesToRead.push(outputArgumentsId);
|
|
203
|
-
if (0 == nodesToRead.length)
|
|
204
|
-
return ret;
|
|
205
|
-
let readResults = yield this.readValues(nodesToRead);
|
|
206
|
-
let argsArr = [];
|
|
207
|
-
for (let item of readResults) {
|
|
208
|
-
if (item.statusCode.isNotGood() ||
|
|
209
|
-
common_1.UaVariantType.ExtensionObject != item.value.type ||
|
|
210
|
-
common_1.UaArrayType.Array != item.value.arrayType)
|
|
211
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
|
|
212
|
-
let extensionObjects = item.value.value;
|
|
213
|
-
let args = [];
|
|
214
|
-
for (let itemL2 of extensionObjects) {
|
|
215
|
-
let arg = common_1.UaArgument.fromExtensionObject(itemL2);
|
|
216
|
-
if (!arg)
|
|
217
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
|
|
218
|
-
args.push(arg);
|
|
219
|
-
}
|
|
220
|
-
argsArr.push(args);
|
|
221
|
-
}
|
|
222
|
-
if (inputArgumentsId && outputArgumentsId) {
|
|
223
|
-
ret.inputArguments = argsArr[0];
|
|
224
|
-
ret.outputArguments = argsArr[1];
|
|
225
|
-
}
|
|
226
|
-
else if (inputArgumentsId) {
|
|
227
|
-
ret.inputArguments = argsArr[0];
|
|
228
|
-
}
|
|
229
|
-
else if (outputArgumentsId) {
|
|
230
|
-
ret.outputArguments = argsArr[0];
|
|
231
|
-
}
|
|
232
|
-
return ret;
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
readObjectAttributes(nodeId) {
|
|
236
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
-
let nodesToRead = [
|
|
238
|
-
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.EventNotifier)
|
|
239
|
-
];
|
|
240
|
-
let results = yield this.read(nodesToRead);
|
|
241
|
-
if (results[0].statusCode.isNotGood())
|
|
242
|
-
throw new common_1.UaError(results[0].statusCode);
|
|
243
|
-
let eventNotifierValue = results[0].value;
|
|
244
|
-
if (common_1.UaVariantType.Byte != eventNotifierValue.type)
|
|
245
|
-
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadNodeAttributesInvalid));
|
|
246
|
-
let ret = {
|
|
247
|
-
eventNotifier: eventNotifierValue.value
|
|
248
|
-
};
|
|
249
|
-
return ret;
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
182
|
methodCall(objectId, methodId, inputArguments) {
|
|
253
183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
184
|
let inputs = [];
|
|
@@ -369,26 +299,6 @@ class UaWebClient {
|
|
|
369
299
|
return ret;
|
|
370
300
|
});
|
|
371
301
|
}
|
|
372
|
-
addObject(parentNodeId, typeDefinitionNodeId, displayName, browseName, referenceTypeId) {
|
|
373
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
374
|
-
let objectAttributes = new common_1.UaObjectAttributes(displayName);
|
|
375
|
-
let extensionObject = objectAttributes.toExtensionObject();
|
|
376
|
-
let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(typeDefinitionNodeId), null, browseName, referenceTypeId);
|
|
377
|
-
let results = yield this.addNodes([nodeToAdd]);
|
|
378
|
-
if (results[0].statusCode.isNotGood())
|
|
379
|
-
throw new common_1.UaError(results[0].statusCode);
|
|
380
|
-
let newNodeId = results[0].addedNodeId;
|
|
381
|
-
return newNodeId;
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
deleteNode(nodeId) {
|
|
385
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
-
let nodeToDelete = new common_1.UaDeleteNodesItem(nodeId);
|
|
387
|
-
let results = yield this.deleteNodes([nodeToDelete]);
|
|
388
|
-
if (results[0].isNotGood())
|
|
389
|
-
throw new common_1.UaError(results[0]);
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
302
|
// Native APIs
|
|
393
303
|
browse(nodesToBrowse, maxReferencesPerNode, view, additionalParameters) {
|
|
394
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -14,16 +14,16 @@ const opcua_webapi_1 = require("opcua-webapi");
|
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
15
|
const __1 = require("../..");
|
|
16
16
|
class UaDataTypeDictionary {
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this._client = client;
|
|
18
19
|
this._dataTypes = new Map;
|
|
19
|
-
this._returnAllAttributes = (null == simpleMode) ? false : !simpleMode;
|
|
20
20
|
let baseDataTypeId = new common_1.UaNodeId(common_1.DataTypeIds.BaseDataType);
|
|
21
21
|
this._dataTypes.set(baseDataTypeId.toString(), new common_1.UaDataType(baseDataTypeId, "BaseDataType", new common_1.UaLocalizedText("BaseDataType"), true));
|
|
22
22
|
}
|
|
23
|
-
read(
|
|
23
|
+
read() {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
let browser = new __1.UaChildBrowser([common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
|
|
26
|
-
yield this._read(browser
|
|
25
|
+
let browser = new __1.UaChildBrowser(this._client, [common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
|
|
26
|
+
yield this._read(browser);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
getDataType(nodeId) {
|
|
@@ -33,10 +33,10 @@ class UaDataTypeDictionary {
|
|
|
33
33
|
getDataTypes() {
|
|
34
34
|
return [...this._dataTypes.values()];
|
|
35
35
|
}
|
|
36
|
-
_read(browser
|
|
36
|
+
_read(browser) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
// Browse child type
|
|
39
|
-
yield browser.browse(
|
|
39
|
+
yield browser.browse();
|
|
40
40
|
let results = browser.results();
|
|
41
41
|
let referencesToRead = [];
|
|
42
42
|
let needToReadEnumValue = false;
|
|
@@ -50,8 +50,8 @@ class UaDataTypeDictionary {
|
|
|
50
50
|
return;
|
|
51
51
|
// Read child type
|
|
52
52
|
let nodeIdsToBrowse = [];
|
|
53
|
-
let nodeReader = new __1.UaNodeReader(this.
|
|
54
|
-
let nodes = yield nodeReader.readByReferences(referencesToRead
|
|
53
|
+
let nodeReader = new __1.UaNodeReader(this._client, false, needToReadEnumValue, false, false, true);
|
|
54
|
+
let nodes = yield nodeReader.readByReferences(referencesToRead);
|
|
55
55
|
for (let node of nodes) {
|
|
56
56
|
if (opcua_webapi_1.NodeClass.DataType != node.nodeClass)
|
|
57
57
|
continue;
|
|
@@ -71,8 +71,8 @@ class UaDataTypeDictionary {
|
|
|
71
71
|
return;
|
|
72
72
|
yield this.__delay(20);
|
|
73
73
|
// Continue to browse and read child type
|
|
74
|
-
let childBrowser = new __1.UaChildBrowser(nodeIdsToBrowse);
|
|
75
|
-
yield this._read(childBrowser
|
|
74
|
+
let childBrowser = new __1.UaChildBrowser(this._client, nodeIdsToBrowse);
|
|
75
|
+
yield this._read(childBrowser);
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
__delay(ms) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UaModelling = void 0;
|
|
13
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
|
+
const common_1 = require("../../common");
|
|
15
|
+
const __1 = require("../..");
|
|
16
|
+
class UaModelling {
|
|
17
|
+
constructor(client, objectTypeDictionary) {
|
|
18
|
+
this._client = client;
|
|
19
|
+
this._objectTypeDictionary = objectTypeDictionary;
|
|
20
|
+
}
|
|
21
|
+
getObjectTypeToAdd(objectTypeId) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
let objectType = yield this._readObjectMembers(objectTypeId);
|
|
24
|
+
if (!objectType)
|
|
25
|
+
return [];
|
|
26
|
+
let ret = [];
|
|
27
|
+
let objectMembers = objectType.objectMembers;
|
|
28
|
+
for (let item of objectMembers) {
|
|
29
|
+
if (item.modellingRule != common_1.UaModellingRule.PlaceHolder)
|
|
30
|
+
continue;
|
|
31
|
+
let childObjectType = this._objectTypeDictionary.getObjectType(item.typeDefinitionId);
|
|
32
|
+
if (!childObjectType)
|
|
33
|
+
continue;
|
|
34
|
+
ret.push(childObjectType);
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
addObject(parentNodeId, objectType, displayName, browseName) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
let objectAttributes = new __1.UaObjectAttributes(displayName);
|
|
42
|
+
let extensionObject = objectAttributes.toExtensionObject();
|
|
43
|
+
let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(objectType.nodeId), null, browseName !== null && browseName !== void 0 ? browseName : null, null);
|
|
44
|
+
let results = yield this._client.addNodes([nodeToAdd]);
|
|
45
|
+
if (results[0].statusCode.isNotGood())
|
|
46
|
+
throw new common_1.UaError(results[0].statusCode);
|
|
47
|
+
let newNodeId = results[0].addedNodeId;
|
|
48
|
+
return newNodeId;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
deleteNode(nodeId) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
let nodeToDelete = new common_1.UaDeleteNodesItem(nodeId);
|
|
54
|
+
let results = yield this._client.deleteNodes([nodeToDelete]);
|
|
55
|
+
if (results[0].isNotGood())
|
|
56
|
+
throw new common_1.UaError(results[0]);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getWriteMask(nodes) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
let nodesToRead = [];
|
|
62
|
+
for (let node of nodes) {
|
|
63
|
+
if (node.writeMask != null)
|
|
64
|
+
continue;
|
|
65
|
+
let nodeIdToRead = new common_1.UaReadValueId(node.nodeId, opcua_webapi_1.Attributes.UserWriteMask);
|
|
66
|
+
nodesToRead.push(nodeIdToRead);
|
|
67
|
+
}
|
|
68
|
+
if (0 == nodesToRead.length)
|
|
69
|
+
return;
|
|
70
|
+
let results = yield this._client.read(nodesToRead);
|
|
71
|
+
let index = 0;
|
|
72
|
+
for (let node of nodes) {
|
|
73
|
+
if (node.writeMask != null)
|
|
74
|
+
continue;
|
|
75
|
+
let result = results[index];
|
|
76
|
+
let writeMask = 0;
|
|
77
|
+
if (result.statusCode.isGood() &&
|
|
78
|
+
result.value.type == common_1.UaVariantType.UInt32) {
|
|
79
|
+
writeMask = result.value.value;
|
|
80
|
+
}
|
|
81
|
+
node.writeMask = writeMask;
|
|
82
|
+
index++;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
_readObjectMembers(objectTypeId) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
let objectType = this._objectTypeDictionary.getObjectType(objectTypeId);
|
|
89
|
+
if (!objectType)
|
|
90
|
+
return null;
|
|
91
|
+
if (objectType.isObjectMemberRead)
|
|
92
|
+
return objectType;
|
|
93
|
+
let typeMemberBrowser = new __1.UaNodeReferenceBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object, false);
|
|
94
|
+
yield typeMemberBrowser.browse();
|
|
95
|
+
let browseMemberResults = typeMemberBrowser.results();
|
|
96
|
+
let instanceNodes = new Map();
|
|
97
|
+
for (let item of browseMemberResults) {
|
|
98
|
+
for (let reference of item.references) {
|
|
99
|
+
if (reference.nodeClass != opcua_webapi_1.NodeClass.Object)
|
|
100
|
+
continue;
|
|
101
|
+
instanceNodes.set(reference.nodeId.toString(), new common_1.UaObject(reference.nodeId, reference.browseName, reference.displayName, 0, reference.typeDefinitionId));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
let memberObjectIds = [];
|
|
105
|
+
for (let node of instanceNodes) {
|
|
106
|
+
memberObjectIds.push(node[1].nodeId);
|
|
107
|
+
}
|
|
108
|
+
let modellingRuleBrowser = new __1.UaNodeReferenceBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object, false);
|
|
109
|
+
yield modellingRuleBrowser.browse();
|
|
110
|
+
let browseModellingRuleResults = modellingRuleBrowser.results();
|
|
111
|
+
for (let item of browseModellingRuleResults) {
|
|
112
|
+
let instanceNode = instanceNodes.get(item.nodeId.toString());
|
|
113
|
+
if (!instanceNode)
|
|
114
|
+
continue;
|
|
115
|
+
if (0 == item.references.length)
|
|
116
|
+
continue;
|
|
117
|
+
instanceNode.setModellingRule(item.references[0].nodeId);
|
|
118
|
+
}
|
|
119
|
+
for (let node of instanceNodes) {
|
|
120
|
+
if (node[1].modellingRule == common_1.UaModellingRule.None)
|
|
121
|
+
continue;
|
|
122
|
+
objectType.addMember(node[1]);
|
|
123
|
+
}
|
|
124
|
+
objectType.isObjectMemberRead = true;
|
|
125
|
+
return objectType;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.UaModelling = UaModelling;
|