opcua-webapi-ts 1.1.17 → 1.1.19
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 +95 -101
- package/dist/cjs/client/utils/UaDataTypeDictionary.js +11 -11
- package/dist/cjs/client/utils/UaModelling.js +137 -0
- package/dist/cjs/client/utils/UaNodeBrowser.js +186 -0
- package/dist/cjs/client/utils/UaNodeReader.js +38 -203
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +12 -11
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +12 -11
- package/dist/cjs/client/utils/index.js +2 -0
- 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/types/UaModellingRule.js +10 -0
- package/dist/cjs/common/types/index.js +1 -1
- package/dist/client/UaWebClient.d.ts +15 -6
- package/dist/client/UaWebClient.js +95 -101
- package/dist/client/utils/UaDataTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaDataTypeDictionary.js +11 -11
- package/dist/client/utils/UaModelling.d.ts +14 -0
- package/dist/client/utils/UaModelling.js +137 -0
- package/dist/client/utils/UaNodeBrowser.d.ts +34 -0
- package/dist/client/utils/UaNodeBrowser.js +186 -0
- package/dist/client/utils/UaNodeReader.d.ts +8 -39
- package/dist/client/utils/UaNodeReader.js +38 -203
- package/dist/client/utils/UaObjectTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaObjectTypeDictionary.js +12 -11
- package/dist/client/utils/UaReferenceTypeDictionary.d.ts +3 -3
- package/dist/client/utils/UaReferenceTypeDictionary.js +12 -11
- package/dist/client/utils/index.d.ts +2 -0
- package/dist/client/utils/index.js +2 -0
- 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/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 +2 -2
|
@@ -89,13 +89,28 @@ class UaWebClient {
|
|
|
89
89
|
throw new common_1.UaError(results[0]);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
+
methodCall(objectId, methodId, inputArguments) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
let inputs = [];
|
|
95
|
+
for (let item of inputArguments) {
|
|
96
|
+
inputs.push(common_1.UaPayloadMapper.variantToWebApi(item));
|
|
97
|
+
}
|
|
98
|
+
let methodsToCall = [
|
|
99
|
+
new common_2.UaCallMethodRequest(objectId, methodId, inputArguments)
|
|
100
|
+
];
|
|
101
|
+
let results = yield this.call(methodsToCall);
|
|
102
|
+
if (results[0].statusCode.isNotGood())
|
|
103
|
+
throw new common_1.UaError(results[0].statusCode);
|
|
104
|
+
let outputs = results[0].outputArguments;
|
|
105
|
+
return outputs;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
92
108
|
readNodeAttributes(nodeId, returnDescription) {
|
|
93
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
110
|
let nodesToRead = [
|
|
95
111
|
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.NodeClass),
|
|
96
112
|
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.BrowseName),
|
|
97
113
|
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.DisplayName),
|
|
98
|
-
new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.WriteMask)
|
|
99
114
|
];
|
|
100
115
|
if (returnDescription) {
|
|
101
116
|
nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.Description));
|
|
@@ -114,21 +129,79 @@ class UaWebClient {
|
|
|
114
129
|
common_1.UaVariantType.QualifiedName != browseNameValue.type ||
|
|
115
130
|
common_1.UaVariantType.LocalizedText != displayNameValue.type)
|
|
116
131
|
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
132
|
let descriptionValue = (returnDescription &&
|
|
120
|
-
results[
|
|
121
|
-
results[
|
|
133
|
+
results[3].statusCode.isGood() &&
|
|
134
|
+
results[3].value.type == common_1.UaVariantType.LocalizedText) ? results[3].value : undefined;
|
|
122
135
|
let ret = {
|
|
123
136
|
nodeClass: nodeClassValue.value,
|
|
124
137
|
browseName: browseNameValue.value,
|
|
125
138
|
displayName: displayNameValue.value,
|
|
126
|
-
writeMask: (writeMaskValue) ? writeMaskValue.value : 0,
|
|
127
139
|
description: (descriptionValue) ? descriptionValue.value : undefined
|
|
128
140
|
};
|
|
129
141
|
return ret;
|
|
130
142
|
});
|
|
131
143
|
}
|
|
144
|
+
readMethodArguments(nodeId) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
let ret = { inputArguments: [], outputArguments: [] };
|
|
147
|
+
let browseResult = yield this.browseChild(nodeId, opcua_webapi_1.NodeClass.Variable);
|
|
148
|
+
let inputArgumentsId = null;
|
|
149
|
+
let outputArgumentsId = null;
|
|
150
|
+
for (let item of browseResult.results) {
|
|
151
|
+
if ("InputArguments" == item.browseName)
|
|
152
|
+
inputArgumentsId = item.nodeId.getNodeId();
|
|
153
|
+
if ("OutputArguments" == item.browseName)
|
|
154
|
+
outputArgumentsId = item.nodeId.getNodeId();
|
|
155
|
+
}
|
|
156
|
+
let nodesToRead = [];
|
|
157
|
+
if (inputArgumentsId)
|
|
158
|
+
nodesToRead.push(inputArgumentsId);
|
|
159
|
+
if (outputArgumentsId)
|
|
160
|
+
nodesToRead.push(outputArgumentsId);
|
|
161
|
+
if (0 == nodesToRead.length)
|
|
162
|
+
return ret;
|
|
163
|
+
let readResults = yield this.readValues(nodesToRead);
|
|
164
|
+
let argsArr = [];
|
|
165
|
+
for (let item of readResults) {
|
|
166
|
+
if (item.statusCode.isNotGood() ||
|
|
167
|
+
common_1.UaVariantType.ExtensionObject != item.value.type ||
|
|
168
|
+
common_1.UaArrayType.Array != item.value.arrayType)
|
|
169
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
|
|
170
|
+
let extensionObjects = item.value.value;
|
|
171
|
+
let args = [];
|
|
172
|
+
for (let itemL2 of extensionObjects) {
|
|
173
|
+
let arg = common_1.UaArgument.fromExtensionObject(itemL2);
|
|
174
|
+
if (!arg)
|
|
175
|
+
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadInvalidArgument));
|
|
176
|
+
args.push(arg);
|
|
177
|
+
}
|
|
178
|
+
argsArr.push(args);
|
|
179
|
+
}
|
|
180
|
+
if (inputArgumentsId && outputArgumentsId) {
|
|
181
|
+
ret.inputArguments = argsArr[0];
|
|
182
|
+
ret.outputArguments = argsArr[1];
|
|
183
|
+
}
|
|
184
|
+
else if (inputArgumentsId) {
|
|
185
|
+
ret.inputArguments = argsArr[0];
|
|
186
|
+
}
|
|
187
|
+
else if (outputArgumentsId) {
|
|
188
|
+
ret.outputArguments = argsArr[0];
|
|
189
|
+
}
|
|
190
|
+
return ret;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
readObjectEventNotifier(nodeId) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
let nodesToRead = [];
|
|
196
|
+
nodesToRead.push(new common_1.UaReadValueId(nodeId, opcua_webapi_1.Attributes.EventNotifier));
|
|
197
|
+
let results = yield this.read(nodesToRead);
|
|
198
|
+
if (results[0].statusCode.isNotGood())
|
|
199
|
+
throw new common_1.UaError(results[0].statusCode);
|
|
200
|
+
if (common_1.UaVariantType.Byte == results[0].value.type)
|
|
201
|
+
return results[0].value.value;
|
|
202
|
+
return 0;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
132
205
|
readVariableAttributes(nodeIds) {
|
|
133
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
207
|
if (nodeIds.length == 0)
|
|
@@ -183,86 +256,26 @@ class UaWebClient {
|
|
|
183
256
|
return ret;
|
|
184
257
|
});
|
|
185
258
|
}
|
|
186
|
-
|
|
259
|
+
readWriteMasks(nodeIds) {
|
|
187
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
}
|
|
261
|
+
if (nodeIds.length == 0)
|
|
262
|
+
return [];
|
|
198
263
|
let nodesToRead = [];
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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];
|
|
264
|
+
for (let item of nodeIds) {
|
|
265
|
+
let nodeIdToRead = new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.UserWriteMask);
|
|
266
|
+
nodesToRead.push(nodeIdToRead);
|
|
231
267
|
}
|
|
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
268
|
let results = yield this.read(nodesToRead);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return ret;
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
methodCall(objectId, methodId, inputArguments) {
|
|
253
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
let inputs = [];
|
|
255
|
-
for (let item of inputArguments) {
|
|
256
|
-
inputs.push(common_1.UaPayloadMapper.variantToWebApi(item));
|
|
269
|
+
let writeMasks = [];
|
|
270
|
+
for (let result of results) {
|
|
271
|
+
if (result.statusCode.isGood() && result.value.type == common_1.UaVariantType.UInt32) {
|
|
272
|
+
writeMasks.push(result.value.value);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
writeMasks.push(0);
|
|
276
|
+
}
|
|
257
277
|
}
|
|
258
|
-
|
|
259
|
-
new common_2.UaCallMethodRequest(objectId, methodId, inputArguments)
|
|
260
|
-
];
|
|
261
|
-
let results = yield this.call(methodsToCall);
|
|
262
|
-
if (results[0].statusCode.isNotGood())
|
|
263
|
-
throw new common_1.UaError(results[0].statusCode);
|
|
264
|
-
let outputs = results[0].outputArguments;
|
|
265
|
-
return outputs;
|
|
278
|
+
return writeMasks;
|
|
266
279
|
});
|
|
267
280
|
}
|
|
268
281
|
getGeneratedEventType(typeId) {
|
|
@@ -369,26 +382,6 @@ class UaWebClient {
|
|
|
369
382
|
return ret;
|
|
370
383
|
});
|
|
371
384
|
}
|
|
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
385
|
// Native APIs
|
|
393
386
|
browse(nodesToBrowse, maxReferencesPerNode, view, additionalParameters) {
|
|
394
387
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -796,6 +789,7 @@ class UaWebClient {
|
|
|
796
789
|
response = yield this.api.addNodes(request, { signal: controller.signal });
|
|
797
790
|
}
|
|
798
791
|
catch (error) {
|
|
792
|
+
console.error(error);
|
|
799
793
|
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadCommunicationError));
|
|
800
794
|
}
|
|
801
795
|
finally {
|
|
@@ -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.
|
|
26
|
-
yield this._read(browser
|
|
25
|
+
let browser = new __1.UaTypeBrowser(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.
|
|
75
|
-
yield this._read(childBrowser
|
|
74
|
+
let childBrowser = new __1.UaTypeBrowser(this._client, nodeIdsToBrowse);
|
|
75
|
+
yield this._read(childBrowser);
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
__delay(ms) {
|
|
@@ -0,0 +1,137 @@
|
|
|
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) {
|
|
18
|
+
this._client = client;
|
|
19
|
+
}
|
|
20
|
+
getObjectTypeToAdd(objectTypeId, dictionary) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
let objectType = yield this._readObjectMembers(objectTypeId, dictionary);
|
|
23
|
+
if (!objectType)
|
|
24
|
+
return [];
|
|
25
|
+
let ret = [];
|
|
26
|
+
let objectMembers = objectType.objectMembers;
|
|
27
|
+
for (let item of objectMembers) {
|
|
28
|
+
if (item.modellingRule != common_1.UaModellingRule.PlaceHolder)
|
|
29
|
+
continue;
|
|
30
|
+
let childObjectType = dictionary.getObjectType(item.typeDefinitionId);
|
|
31
|
+
if (!childObjectType)
|
|
32
|
+
continue;
|
|
33
|
+
ret.push(childObjectType);
|
|
34
|
+
}
|
|
35
|
+
return ret;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getWriteMask(nodes) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
let nodesToRead = [];
|
|
41
|
+
for (let node of nodes) {
|
|
42
|
+
if (node.writeMask != null)
|
|
43
|
+
continue;
|
|
44
|
+
nodesToRead.push(node.nodeId);
|
|
45
|
+
}
|
|
46
|
+
if (0 == nodesToRead.length)
|
|
47
|
+
return;
|
|
48
|
+
let results = yield this._client.readWriteMasks(nodesToRead);
|
|
49
|
+
let index = 0;
|
|
50
|
+
for (let node of nodes) {
|
|
51
|
+
if (node.writeMask != null)
|
|
52
|
+
continue;
|
|
53
|
+
node.writeMask = results[index];
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
addObject(parentNodeId, objectTypeId, displayName, browseName) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
let objectAttributes = new __1.UaObjectAttributes(displayName);
|
|
61
|
+
let extensionObject = objectAttributes.toExtensionObject();
|
|
62
|
+
let nodeToAdd = new common_1.UaAddNodesItem(new common_1.UaExpandedNodeId(parentNodeId), opcua_webapi_1.NodeClass.Object, extensionObject, new common_1.UaExpandedNodeId(objectTypeId), null, browseName !== null && browseName !== void 0 ? browseName : null, null);
|
|
63
|
+
let results = yield this._client.addNodes([nodeToAdd]);
|
|
64
|
+
if (results[0].statusCode.isNotGood())
|
|
65
|
+
throw new common_1.UaError(results[0].statusCode);
|
|
66
|
+
let newNodeId = results[0].addedNodeId;
|
|
67
|
+
return newNodeId;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
deleteNode(nodeId) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
let nodeToDelete = new common_1.UaDeleteNodesItem(nodeId);
|
|
73
|
+
let results = yield this._client.deleteNodes([nodeToDelete]);
|
|
74
|
+
if (results[0].isNotGood())
|
|
75
|
+
throw new common_1.UaError(results[0]);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
rename(nodeId, name) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
let writeValue = new common_1.UaWriteValue(nodeId, common_1.UaVariant.localizedText(name), opcua_webapi_1.Attributes.DisplayName);
|
|
81
|
+
let results = yield this._client.write([writeValue]);
|
|
82
|
+
if (results[0].isNotGood())
|
|
83
|
+
throw new common_1.UaError(results[0]);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
setDescription(nodeId, description) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
let writeValue = new common_1.UaWriteValue(nodeId, common_1.UaVariant.localizedText(description), opcua_webapi_1.Attributes.Description);
|
|
89
|
+
let results = yield this._client.write([writeValue]);
|
|
90
|
+
if (results[0].isNotGood())
|
|
91
|
+
throw new common_1.UaError(results[0]);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
_readObjectMembers(objectTypeId, dictionary) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
let objectType = dictionary.getObjectType(objectTypeId);
|
|
97
|
+
if (!objectType)
|
|
98
|
+
return null;
|
|
99
|
+
if (objectType.isObjectMemberRead)
|
|
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, false);
|
|
102
|
+
yield typeMemberBrowser.browse();
|
|
103
|
+
let browseMemberResults = typeMemberBrowser.results();
|
|
104
|
+
let instanceNodes = new Map();
|
|
105
|
+
for (let item of browseMemberResults) {
|
|
106
|
+
for (let reference of item.references) {
|
|
107
|
+
if (reference.nodeClass != opcua_webapi_1.NodeClass.Object)
|
|
108
|
+
continue;
|
|
109
|
+
instanceNodes.set(reference.nodeId.toString(), new common_1.UaObject(reference.nodeId, reference.browseName, reference.displayName, 0, reference.typeDefinitionId));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let memberObjectIds = [];
|
|
113
|
+
for (let node of instanceNodes) {
|
|
114
|
+
memberObjectIds.push(node[1].nodeId);
|
|
115
|
+
}
|
|
116
|
+
let modellingRuleBrowser = new __1.UaNodeBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object, false);
|
|
117
|
+
yield modellingRuleBrowser.browse();
|
|
118
|
+
let browseModellingRuleResults = modellingRuleBrowser.results();
|
|
119
|
+
for (let item of browseModellingRuleResults) {
|
|
120
|
+
let instanceNode = instanceNodes.get(item.nodeId.toString());
|
|
121
|
+
if (!instanceNode)
|
|
122
|
+
continue;
|
|
123
|
+
if (0 == item.references.length)
|
|
124
|
+
continue;
|
|
125
|
+
instanceNode.setModellingRule(item.references[0].nodeId);
|
|
126
|
+
}
|
|
127
|
+
for (let node of instanceNodes) {
|
|
128
|
+
if (node[1].modellingRule == common_1.UaModellingRule.None)
|
|
129
|
+
continue;
|
|
130
|
+
objectType.addMember(node[1]);
|
|
131
|
+
}
|
|
132
|
+
objectType.isObjectMemberRead = true;
|
|
133
|
+
return objectType;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.UaModelling = UaModelling;
|
|
@@ -0,0 +1,186 @@
|
|
|
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.UaTypeBrowser = exports.UaLinkBrowser = exports.UaObjectBrowser = exports.UaNodeBrowser = void 0;
|
|
13
|
+
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
|
+
const common_1 = require("../../common");
|
|
15
|
+
class UaNodeBrowser {
|
|
16
|
+
constructor(client, nodeIds, referenceType, nodeClassToReturn, returnDescription, maxNodesPerBrowse, maxReferencesPerNode) {
|
|
17
|
+
this._client = client;
|
|
18
|
+
this._nodesToBrowse = [];
|
|
19
|
+
this._referenceType = referenceType;
|
|
20
|
+
this._nodeClassToReturn = nodeClassToReturn;
|
|
21
|
+
this._continuationPointToBrowse = [];
|
|
22
|
+
this._returnDescription = returnDescription !== null && returnDescription !== void 0 ? returnDescription : false;
|
|
23
|
+
this._maxNodesPerBrowse = (null == maxNodesPerBrowse || maxNodesPerBrowse <= 0) ? 50 : maxNodesPerBrowse;
|
|
24
|
+
this._maxReferencesPerNode = (null == maxReferencesPerNode || maxReferencesPerNode < 0) ? 50 : maxReferencesPerNode;
|
|
25
|
+
this._readResults = new Map();
|
|
26
|
+
if (this._nodeClassToReturn != 0) {
|
|
27
|
+
let nodeIdSet = new Set;
|
|
28
|
+
for (let item of nodeIds) {
|
|
29
|
+
if (nodeIdSet.has(item.toString()))
|
|
30
|
+
continue;
|
|
31
|
+
nodeIdSet.add(item.toString());
|
|
32
|
+
this._nodesToBrowse.push(item);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
browse() {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (this.isFinish())
|
|
39
|
+
return;
|
|
40
|
+
yield this.browseOnce();
|
|
41
|
+
yield this.browse();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
browseOnce() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (this._continuationPointToBrowse.length != 0) {
|
|
47
|
+
yield this._browseContinuationPoints();
|
|
48
|
+
}
|
|
49
|
+
else if (this._nodesToBrowse.length != 0) {
|
|
50
|
+
yield this._browseNodes();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
results() {
|
|
55
|
+
let results = [];
|
|
56
|
+
for (let item of this._readResults) {
|
|
57
|
+
results.push({
|
|
58
|
+
nodeId: (0, common_1.parseUaNodeId)(item[0]),
|
|
59
|
+
references: item[1]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
this._readResults.clear();
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
isFinish() {
|
|
66
|
+
return (this._nodesToBrowse.length == 0) && (this._continuationPointToBrowse.length == 0);
|
|
67
|
+
}
|
|
68
|
+
_browseNodes() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
var _a;
|
|
71
|
+
let nodesToBrowse = this._nodesToBrowse.splice(0, this._maxNodesPerBrowse);
|
|
72
|
+
let browseDescriptions = [];
|
|
73
|
+
for (let item of nodesToBrowse) {
|
|
74
|
+
let browseDescription = new common_1.UaBrowseDescription(item, opcua_webapi_1.BrowseDirection.Forward, this._referenceType, true, this._nodeClassToReturn, 63);
|
|
75
|
+
browseDescriptions.push(browseDescription);
|
|
76
|
+
}
|
|
77
|
+
let results = yield this._client.browse(browseDescriptions, this._maxReferencesPerNode);
|
|
78
|
+
for (let i = 0; i < nodesToBrowse.length; ++i) {
|
|
79
|
+
let currentNodeId = nodesToBrowse[i];
|
|
80
|
+
let currentResult = results[i];
|
|
81
|
+
if (currentResult.statusCode.isNotGood())
|
|
82
|
+
throw new common_1.UaError(currentResult.statusCode);
|
|
83
|
+
let currentReferences = this._readResults.get(currentNodeId.toString());
|
|
84
|
+
if (!currentReferences) {
|
|
85
|
+
currentReferences = [];
|
|
86
|
+
this._readResults.set(currentNodeId.toString(), currentReferences);
|
|
87
|
+
}
|
|
88
|
+
let newReferences = [];
|
|
89
|
+
for (let item of currentResult.references) {
|
|
90
|
+
let nodeId = item.nodeId.getNodeId();
|
|
91
|
+
let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
|
|
92
|
+
if (null == nodeId || null === typeDefinition)
|
|
93
|
+
continue;
|
|
94
|
+
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);
|
|
95
|
+
currentReferences.push(reference);
|
|
96
|
+
newReferences.push(reference);
|
|
97
|
+
}
|
|
98
|
+
if (currentResult.continuationPoint) {
|
|
99
|
+
this._continuationPointToBrowse.push({
|
|
100
|
+
nodeId: currentNodeId,
|
|
101
|
+
continuationPoint: currentResult.continuationPoint
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (this._returnDescription)
|
|
105
|
+
yield this._readDescriptions(newReferences);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
_browseContinuationPoints() {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
var _a;
|
|
112
|
+
let cpsToBrowse = this._continuationPointToBrowse.splice(0, this._maxNodesPerBrowse);
|
|
113
|
+
let continuationPoints = [];
|
|
114
|
+
for (let item of cpsToBrowse) {
|
|
115
|
+
continuationPoints.push(item.continuationPoint);
|
|
116
|
+
}
|
|
117
|
+
let results = yield this._client.browseNext(continuationPoints, false);
|
|
118
|
+
for (let i = 0; i < cpsToBrowse.length; ++i) {
|
|
119
|
+
let currentNodeId = cpsToBrowse[i].nodeId;
|
|
120
|
+
let currentResult = results[i];
|
|
121
|
+
if (currentResult.statusCode.isNotGood())
|
|
122
|
+
throw new common_1.UaError(currentResult.statusCode);
|
|
123
|
+
let newReferences = [];
|
|
124
|
+
for (let item of currentResult.references) {
|
|
125
|
+
let nodeId = item.nodeId.getNodeId();
|
|
126
|
+
let typeDefinition = (_a = item.typeDefinition) === null || _a === void 0 ? void 0 : _a.getNodeId();
|
|
127
|
+
if (null == nodeId || null === typeDefinition)
|
|
128
|
+
continue;
|
|
129
|
+
let currentReferences = this._readResults.get(currentNodeId.toString());
|
|
130
|
+
if (!currentReferences) {
|
|
131
|
+
currentReferences = [];
|
|
132
|
+
this._readResults.set(currentNodeId.toString(), currentReferences);
|
|
133
|
+
}
|
|
134
|
+
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);
|
|
135
|
+
currentReferences.push(reference);
|
|
136
|
+
newReferences.push(reference);
|
|
137
|
+
}
|
|
138
|
+
if (currentResult.continuationPoint) {
|
|
139
|
+
this._continuationPointToBrowse.push({
|
|
140
|
+
nodeId: currentNodeId,
|
|
141
|
+
continuationPoint: currentResult.continuationPoint
|
|
142
|
+
});
|
|
143
|
+
}
|
|
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
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.UaNodeBrowser = UaNodeBrowser;
|
|
169
|
+
class UaObjectBrowser extends UaNodeBrowser {
|
|
170
|
+
constructor(client, nodeIds, returnDescription) {
|
|
171
|
+
super(client, nodeIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HierarchicalReferences), opcua_webapi_1.NodeClass.Object, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
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
|
+
class UaTypeBrowser extends UaNodeBrowser {
|
|
182
|
+
constructor(client, nodeIds, returnDescription) {
|
|
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, returnDescription !== null && returnDescription !== void 0 ? returnDescription : false, 20);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.UaTypeBrowser = UaTypeBrowser;
|