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


TypeScript OPCUAServer.on方法代码示例

本文整理汇总了TypeScript中node-opcua.OPCUAServer.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript OPCUAServer.on方法的具体用法?TypeScript OPCUAServer.on怎么用?TypeScript OPCUAServer.on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在node-opcua.OPCUAServer的用法示例。


在下文中一共展示了OPCUAServer.on方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: main

async function main() {

    const server = new OPCUAServer(server_options);

    server.on("post_initialize", () => {
        /* empty */
    });

    console.log(chalk.yellow("  server PID          :"), process.pid);
    console.log(chalk.yellow("  silent              :"), argv.silent);

    await server.start();

    const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;
    console.log(chalk.yellow("  server on port      :"), chalk.cyan(server.endpoints[0].port.toString()));
    console.log(chalk.yellow("  endpointUrl         :"), chalk.cyan(endpointUrl));

    console.log(chalk.yellow("\n  server now waiting for connections. CTRL+C to stop"));

    if (argv.silent) {
        console.log("silent");
        console.log = (...args: [any?, ... any[]]) => {
            /* silent */
        };
    }

    server.on("create_session", (session: ServerSession) => {
        console.log(" SESSION CREATED");
        console.log(chalk.cyan("    client application URI: "), session.clientDescription!.applicationUri);
        console.log(chalk.cyan("        client product URI: "), session.clientDescription!.productUri);
        console.log(chalk.cyan("   client application name: "), session.clientDescription!.applicationName.toString());
        console.log(chalk.cyan("   client application type: "), session.clientDescription!.applicationType.toString());
        console.log(chalk.cyan("              session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
        console.log(chalk.cyan("           session timeout: "), session.sessionTimeout);
        console.log(chalk.cyan("                session id: "), session.nodeId);
    });

    server.on("session_closed", (session: ServerSession, reason: string) => {
        console.log(" SESSION CLOSED :", reason);
        console.log(chalk.cyan("              session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
    });

    process.on("SIGINT", async () => {
        // only work on linux apparently
        console.error(chalk.red.bold(" Received server interruption from user "));
        console.error(chalk.red.bold(" shutting down ..."));
        await server.shutdown(1000);
        console.error(chalk.red.bold(" shot down ..."));
        process.exit(1);
    });

}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:52,代码来源:simple_secure_server.ts

示例2: before

    before(done => {
        port += 1;

        const options = { port };
        server = new OPCUAServer(options);

        server.on("post_initialize", () => {
            const addressSpace = server.engine.addressSpace!;

            const group = addressSpace.getOwnNamespace().addObject({
                browseName: "Group",
                organizedBy: addressSpace.rootFolder.objects
            });

            for (let i = 0; i < 27; i++) {
                addressSpace.getOwnNamespace().addObject({
                    browseName: "Object" + i,
                    organizedBy: group
                });
            }
            groupNodeId = group.nodeId;
        });
        server.start((err?: Error) => {
            if (err) {
                return done(err);
            }
            endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl;
            if (err) {
                return done(err);
            }
            done();
        });
    });
开发者ID:node-opcua,项目名称:node-opcua,代码行数:33,代码来源:test_e2e_#519_Nodecrawler_is_not_browsing_some_nodes.ts

示例3: main

async function main() {
    process.title = "Node OPCUA Server on port : " + server_options.port;

    const server = new OPCUAServer(server_options);


    server.on("post_initialize", () => {/**/
    });

    console.log(chalk.yellow("  server PID          :"), process.pid);

    try {
        await server.start();
    } catch (err) {
        console.log(" Server failed to start ... exiting");
        process.exit(-3);
    }

    const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;

    console.log(chalk.yellow("  server on port      :"), server.endpoints[0].port.toString());
    console.log(chalk.yellow("  endpointUrl         :"), chalk.cyan(endpointUrl));
    console.log(chalk.yellow("\n  server now waiting for connections. CTRL+C to stop"));

    server.on("create_session", (session: ServerSession) => {
        console.log(" SESSION CREATED");
        console.log(chalk.cyan("    client application URI: "), session.clientDescription!.applicationUri);
        console.log(chalk.cyan("        client product URI: "), session.clientDescription!.productUri);
        console.log(chalk.cyan("   client application name: "), session.clientDescription!.applicationName.toString());
        console.log(chalk.cyan("   client application type: "), session.clientDescription!.applicationType.toString());
        console.log(chalk.cyan("              session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
        console.log(chalk.cyan("           session timeout: "), session.sessionTimeout);
        console.log(chalk.cyan("                session id: "), session.nodeId);
    });

    server.on("session_closed", (session: ServerSession, reason: string) => {
        console.log(" SESSION CLOSED :", reason);
        console.log(chalk.cyan("              session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
    });
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:40,代码来源:mini_server.ts

示例4: main

async function main() {

    const server = new OPCUAServer(server_options);

    console.log(chalk.yellow("  server PID          :"), process.pid);

    server.on("post_initialize", () => {

        const addressSpace = server.engine.addressSpace!;

        // to do: expose new nodeid here
        const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
        const myStructureType = addressSpace.findVariableType("MyStructureType", ns);
        if (!myStructureType) {
           console.log(" ns = ", ns, "cannot find MyStructureDataType ");
           return;
        }

        const namespace = addressSpace.getOwnNamespace();
        const someObject =  namespace.addObject({
            browseName: "SomeObject",
            organizedBy: addressSpace.rootFolder.objects
        });

        myStructureType.instantiate({
            browseName: "MyVar",
            componentOf: someObject
        });

    });

    try {
        await server.start();
    } catch (err) {
        console.log(" Server failed to start ... exiting");
        process.exit(-3);
    }

    const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;

    console.log(chalk.yellow("  server on port      :"), chalk.cyan(server.endpoints[0].port.toString()));
    console.log(chalk.yellow("  endpointUrl         :"), chalk.cyan(endpointUrl));
    console.log(chalk.yellow("\n  server now waiting for connections. CTRL+C to stop"));

    process.on("SIGINT", async () => {
        // only work on linux apparently
        await server.shutdown(1000);
        console.log(chalk.red.bold(" shutting down completed "));
        process.exit(-1);
    });
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:51,代码来源:simple_server_with_custom_extension_objects.ts

示例5: main

async function main() {

    const tmpFolder = path.join(__dirname, "../certificates/myApp");

    const applicationGroup = new CertificateManager({
        location: tmpFolder
    });
    await applicationGroup.initialize();

    const server = new OPCUAServer(server_options);

    console.log(" Configuration rootdir =  ", server.serverCertificateManager.rootDir);

    console.log(chalk.yellow("  server PID          :"), process.pid);

    server.on("post_initialize", () => {

        const addressSpace = server.engine.addressSpace!;
        // to do: expose new nodeid here
        const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");

        installPushCertificateManagement(addressSpace, {
            applicationGroup: server.serverCertificateManager,
            userTokenGroup: server.userCertificateManager
        });

        console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);

    });

    try {
        await server.start();
    } catch (err) {
        console.log(" Server failed to start ... exiting");
        process.exit(-3);
    }

    const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;

    console.log(chalk.yellow("  server on port      :"), chalk.cyan(server.endpoints[0].port.toString()));
    console.log(chalk.yellow("  endpointUrl         :"), chalk.cyan(endpointUrl));
    console.log(chalk.yellow("\n  server now waiting for connections. CTRL+C to stop"));

    process.on("SIGINT", async () => {
        // only work on linux apparently
        await server.shutdown(1000);
        console.log(chalk.red.bold(" shutting down completed "));
        process.exit(-1);
    });
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:50,代码来源:server_with_push_certificate.ts

示例6: startMultiHeadServer

async function startMultiHeadServer() {

    const server_options: OPCUAServerOptions = {
        isAuditing: false,
        nodeset_filename: [
            nodesets.standard
        ],
        serverInfo: {
            applicationName: { text: "Mini NodeOPCUA Server", locale: "en" },
            applicationUri: makeApplicationUrn("%FQDN%", "MiniNodeOPCUA-Server"),
            productUri: "Mini NodeOPCUA-Server"
        },

        // default endpoint
        allowAnonymous: false,
        alternateHostname: ["MyHostname1"],
        port: port1,
        securityModes: [MessageSecurityMode.None],
        securityPolicies: [SecurityPolicy.None],

        // alternate endpoint
        alternateEndpoints: [
            {
                allowAnonymous: false,
                alternateHostname: ["1.2.3.4"],
                port: port2,
                securityModes: [MessageSecurityMode.SignAndEncrypt],
                securityPolicies: [SecurityPolicy.Basic256Sha256]
            }
        ]
    };

    server = new OPCUAServer(server_options);

    server.on("post_initialize", () => {/**/
    });

    console.log(chalk.yellow("  server PID          :"), process.pid);

    try {
        await server.start();
    } catch (err) {
        console.log(" Server failed to start ... exiting => err:", err.message);
        return;
    }

}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:47,代码来源:test_server_with_alternate_names.ts

示例7: startServer

async function startServer() {

    const server_options: OPCUAServerOptions = {

        port: port1,

        nodeset_filename: [
            nodesets.standard
        ],

        serverInfo: {
            applicationUri: makeApplicationUrn("%FQDN%", "MiniNodeOPCUA-Server"),
            productUri: "Mini NodeOPCUA-Server",

            applicationName: { text: "Mini NodeOPCUA Server", locale: "en" }

        },

        alternateHostname: ["MyHostname1", "MyHostname2"],

        isAuditing: false
    };

    server = new OPCUAServer(server_options);

    server.on("post_initialize", () => {/**/
    });

    console.log(chalk.yellow("  server PID          :"), process.pid);

    try {
        await server.start();
    } catch (err) {
        console.log(" Server failed to start ... exiting => err:", err.message);
        return;
    }

    for (const endpoint of server.endpoints) {
        const endpointUrl = endpoint.endpointDescriptions()[0].endpointUrl!;
        console.log(chalk.yellow("  server on port1      :"), endpoint.port.toString());
        console.log(chalk.yellow("  endpointUrl1         :"), chalk.cyan(endpointUrl));
    }

}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:44,代码来源:test_server_with_alternate_names.ts

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