How to use node-opcua-service-call - 10 common examples

To help you get started, we’ve selected a few node-opcua-service-call 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-client-proxy / source / object_explorer.ts View on Github external
// xx console.log("xxx ",arg.toString());
            const propName = lowerFirstLetter(arg.name);

            const value = inputArgs[propName];
            if (value === undefined) {
                throw new Error("expecting input argument " + propName);
            }
            if (arrayType === VariantArrayType.Array) {
                if (!_.isArray(value)) {
                    throw new Error("expecting value to be an Array or a TypedArray");
                }
            }
            return new Variant({arrayType, dataType, value});
        });

        const methodToCall = new CallMethodRequest({
            inputArguments,
            methodId: reference.nodeId,
            objectId: obj.nodeId,
        });

        session.call(methodToCall, (err: Error | null, callResult?: CallMethodResult) => {

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

            callResult = callResult!;

            if (callResult.statusCode !== StatusCodes.Good) {
                return callback(new Error("Error " + callResult.statusCode.toString()));
github node-opcua / node-opcua / packages / node-opcua-client-proxy / src / proxy.js View on Github external
const propName = lowerFirstLetter(arg.name);

                const value = inputArgs[propName];
                if (value === undefined) {
                    throw new Error("expecting input argument " + propName);
                }
                if (arrayType === VariantArrayType.Array) {
                    if (!_.isArray(value)) {
                        throw new Error("expecting value to be an Array or a TypedArray");
                    }
                }

                return new Variant({arrayType: arrayType, dataType: dataType, value: value});
            });

            const methodToCall = new call_service.CallMethodRequest({
                objectId: obj.nodeId,
                methodId: reference.nodeId,
                inputArguments: inputArguments
            });

            //xx console.log(" calling ",methodToCall.toString());

            session.call(methodToCall, function (err, callResult) {

                // istanbul ignore next
                if (err) {
                    return callback(err);
                }
                if (callResult.statusCode !== StatusCodes.Good) {
                    return callback(new Error("Error " + callResult.statusCode.toString()));
                }
github node-opcua / node-opcua / packages / node-opcua-client / source / alarms_and_conditions / client_tools.ts View on Github external
(innerCallback: ErrorCallback) => {

            const methodToCalls = [];

            methodToCalls.push(new CallMethodRequest({
                inputArguments: [
                    /* eventId */ new Variant({ dataType: "ByteString", value: eventId }),
                    /* comment */ new Variant({ dataType: "LocalizedText", value: comment })
                ],
                methodId,
                objectId: conditionId
            }));

            this.call(methodToCalls, (err: Error | null, results?: CallMethodResult[]) => {
                if (err) {
                    return innerCallback(err);
                }
                statusCode = results![0].statusCode;
                innerCallback();
            });
        }
github node-opcua / node-opcua / packages / node-opcua-client / src / client_session.js View on Github external
ClientSession.prototype.getMonitoredItems = function (subscriptionId, callback) {

    // 
    // 
    // 
    const self = this;
    const methodsToCall =
        new call_service.CallMethodRequest({
            objectId: coerceNodeId("ns=0;i=2253"),  // ObjectId.Server
            methodId: coerceNodeId("ns=0;i=11492"), // MethodIds.Server_GetMonitoredItems;
            inputArguments: [
                // BaseDataType
                {dataType: DataType.UInt32, value: subscriptionId}
            ]
        });

    self.call([methodsToCall], function (err, result) {

            /* istanbul ignore next */
            if (err) {
                return callback(err);
            }

            result = result[0];
github node-opcua / node-opcua / packages / node-opcua-server / src / server_engine.js View on Github external
const subscription = session.getSubscription(subscriptionId);
    if (!subscription) {
        // subscription may belongs to a different session  that ours
        if (engine.findSubscription(subscriptionId)) {
            // if yes, then access to  Subscription data should be denied
            return callback(null, {statusCode: StatusCodes.BadUserAccessDenied});
        }

        return callback(null, {statusCode: StatusCodes.BadSubscriptionIdInvalid});
    }
    const result = subscription.getMonitoredItems();
    assert(result.statusCode);
    assert(_.isArray(result.serverHandles));
    assert(_.isArray(result.clientHandles));
    assert(result.serverHandles.length === result.clientHandles.length);
    const callMethodResult = new CallMethodResult({
        statusCode: result.statusCode,
        outputArguments: [
            {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.serverHandles},
            {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.clientHandles}
        ]
    });
    callback(null, callMethodResult);

}
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
const subscription = session.getSubscription(subscriptionId);
  if (!subscription) {
    // subscription may belongs to a different session  that ours
    if (engine.findSubscription(subscriptionId)) {
      // if yes, then access to  Subscription data should be denied
      return callback(null, { statusCode: StatusCodes.BadUserAccessDenied });
    }

    return callback(null, { statusCode: StatusCodes.BadSubscriptionIdInvalid });
  }
  const result = subscription.getMonitoredItems();
  assert(result.statusCode);
  assert(_.isArray(result.serverHandles));
  assert(_.isArray(result.clientHandles));
  assert(result.serverHandles.length === result.clientHandles.length);
  const callMethodResult = new CallMethodResult({
    statusCode: result.statusCode,

    outputArguments: [
      { dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.serverHandles },
      { dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.clientHandles }
    ]
  });
  callback(null, callMethodResult);

}
github node-opcua / node-opcua / packages / node-opcua-client / src / client_session.js View on Github external
self.performMessageTransaction(request, function (err, response) {

        /* istanbul ignore next */
        if (err) {
            return callback(err);
        }
        assert(response instanceof call_service.CallResponse);
        callback(null, isArray ? response.results : response.results[0]);

    });
github node-opcua / node-opcua / packages / node-opcua-client / src / client_session.js View on Github external
ClientSession.prototype.call = function (methodsToCall, callback) {

    const self = this;

    const isArray = _.isArray(methodsToCall);
    if (!isArray) { methodsToCall = [methodsToCall]; }

    assert(_.isArray(methodsToCall));

    // Note : The client has no explicit address space and therefore will struggle to
    //        access the method arguments signature.
    //        There are two methods that can be considered:
    //           - get the object definition by querying the server
    //           - load a fake address space to have some thing to query on our end
    // const request = self._client.factory.constructObjectId("CallRequest",{ methodsToCall: methodsToCall});
    const request = new call_service.CallRequest({methodsToCall: methodsToCall});

    self.performMessageTransaction(request, function (err, response) {

        /* istanbul ignore next */
        if (err) {
            return callback(err);
        }
        assert(response instanceof call_service.CallResponse);
        callback(null, isArray ? response.results : response.results[0]);

    });

};
github node-opcua / node-opcua / packages / node-opcua-address-space / src / address_space_add_method.js View on Github external
value: options.inputArguments.map(function (opt) {
                    return new Argument(opt);
                })
            });

node-opcua-service-call

pure nodejs OPCUA SDK - module service-call

MIT
Latest version published 2 months ago

Package Health Score

86 / 100
Full package analysis