opcua-webapi-ts 1.1.18 → 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 +96 -12
- package/dist/cjs/client/utils/UaDataTypeDictionary.js +2 -2
- package/dist/cjs/client/utils/UaModelling.js +43 -35
- package/dist/cjs/client/utils/UaNodeBrowser.js +186 -0
- package/dist/cjs/client/utils/UaNodeReader.js +4 -175
- package/dist/cjs/client/utils/UaObjectTypeDictionary.js +3 -2
- package/dist/cjs/client/utils/UaReferenceTypeDictionary.js +3 -2
- package/dist/cjs/client/utils/index.js +2 -0
- package/dist/client/UaWebClient.d.ts +9 -2
- package/dist/client/UaWebClient.js +96 -12
- package/dist/client/utils/UaDataTypeDictionary.js +2 -2
- package/dist/client/utils/UaModelling.d.ts +6 -5
- package/dist/client/utils/UaModelling.js +43 -35
- package/dist/client/utils/UaNodeBrowser.d.ts +34 -0
- package/dist/client/utils/UaNodeBrowser.js +186 -0
- package/dist/client/utils/UaNodeReader.d.ts +0 -36
- package/dist/client/utils/UaNodeReader.js +4 -175
- package/dist/client/utils/UaObjectTypeDictionary.js +3 -2
- package/dist/client/utils/UaReferenceTypeDictionary.js +3 -2
- package/dist/client/utils/index.d.ts +2 -0
- package/dist/client/utils/index.js +2 -0
- package/package.json +2 -2
|
@@ -13,6 +13,7 @@ exports.UaObjectTypeDictionary = void 0;
|
|
|
13
13
|
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
15
|
const UaNodeReader_1 = require("./UaNodeReader");
|
|
16
|
+
const UaNodeBrowser_1 = require("./UaNodeBrowser");
|
|
16
17
|
class UaObjectTypeDictionary {
|
|
17
18
|
constructor(client) {
|
|
18
19
|
this._client = client;
|
|
@@ -22,7 +23,7 @@ class UaObjectTypeDictionary {
|
|
|
22
23
|
}
|
|
23
24
|
read() {
|
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
let browser = new
|
|
26
|
+
let browser = new UaNodeBrowser_1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.ObjectTypeIds.BaseObjectType)]);
|
|
26
27
|
yield this._read(browser);
|
|
27
28
|
});
|
|
28
29
|
}
|
|
@@ -68,7 +69,7 @@ class UaObjectTypeDictionary {
|
|
|
68
69
|
return;
|
|
69
70
|
yield this.__delay(20);
|
|
70
71
|
// Continue to browse and read child type
|
|
71
|
-
let childBrowser = new
|
|
72
|
+
let childBrowser = new UaNodeBrowser_1.UaTypeBrowser(this._client, nodeIdsToBrowse);
|
|
72
73
|
yield this._read(childBrowser);
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -13,6 +13,7 @@ exports.UaReferenceTypeDictionary = void 0;
|
|
|
13
13
|
const opcua_webapi_1 = require("opcua-webapi");
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
15
|
const UaNodeReader_1 = require("./UaNodeReader");
|
|
16
|
+
const UaNodeBrowser_1 = require("./UaNodeBrowser");
|
|
16
17
|
class UaReferenceTypeDictionary {
|
|
17
18
|
constructor(client) {
|
|
18
19
|
this._client = client;
|
|
@@ -22,7 +23,7 @@ class UaReferenceTypeDictionary {
|
|
|
22
23
|
}
|
|
23
24
|
read() {
|
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
let browser = new
|
|
26
|
+
let browser = new UaNodeBrowser_1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.ReferenceTypeIds.References)]);
|
|
26
27
|
yield this._read(browser);
|
|
27
28
|
});
|
|
28
29
|
}
|
|
@@ -68,7 +69,7 @@ class UaReferenceTypeDictionary {
|
|
|
68
69
|
return;
|
|
69
70
|
yield this.__delay(20);
|
|
70
71
|
// Continue to browse and read child type
|
|
71
|
-
let childBrowser = new
|
|
72
|
+
let childBrowser = new UaNodeBrowser_1.UaTypeBrowser(this._client, nodeIdsToBrowse);
|
|
72
73
|
yield this._read(childBrowser);
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./UaDataTypeDictionary"), exports);
|
|
18
18
|
__exportStar(require("./UaObjectTypeDictionary"), exports);
|
|
19
19
|
__exportStar(require("./UaReferenceTypeDictionary"), exports);
|
|
20
|
+
__exportStar(require("./UaNodeBrowser"), exports);
|
|
20
21
|
__exportStar(require("./UaNodeReader"), exports);
|
|
22
|
+
__exportStar(require("./UaModelling"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ViewDescription, RequestHeader, ApplicationDescription, BrowseDirection, EndpointDescription } from "opcua-webapi";
|
|
2
|
-
import { UaBrowseResult, OpcUaNodeAttributes, OpcUaVariableAttributes, UaNodeId, UaDataValue, UaVariant, UaStatusCode, UaExtensionObject, UaHistoryDataResult, UaQuery, UaBrowseDescription, UaReadValueId, UaWriteValue, UaHistoryReadValueId, UaHistoryReadResult, UaLocalizedText, UaAddNodesItem, UaAddNodesResult, UaDeleteNodesItem, UaAddReferencesItem, UaDeleteReferencesItem } from "../common";
|
|
2
|
+
import { UaBrowseResult, OpcUaNodeAttributes, OpcUaVariableAttributes, UaNodeId, UaDataValue, UaVariant, UaStatusCode, UaArgument, UaExtensionObject, UaHistoryDataResult, UaQuery, UaBrowseDescription, UaReadValueId, UaWriteValue, UaHistoryReadValueId, UaHistoryReadResult, UaLocalizedText, UaAddNodesItem, UaAddNodesResult, UaDeleteNodesItem, UaAddReferencesItem, UaDeleteReferencesItem } from "../common";
|
|
3
3
|
import { UaClientConfiguration, UaClientParameters, UaWebClientApi } from "..";
|
|
4
4
|
import { UaHistoryEventResult, UaCallMethodRequest, UaCallMethodResult } from "../common";
|
|
5
5
|
export type UaApplicationDescriptor = {
|
|
@@ -8,6 +8,10 @@ export type UaApplicationDescriptor = {
|
|
|
8
8
|
applicationName: UaLocalizedText;
|
|
9
9
|
productUri: string;
|
|
10
10
|
};
|
|
11
|
+
export type UaMethodArguments = {
|
|
12
|
+
inputArguments: Array<UaArgument>;
|
|
13
|
+
outputArguments: Array<UaArgument>;
|
|
14
|
+
};
|
|
11
15
|
export declare class UaWebClient {
|
|
12
16
|
private api;
|
|
13
17
|
private clientConfig;
|
|
@@ -20,9 +24,12 @@ export declare class UaWebClient {
|
|
|
20
24
|
browseNextByCP(continuationPoint: string): Promise<UaBrowseResult>;
|
|
21
25
|
readValues(nodeIds: Array<UaNodeId>, timestampsToReturn?: number): Promise<Array<UaDataValue>>;
|
|
22
26
|
writeValue(nodeId: UaNodeId, value: UaVariant): Promise<void>;
|
|
27
|
+
methodCall(objectId: UaNodeId, methodId: UaNodeId, inputArguments: Array<UaVariant>): Promise<Array<UaVariant>>;
|
|
23
28
|
readNodeAttributes(nodeId: UaNodeId, returnDescription?: boolean): Promise<OpcUaNodeAttributes>;
|
|
29
|
+
readMethodArguments(nodeId: UaNodeId): Promise<UaMethodArguments>;
|
|
30
|
+
readObjectEventNotifier(nodeId: UaNodeId): Promise<number>;
|
|
24
31
|
readVariableAttributes(nodeIds: Array<UaNodeId>): Promise<Array<OpcUaVariableAttributes>>;
|
|
25
|
-
|
|
32
|
+
readWriteMasks(nodeIds: Array<UaNodeId>): Promise<Array<number>>;
|
|
26
33
|
getGeneratedEventType(typeId: UaNodeId): Promise<Array<UaNodeId>>;
|
|
27
34
|
historyReadRawData(nodeId: UaNodeId, startTime: Date, endTime: Date, numValuesPerNode?: number | null, continuationPoint?: string | null, returnBounds?: boolean | null, isReadModified?: boolean | null, timestampsToReturn?: number | null, releaseContinuationPoints?: boolean | null): Promise<UaHistoryDataResult>;
|
|
28
35
|
historyReadAtTime(nodeId: UaNodeId, requiredTimes: Array<Date>, useSimpleBounds?: boolean | null, continuationPoint?: string | null, timestampsToReturn?: number | null, releaseContinuationPoints?: boolean | null): Promise<UaHistoryDataResult>;
|
|
@@ -89,6 +89,22 @@ 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 = [
|
|
@@ -125,6 +141,67 @@ class UaWebClient {
|
|
|
125
141
|
return ret;
|
|
126
142
|
});
|
|
127
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
|
+
}
|
|
128
205
|
readVariableAttributes(nodeIds) {
|
|
129
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
207
|
if (nodeIds.length == 0)
|
|
@@ -179,20 +256,26 @@ class UaWebClient {
|
|
|
179
256
|
return ret;
|
|
180
257
|
});
|
|
181
258
|
}
|
|
182
|
-
|
|
259
|
+
readWriteMasks(nodeIds) {
|
|
183
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
261
|
+
if (nodeIds.length == 0)
|
|
262
|
+
return [];
|
|
263
|
+
let nodesToRead = [];
|
|
264
|
+
for (let item of nodeIds) {
|
|
265
|
+
let nodeIdToRead = new common_1.UaReadValueId(item, opcua_webapi_1.Attributes.UserWriteMask);
|
|
266
|
+
nodesToRead.push(nodeIdToRead);
|
|
187
267
|
}
|
|
188
|
-
let
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
268
|
+
let results = yield this.read(nodesToRead);
|
|
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
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return writeMasks;
|
|
196
279
|
});
|
|
197
280
|
}
|
|
198
281
|
getGeneratedEventType(typeId) {
|
|
@@ -706,6 +789,7 @@ class UaWebClient {
|
|
|
706
789
|
response = yield this.api.addNodes(request, { signal: controller.signal });
|
|
707
790
|
}
|
|
708
791
|
catch (error) {
|
|
792
|
+
console.error(error);
|
|
709
793
|
throw new common_1.UaError((0, common_1.makeUaStatusCode)(opcua_webapi_1.StatusCodes.BadCommunicationError));
|
|
710
794
|
}
|
|
711
795
|
finally {
|
|
@@ -22,7 +22,7 @@ class UaDataTypeDictionary {
|
|
|
22
22
|
}
|
|
23
23
|
read() {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
let browser = new __1.
|
|
25
|
+
let browser = new __1.UaTypeBrowser(this._client, [common_1.UaNodeId.from(common_1.DataTypeIds.BaseDataType)]);
|
|
26
26
|
yield this._read(browser);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -71,7 +71,7 @@ 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.
|
|
74
|
+
let childBrowser = new __1.UaTypeBrowser(this._client, nodeIdsToBrowse);
|
|
75
75
|
yield this._read(childBrowser);
|
|
76
76
|
});
|
|
77
77
|
}
|
|
@@ -3,11 +3,12 @@ import { UaWebClient } from "../UaWebClient";
|
|
|
3
3
|
import { UaObjectTypeDictionary } from "../..";
|
|
4
4
|
export declare class UaModelling {
|
|
5
5
|
private _client;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getObjectTypeToAdd(objectTypeId: UaNodeId): Promise<Array<UaObjectType>>;
|
|
9
|
-
addObject(parentNodeId: UaNodeId, objectType: UaObjectType, displayName: UaLocalizedText, browseName?: string): Promise<UaNodeId>;
|
|
10
|
-
deleteNode(nodeId: UaNodeId): Promise<void>;
|
|
6
|
+
constructor(client: UaWebClient);
|
|
7
|
+
getObjectTypeToAdd(objectTypeId: UaNodeId, dictionary: UaObjectTypeDictionary): Promise<Array<UaObjectType>>;
|
|
11
8
|
getWriteMask(nodes: Array<UaNode>): Promise<void>;
|
|
9
|
+
addObject(parentNodeId: UaNodeId, objectTypeId: UaNodeId, displayName: UaLocalizedText, browseName?: string): Promise<UaNodeId>;
|
|
10
|
+
deleteNode(nodeId: UaNodeId): Promise<void>;
|
|
11
|
+
rename(nodeId: UaNodeId, name: UaLocalizedText): Promise<void>;
|
|
12
|
+
setDescription(nodeId: UaNodeId, description: UaLocalizedText): Promise<void>;
|
|
12
13
|
private _readObjectMembers;
|
|
13
14
|
}
|
|
@@ -14,13 +14,12 @@ const opcua_webapi_1 = require("opcua-webapi");
|
|
|
14
14
|
const common_1 = require("../../common");
|
|
15
15
|
const __1 = require("../..");
|
|
16
16
|
class UaModelling {
|
|
17
|
-
constructor(client
|
|
17
|
+
constructor(client) {
|
|
18
18
|
this._client = client;
|
|
19
|
-
this._objectTypeDictionary = objectTypeDictionary;
|
|
20
19
|
}
|
|
21
|
-
getObjectTypeToAdd(objectTypeId) {
|
|
20
|
+
getObjectTypeToAdd(objectTypeId, dictionary) {
|
|
22
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
let objectType = yield this._readObjectMembers(objectTypeId);
|
|
22
|
+
let objectType = yield this._readObjectMembers(objectTypeId, dictionary);
|
|
24
23
|
if (!objectType)
|
|
25
24
|
return [];
|
|
26
25
|
let ret = [];
|
|
@@ -28,7 +27,7 @@ class UaModelling {
|
|
|
28
27
|
for (let item of objectMembers) {
|
|
29
28
|
if (item.modellingRule != common_1.UaModellingRule.PlaceHolder)
|
|
30
29
|
continue;
|
|
31
|
-
let childObjectType =
|
|
30
|
+
let childObjectType = dictionary.getObjectType(item.typeDefinitionId);
|
|
32
31
|
if (!childObjectType)
|
|
33
32
|
continue;
|
|
34
33
|
ret.push(childObjectType);
|
|
@@ -36,11 +35,31 @@ class UaModelling {
|
|
|
36
35
|
return ret;
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
|
-
|
|
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) {
|
|
40
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
60
|
let objectAttributes = new __1.UaObjectAttributes(displayName);
|
|
42
61
|
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(
|
|
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);
|
|
44
63
|
let results = yield this._client.addNodes([nodeToAdd]);
|
|
45
64
|
if (results[0].statusCode.isNotGood())
|
|
46
65
|
throw new common_1.UaError(results[0].statusCode);
|
|
@@ -56,41 +75,30 @@ class UaModelling {
|
|
|
56
75
|
throw new common_1.UaError(results[0]);
|
|
57
76
|
});
|
|
58
77
|
}
|
|
59
|
-
|
|
78
|
+
rename(nodeId, name) {
|
|
60
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
let results = yield this._client.
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
}
|
|
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]);
|
|
84
92
|
});
|
|
85
93
|
}
|
|
86
|
-
_readObjectMembers(objectTypeId) {
|
|
94
|
+
_readObjectMembers(objectTypeId, dictionary) {
|
|
87
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
let objectType =
|
|
96
|
+
let objectType = dictionary.getObjectType(objectTypeId);
|
|
89
97
|
if (!objectType)
|
|
90
98
|
return null;
|
|
91
99
|
if (objectType.isObjectMemberRead)
|
|
92
100
|
return objectType;
|
|
93
|
-
let typeMemberBrowser = new __1.
|
|
101
|
+
let typeMemberBrowser = new __1.UaNodeBrowser(this._client, [objectType.nodeId], common_1.UaNodeId.from(common_1.ReferenceTypeIds.Aggregates), opcua_webapi_1.NodeClass.Object, false);
|
|
94
102
|
yield typeMemberBrowser.browse();
|
|
95
103
|
let browseMemberResults = typeMemberBrowser.results();
|
|
96
104
|
let instanceNodes = new Map();
|
|
@@ -105,7 +113,7 @@ class UaModelling {
|
|
|
105
113
|
for (let node of instanceNodes) {
|
|
106
114
|
memberObjectIds.push(node[1].nodeId);
|
|
107
115
|
}
|
|
108
|
-
let modellingRuleBrowser = new __1.
|
|
116
|
+
let modellingRuleBrowser = new __1.UaNodeBrowser(this._client, memberObjectIds, common_1.UaNodeId.from(common_1.ReferenceTypeIds.HasModellingRule), opcua_webapi_1.NodeClass.Object, false);
|
|
109
117
|
yield modellingRuleBrowser.browse();
|
|
110
118
|
let browseModellingRuleResults = modellingRuleBrowser.results();
|
|
111
119
|
for (let item of browseModellingRuleResults) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { UaNodeId, UaReference } from "../../common";
|
|
2
|
+
import { UaWebClient } from "../UaWebClient";
|
|
3
|
+
export type BrowseReferenceResult = {
|
|
4
|
+
nodeId: UaNodeId;
|
|
5
|
+
references: Array<UaReference>;
|
|
6
|
+
};
|
|
7
|
+
export declare class UaNodeBrowser {
|
|
8
|
+
private _client;
|
|
9
|
+
private _nodesToBrowse;
|
|
10
|
+
private _continuationPointToBrowse;
|
|
11
|
+
private _referenceType;
|
|
12
|
+
private _nodeClassToReturn;
|
|
13
|
+
private _returnDescription;
|
|
14
|
+
private _maxNodesPerBrowse;
|
|
15
|
+
private _maxReferencesPerNode;
|
|
16
|
+
private _readResults;
|
|
17
|
+
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, referenceType: UaNodeId, nodeClassToReturn: number, returnDescription?: boolean, maxNodesPerBrowse?: number | null, maxReferencesPerNode?: number | null);
|
|
18
|
+
browse(): Promise<void>;
|
|
19
|
+
browseOnce(): Promise<void>;
|
|
20
|
+
results(): Array<BrowseReferenceResult>;
|
|
21
|
+
isFinish(): boolean;
|
|
22
|
+
private _browseNodes;
|
|
23
|
+
private _browseContinuationPoints;
|
|
24
|
+
private _readDescriptions;
|
|
25
|
+
}
|
|
26
|
+
export declare class UaObjectBrowser extends UaNodeBrowser {
|
|
27
|
+
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
|
|
28
|
+
}
|
|
29
|
+
export declare class UaLinkBrowser extends UaNodeBrowser {
|
|
30
|
+
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
|
|
31
|
+
}
|
|
32
|
+
export declare class UaTypeBrowser extends UaNodeBrowser {
|
|
33
|
+
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
|
|
34
|
+
}
|
|
@@ -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;
|
|
@@ -1,41 +1,5 @@
|
|
|
1
1
|
import { UaNode, UaNodeId, UaReference } from "../../common";
|
|
2
2
|
import { UaWebClient } from "../UaWebClient";
|
|
3
|
-
export type BrowseReferenceResult = {
|
|
4
|
-
nodeId: UaNodeId;
|
|
5
|
-
references: Array<UaReference>;
|
|
6
|
-
};
|
|
7
|
-
export type ReadChildNodeResult = {
|
|
8
|
-
nodeId: UaNodeId;
|
|
9
|
-
children: Array<UaNode>;
|
|
10
|
-
};
|
|
11
|
-
export declare class UaNodeReferenceBrowser {
|
|
12
|
-
private _client;
|
|
13
|
-
private _nodesToBrowse;
|
|
14
|
-
private _continuationPointToBrowse;
|
|
15
|
-
private _referenceType;
|
|
16
|
-
private _nodeClassToReturn;
|
|
17
|
-
private _returnDescription;
|
|
18
|
-
private _maxNodesPerBrowse;
|
|
19
|
-
private _maxReferencesPerNode;
|
|
20
|
-
private _readResults;
|
|
21
|
-
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, referenceType: UaNodeId, nodeClassToReturn: number, returnDescription?: boolean, maxNodesPerBrowse?: number | null, maxReferencesPerNode?: number | null);
|
|
22
|
-
browse(): Promise<void>;
|
|
23
|
-
browseOnce(): Promise<void>;
|
|
24
|
-
results(): Array<BrowseReferenceResult>;
|
|
25
|
-
isFinish(): boolean;
|
|
26
|
-
private _browseNodes;
|
|
27
|
-
private _browseContinuationPoints;
|
|
28
|
-
private _readDescriptions;
|
|
29
|
-
}
|
|
30
|
-
export declare class UaChildBrowser extends UaNodeReferenceBrowser {
|
|
31
|
-
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
|
|
32
|
-
}
|
|
33
|
-
export declare class UaLinkBrowser extends UaNodeReferenceBrowser {
|
|
34
|
-
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
|
|
35
|
-
}
|
|
36
|
-
export declare class UaSubtypeBrowser extends UaNodeReferenceBrowser {
|
|
37
|
-
constructor(client: UaWebClient, nodeIds: Array<UaNodeId>, returnDescription?: boolean);
|
|
38
|
-
}
|
|
39
3
|
export declare class UaNodeReader {
|
|
40
4
|
private _client;
|
|
41
5
|
private _nodeClassToReturn;
|