當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。