How to use the node-opcua-service-subscription.CreateMonitoredItemsRequest function in node-opcua-service-subscription

To help you get started, we’ve selected a few node-opcua-service-subscription examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server / test_to_fix / test_subscriptions.js View on Github external
it("server should create a monitored item  (CreateMonitoredItems)", function (done) {


        // CreateMonitoredItemsRequest
        var request = new subscription_service.CreateMonitoredItemsRequest({
            subscriptionId: subscriptionId,
            timestampsToReturn: read_service.TimestampsToReturn.Both,
            itemsToCreate: [
                {
                    itemToMonitor: {
                        nodeId: ec.makeNodeId(VariableIds.Server_ServerStatus_CurrentTime)
                    },
                    monitoringMode: subscription_service.MonitoringMode.Sampling,
                    requestedParameters: {
                        clientHandle: 26,
                        samplingInterval: 100,
                        filter: null,
                        queueSize: 100,
                        discardOldest: true
                    }
                }
github node-opcua / node-opcua / packages / node-opcua-client / src / client_monitored_item_base.js View on Github external
ClientMonitoredItemBase._toolbox_monitor = function (subscription, timestampsToReturn, monitoredItems, done) {
    assert(_.isFunction(done));
    const itemsToCreate = [];
    for (let i = 0; i < monitoredItems.length; i++) {

        const monitoredItem = monitoredItems[i];
        const itemToCreate = monitoredItem._prepare_for_monitoring(done);
        if (_.isString(itemToCreate.error)) {
            return done(new Error(itemToCreate.error));
        }
        itemsToCreate.push(itemToCreate);
    }

    const createMonitorItemsRequest = new subscription_service.CreateMonitoredItemsRequest({
        subscriptionId: subscription.subscriptionId,
        timestampsToReturn: timestampsToReturn,
        itemsToCreate: itemsToCreate
    });

    assert(subscription.session);
    subscription.session.createMonitoredItems(createMonitorItemsRequest, function (err, response) {

        /* istanbul ignore next */
        if (err) {
            //xx console.log("ClientMonitoredItemBase#_toolbox_monitor:  ERROR in createMonitoredItems ".red, err.message);
            //xx  console.log("ClientMonitoredItemBase#_toolbox_monitor:  ERROR in createMonitoredItems ".red, err);
            //xx  console.log(createMonitorItemsRequest.toString());
        } else {
            assert(response instanceof subscription_service.CreateMonitoredItemsResponse);
github node-opcua / node-opcua / packages / node-opcua-client / src / client_subscription.js View on Github external
assert(test === subscription);

            // re-create monitored items

            const itemsToCreate = [];
            _.forEach(monitoredItems_old, function (monitoredItem /*, clientHandle*/) {
                assert(monitoredItem.monitoringParameters.clientHandle > 0);
                itemsToCreate.push({
                    itemToMonitor: monitoredItem.itemToMonitor,
                    monitoringMode: monitoredItem.monitoringMode,
                    requestedParameters: monitoredItem.monitoringParameters
                });

            });

            const createMonitorItemsRequest = new subscription_service.CreateMonitoredItemsRequest({
                subscriptionId: subscription.subscriptionId,
                timestampsToReturn: TimestampsToReturn.Both, // self.timestampsToReturn,
                itemsToCreate: itemsToCreate
            });

            subscription.session.createMonitoredItems(createMonitorItemsRequest, function (err, response) {

                if (!err) {
                    assert(response instanceof subscription_service.CreateMonitoredItemsResponse);
                    const monitoredItemResults = response.results;

                    monitoredItemResults.forEach(function (monitoredItemResult, index) {

                        const clientHandle = itemsToCreate[index].requestedParameters.clientHandle;
                        const monitoredItem = subscription.monitoredItems[clientHandle];
github node-opcua / node-opcua / packages / node-opcua-client / source / client_monitored_item_toolbox.ts View on Github external
monitoredItems: ClientMonitoredItemBase[],
        done: ErrorCallback
    ) {
        assert(_.isFunction(done));
        const itemsToCreate: MonitoredItemCreateRequestOptions[] = [];
        for (const monitoredItem of monitoredItems) {

            const monitoredItemI = monitoredItem as ClientMonitoredItemImpl;
            const itemToCreate = monitoredItemI._prepare_for_monitoring();
            if (_.isString(itemToCreate.error)) {
                return done(new Error(itemToCreate.error));
            }
            itemsToCreate.push(itemToCreate as MonitoredItemCreateRequestOptions);
        }

        const createMonitorItemsRequest = new CreateMonitoredItemsRequest({
            itemsToCreate,
            subscriptionId: subscription.subscriptionId,
            timestampsToReturn,
        });

        const session = subscription.session as ClientSessionImpl;
        assert(session,
            "expecting a valid session attached to the subscription ");
        session.createMonitoredItems(
            createMonitorItemsRequest,
            (err?: Error | null, response?: CreateMonitoredItemsResponse) => {

                /* istanbul ignore next */
                if (err) {
                    debugLog(chalk.red("ClientMonitoredItemBase#_toolbox_monitor:  ERROR in createMonitoredItems "));
                } else {