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


TypeScript ClientSession.createSubscription2方法代码示例

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


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

示例1: startOnGoingConnection

    async function startOnGoingConnection(endpointUri: string) {
        onGoingClient = OPCUAClient.create({
            certificateFile: clientCertificateFile,
            privateKeyFile: clientPrivateKeyFile,

            securityMode: MessageSecurityMode.SignAndEncrypt,
            securityPolicy: SecurityPolicy.Basic256
        });
        onGoingClient.on("start_reconnection", () => {
            debugLog(chalk.bgWhite.red(" !!!!!!!!!!!!!!!!!!!!!!!!  Starting Reconnection !!!!!!!!!!!!!!!!!!!"));
        });
        onGoingClient.on("backoff", (retry: number, delay: number) => {
            debugLog(chalk.bgWhite.yellow("backoff  attempt #"), retry, " retrying in ", delay / 1000.0, " seconds");
        });
        onGoingClient.on("connection_reestablished", () => {
            debugLog(chalk.bgWhite.red(" !!!!!!!!!!!!!!!!!!!!!!!!  CONNECTION RE-ESTABLISHED !!!!!!!!!!!!!!!!!!!"));
            debugLog("    Server certificate is now ", makeSHA1Thumbprint(onGoingClient.serverCertificate!).toString("base64"));
        });
        onGoingClient.on("connection_lost", () => {
            debugLog(chalk.bgWhite.red("Client has lost connection ..."));
            debugLog(chalk.bgWhite.red("    Server certificate was ", makeSHA1Thumbprint(onGoingClient.serverCertificate!).toString("base64")));
        });

        onGoingClient.on("close", () => {
            debugLog(chalk.bgWhite.red("client has CLOOOOOOOOOOSSSSSED"));
        });

        await onGoingClient.connect(endpointUri);
        onGoingSession = await onGoingClient.createSession();

        const subscription = await onGoingSession.createSubscription2({
            requestedPublishingInterval: 500,

            maxNotificationsPerPublish: 1000,
            publishingEnabled: true,
            requestedLifetimeCount: 100,
            requestedMaxKeepAliveCount: 10
        });

        const monitoredItem = await subscription.monitor({
              attributeId: AttributeIds.Value,
              nodeId: "i=2258" // Current Time
          },
          { samplingInterval: 500 }, TimestampsToReturn.Both);

        count = 0;
        monitoredItem.on("changed", (dataValue: DataValue) => {
            debugLog(" ", chalk.cyan(dataValue.value.toString()));
            count++;
        });

        await new Promise((resolve) => setTimeout(resolve, 1500));

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

示例2: test1

async function test1() {

    try {

        await client.connect("opc.tcp://opcuademo.sterfive.com:26543");

        const session: ClientSession = await client.createSession({
            type: UserTokenType.UserName,

            password: "password1",
            userName: "user1"
        });

        const subscription = await session.createSubscription2({
            maxNotificationsPerPublish: 1000,
            publishingEnabled: true,
            requestedLifetimeCount: 100,
            requestedMaxKeepAliveCount: 10,
            requestedPublishingInterval: 1000
        });

        subscription.on("raw_notification", (n) => {
            console.log(n.toString());
        });

        const parameters1: MonitoringParametersOptions = {
            discardOldest: true,
            queueSize: 100,
            samplingInterval: 100,

            filter: new DataChangeFilter({
                deadbandType: DeadbandType.Absolute,
                deadbandValue: 0.1,
                trigger: DataChangeTrigger.StatusValueTimestamp
            })
        };
        const itemToMonitor1: ReadValueIdLike = {
            attributeId: AttributeIds.Value,
            nodeId: "ns=1;s=FanSpeed"
        };

        const item1 = await subscription.monitor(itemToMonitor1, parameters1, TimestampsToReturn.Both);

        console.log(" Item1 = ", item1.result!.statusCode.toString());

        item1.on("changed", (dataValue: DataValue) => {
            console.log(" Value1 has changed : ", dataValue.toString());
        });
        const itemToMonitor2: ReadValueIdLike = {
            attributeId: AttributeIds.EventNotifier,
            nodeId: "i=2258"
        };
        const parameters2: MonitoringParametersOptions = {
            discardOldest: true,
            filter: new EventFilter({}),
            queueSize: 100,
            samplingInterval: 0
        };
        const item2 = subscription.monitor(itemToMonitor2, parameters2, TimestampsToReturn.Both);

        await timeout(20000);

        await subscription.terminate();

        await client.disconnect();

        console.log(" Done!");

    } catch (e) {
        // Deal with the fact the chain failed
        console.log(chalk.red("Error !"), e);
        process.exit(-1);
    }

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


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