当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript OPCUAServer.initialize方法代码示例

本文整理汇总了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);
    }
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:27,代码来源:test_server_with_method.ts

示例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);
    }
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:89,代码来源:test_server.ts


注:本文中的node-opcua.OPCUAServer.initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。