• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript node-opcua-client.ClientSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: describe


//.........这里部分代码省略.........

        };

        const server = new OPCUAServer({

            port: 2010,

            nodeset_filename: nodesets.standard,
            userManager: mockUserManager,

            serverCertificateManager: certificateManager,
            userCertificateManager: certificateManager
        });
        await server.initialize();

        verifyServer(server);

        await installPushCertificateManagementOnServer(server);
        debugLog("private key location =  ", server.serverCertificateManager.privateKey);

        verifyServer(server);

        // Given that the server is configured to trust client certificate
        const clientCertificatePEM = await promisify(fs.readFile)(clientCertificateFile, "utf8");
        const clientCertificateDER = convertPEMtoDER(clientCertificatePEM);
        await server.serverCertificateManager.trustCertificate(clientCertificateDER);

        // also trusted newest certificate

        return server;
    }

    let onGoingClient: OPCUAClient;
    let onGoingSession: ClientSession;
    let count = 0;

    async function testWithSimpleClient(endpointUri: string) {

        const client = OPCUAClient.create({
            certificateFile: clientCertificateFile,
            privateKeyFile: clientPrivateKeyFile,
            securityMode: MessageSecurityMode.SignAndEncrypt,
            securityPolicy: SecurityPolicy.Basic256
        });
        try {
            await client.connect(endpointUri);
            const session = await client.createSession();

            await session.close();
        } catch (err) {
            errorLog("Cannot reconnect a client !!!! ", err.message, "\n", err);
        } finally {
            await client.disconnect();
        }

    }

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

            securityMode: MessageSecurityMode.SignAndEncrypt,
            securityPolicy: SecurityPolicy.Basic256
        });
        onGoingClient.on("start_reconnection", () => {
开发者ID:node-opcua,项目名称:node-opcua,代码行数:67,代码来源:test_server_with_push_certificate_management.ts


示例3: callback

    session.read(nodeToRead, (err: Error | null, dataValue?: DataValue) => {

        // istanbul ignore next
        if (err) {
             setImmediate(() => {
                callback(err);
            });
             return;
        }

        dataValue = dataValue!;

        let dataType: DataType;
        // istanbul ignore next
        if (dataValue.statusCode !== StatusCodes.Good) {
            dataType = DataType.Null;
            setImmediate(() => {
                callback(null, dataType);
            });
            return;
        }

        const dataTypeName = dataValue.value.value;

        if (dataTypeId.namespace === 0 && DataType[dataTypeId.value as number]) {
            dataType = (DataType as any)[dataTypeId.value as number] as DataType;
            setImmediate(() => {
                callback(null, dataType);
            });
            return;
        }

        /// example => Duration (i=290) => Double (i=11)
        // read subTypeOf
        const nodeToBrowse = {
            browseDirection: BrowseDirection.Inverse,
            includeSubtypes: false,
            nodeId: dataTypeId,
            // BrowseDescription
            referenceTypeId: makeRefId("HasSubtype"),
            // xx nodeClassMask: makeNodeClassMask("ObjectType"),
            resultMask
        };
        // tslint:disable:no-shadowed-variable
        session.browse(nodeToBrowse, (err: Error | null, browseResult?: BrowseResult) => {
            // istanbul ignore next
            if (err) {
                return callback(err);
            }

            const references = browseResult!.references;

            if (!references || references.length !== 1) {
                return callback(new Error("cannot find SuperType of " + dataTypeName.toString()));
            }
            const nodeId = references[0].nodeId;
            return convertNodeIdToDataTypeAsync(session, nodeId, callback);
        });
    });
开发者ID:node-opcua,项目名称:node-opcua,代码行数:59,代码来源:object_explorer.ts


示例4: stopOnGoingConnection

    async function stopOnGoingConnection() {

        debugLog("stopping");
        await new Promise((resolve) => setTimeout(resolve, 5000));
        debugLog("stopOnGoingConnection - Server certificate is now ",
          makeSHA1Thumbprint(onGoingClient.serverCertificate!).toString("base64"));
        await onGoingSession.close();
        await onGoingClient.disconnect();
    }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:9,代码来源:test_server_with_push_certificate_management.ts


示例5: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap