本文整理汇总了TypeScript中node-opcua.OPCUAServer.initialize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript OPCUAServer.initialize方法的具体用法?TypeScript OPCUAServer.initialize怎么用?TypeScript OPCUAServer.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node-opcua.OPCUAServer
的用法示例。
在下文中一共展示了OPCUAServer.initialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: main
async function main() {
try {
const server = new OPCUAServer({
nodeset_filename: [
nodesets.standard_nodeset_file
]
});
await server.initialize();
// post-initialize
const addressSpace = server.engine.addressSpace!;
const object = installObjectWithMethod(addressSpace);
console.log("object = ", object.toString());
await callMethodFromServer(addressSpace, object.nodeId);
await server.start();
console.log(" Server started ", server.endpoints[0].endpointDescriptions()[0].endpointUrl);
} catch (err) {
console.log(" Error: ", err.message);
console.log(err.stack);
}
}
示例2: main
async function main() {
try {
const server = new OPCUAServer({
registerServerMethod: RegisterServerMethod.LDS
});
await server.initialize();
server.on("request", (request: Request) => {
console.log(request.constructor.name, request.requestHeader.requestHandle);
// you can either check the instance of the request object directl
if (request instanceof BrowseRequest) {
console.log("BrowseRequest.requestedMaxReferencesPerNode=", request.requestedMaxReferencesPerNode);
} else if (request instanceof ActivateSessionRequest) {
console.log(request.toString());
}
// ... or check its schema name
switch (request.schema.name) {
case "BrowseRequest":
{
const browseRequest = request as BrowseRequest;
} break;
// etc...
}
});
server.on("response", (response: Response) => {
// you can either check the instance of the request object directl
if (response instanceof BrowseResponse) {
console.log("BrowseResponse.results.length =", response.results ? response.results.length : 0);
}
switch (response.schema.name) {
case "BrowseResponse": {
const browseRequest = response as BrowseResponse;
console.log("BrowseResponse.results.length =", browseRequest.results ? browseRequest.results.length : 0);
} break;
// etc...
}
});
// post-initialize
const addressSpace = server.engine.addressSpace!;
addressSpace.installAlarmsAndConditionsService();
const namespace = addressSpace.getOwnNamespace();
const myEventType = namespace.addEventType({
browseName: "MyEventType",
subtypeOf: "TransitionEventType"
});
const HVACModuleType = namespace.addObjectType({
browseName: "HVACModuleType"
});
namespace.addAnalogDataItem({
modellingRule: "Mandatory",
componentOf: HVACModuleType,
browseName: "TargetTemperature",
minimumSamplingInterval: 0, // could be event Based
dataType: "Double",
instrumentRange: { low: -70, high: 120 },
engineeringUnitsRange: { low: -100, high: 200 }
});
namespace.addObject({
browseName: "Test",
eventNotifier: 0,
organizedBy: addressSpace.rootFolder.objects
});
const boiler1 = makeBoiler(addressSpace, {
browseName: "Boiler1",
organizedBy: addressSpace.rootFolder.objects
});
await server.start();
console.log(" Server started ", server.endpoints[0].endpointDescriptions()[0].endpointUrl);
} catch (err) {
console.log("Error : ", err.message);
console.log(err.stack);
}
}