How to use the node-opcua-status-code.StatusCodes.BadNodeIdUnknown function in node-opcua-status-code

To help you get started, we’ve selected a few node-opcua-status-code 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 / src / server_engine.js View on Github external
const dataEncoding = nodeToRead.dataEncoding;
    const continuationPoint = nodeToRead.continuationPoint;
    assert(engine.addressSpace instanceof AddressSpace); // initialize not called

    if (timestampsToReturn === TimestampsToReturn.Invalid) {
        return new DataValue({statusCode: StatusCodes.BadTimestampsToReturnInvalid});
    }

    timestampsToReturn = (_.isObject(timestampsToReturn)) ? timestampsToReturn : TimestampsToReturn.Neither;

    const obj = engine.__findObject(nodeId);

    if (!obj) {
        // may be return BadNodeIdUnknown in dataValue instead ?
        // Object Not Found
        callback(null, new HistoryReadResult({statusCode: StatusCodes.BadNodeIdUnknown}));
    } else {

        if (!obj.historyRead) {
            // note : Object and View may also support historyRead to provide Event historical data
            //        todo implement historyRead for Object and View
            const msg = " this node doesn't provide historyRead! probably not a UAVariable\n "
                + obj.nodeId.toString() + " " + obj.browseName.toString() + "\n"
                + "with " + nodeToRead.toString() + "\n"
                + "HistoryReadDetails " + historyReadDetails.toString();
            if (doDebug) {
                console.log("ServerEngine#_historyReadSingleNode ".cyan, msg.white.bold);
            }
            const err = new Error(msg);
            // object has no historyRead method
            return setImmediate(callback.bind(null, err));
        }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / argument_list.js View on Github external
function getMethodDeclaration_ArgumentList(addressSpace, objectId, methodId) {

    assert(objectId instanceof NodeId);
    assert(methodId instanceof NodeId);
    // find object in address space
    const obj = addressSpace.findNode(objectId);
    if (!obj) {

        // istanbul ignore next
        if(doDebug) {
            console.warn("cannot find node ",objectId.toString());
        }
        return {statusCode: StatusCodes.BadNodeIdUnknown};
    }
    if (!obj.hasMethods) {
        return {statusCode: StatusCodes.BadNodeIdInvalid};
    }
    let objectMethod = obj.getMethodById(methodId);
    if (!objectMethod) {

        // the method doesn't belong to the object, nevertheless
        // the method can be called
        objectMethod = addressSpace.findNode(methodId);
        if (!objectMethod || !(objectMethod instanceof UAMethod)) {
            return {statusCode: StatusCodes.BadMethodInvalid};
        }
    }

    const methodDeclarationId = objectMethod.methodDeclarationId;
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
assert(context instanceof SessionContext);
    assert(callback instanceof Function);

    const nodeId = nodeToRead.nodeId;
    const indexRange = nodeToRead.indexRange;
    const dataEncoding = nodeToRead.dataEncoding;
    const continuationPoint = nodeToRead.continuationPoint;

    timestampsToReturn = (_.isObject(timestampsToReturn)) ? timestampsToReturn : TimestampsToReturn.Neither;

    const obj = this.__findObject(nodeId) as UAVariable;

    if (!obj) {
      // may be return BadNodeIdUnknown in dataValue instead ?
      // Object Not Found
      callback(null, new HistoryReadResult({ statusCode: StatusCodes.BadNodeIdUnknown }));
      return;

    } else {

      if (!obj.historyRead) {
        // note : Object and View may also support historyRead to provide Event historical data
        //        todo implement historyRead for Object and View
        const msg = " this node doesn't provide historyRead! probably not a UAVariable\n "
          + obj.nodeId.toString() + " " + obj.browseName.toString() + "\n"
          + "with " + nodeToRead.toString() + "\n"
          + "HistoryReadDetails " + historyReadDetails.toString();
        if (doDebug) {
          console.log(chalk.cyan("ServerEngine#_historyReadSingleNode "),
            chalk.white.bold(msg));
        }
        const err = new Error(msg);
github node-opcua / node-opcua / packages / node-opcua-address-space / source / helpers / argument_list.ts View on Github external
addressSpace: AddressSpace,
  objectId: NodeId,
  methodId: NodeId
): any {

    assert(objectId instanceof NodeId);
    assert(methodId instanceof NodeId);
    // find object in address space
    const obj = addressSpace.findNode(objectId) as UAObject;
    if (!obj) {

        // istanbul ignore next
        if (doDebug) {
            debugLog("cannot find node ", objectId.toString());
        }
        return { statusCode: StatusCodes.BadNodeIdUnknown };
    }
    let objectMethod = obj.getMethodById(methodId) as UAMethod;
    if (!objectMethod) {

        // the method doesn't belong to the object, nevertheless
        // the method can be called
        objectMethod = addressSpace.findNode(methodId) as UAMethod;
        if (!objectMethod || objectMethod.nodeClass !== NodeClass.Method) {
            return { statusCode: StatusCodes.BadMethodInvalid };
        }
    }

    const methodDeclarationId = (objectMethod as any).methodDeclarationId;

    const methodDeclaration = addressSpace.findNode(methodDeclarationId);
    if (!methodDeclaration) {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / address_space_browse.js View on Github external
AddressSpace.prototype.browsePath = function (browsePath) {

        const self = this;

        assert(browsePath instanceof translate_service.BrowsePath);

        const startingNode = self.findNode(browsePath.startingNode);

        if (!startingNode) {
            return new BrowsePathResult({statusCode: StatusCodes.BadNodeIdUnknown});
        }

        if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
            return new BrowsePathResult({
                statusCode: StatusCodes.BadNothingToDo,
                targets: []
            });
        }


        const elements_length = browsePath.relativePath.elements.length;
        //-------------------------------------------------------------------------------------------------------
        // verify standard RelativePath construction
        //   from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
        //   TargetName  The BrowseName of the target node.
        //               The final element may have an empty targetName. In this situation all targets of the
github node-opcua / node-opcua / packages / node-opcua-address-space / src / address_space.ts View on Github external
public browsePath(browsePath: BrowsePath): BrowsePathResult {

        assert(browsePath instanceof BrowsePath);

        const startingNode = this.findNode(browsePath.startingNode);

        if (!startingNode) {
            return new BrowsePathResult({ statusCode: StatusCodes.BadNodeIdUnknown });
        }

        if (!browsePath.relativePath.elements || browsePath.relativePath.elements.length === 0) {
            return new BrowsePathResult({
                statusCode: StatusCodes.BadNothingToDo,
                targets: []
            });
        }

        const elements_length = browsePath.relativePath.elements.length;
        // -------------------------------------------------------------------------------------------------------
        // verify standard RelativePath construction
        //   from OPCUA 1.03 - PArt 3 - 7.6 RelativePath:
        //   TargetName  The BrowseName of the target node.
        //               The final element may have an empty targetName. In this situation all targets of the
        //               references identified by the referenceTypeId are the targets of the RelativePath.
github node-opcua / node-opcua / packages / node-opcua-server / src / server_subscription.js View on Github external
Subscription.prototype.createMonitoredItem = function (addressSpace, timestampsToReturn, monitoredItemCreateRequest) {

    const subscription = this;
    assert(addressSpace.constructor.name === "AddressSpace");
    assert(monitoredItemCreateRequest instanceof MonitoredItemCreateRequest);


    function handle_error(statusCode) {
        return new subscription_service.MonitoredItemCreateResult({statusCode: statusCode});
    }

    const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;

    const node = addressSpace.findNode(itemToMonitor.nodeId);
    if (!node) {
        return handle_error(StatusCodes.BadNodeIdUnknown);
    }


    if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
        // AttributeIds.Value is only valid for monitoring value of UAVariables.
        return handle_error(StatusCodes.BadAttributeIdInvalid);
    }


    if (itemToMonitor.attributeId === AttributeIds.INVALID) {
        return handle_error(StatusCodes.BadAttributeIdInvalid);
    }

    if (!itemToMonitor.indexRange.isValid()) {
        return handle_error(StatusCodes.BadIndexRangeInvalid);
    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_subscription.ts View on Github external
addressSpace: AddressSpace,
    timestampsToReturn: TimestampsToReturn,
    monitoredItemCreateRequest: MonitoredItemCreateRequest
  ): MonitoredItemCreateResult {

    assert(monitoredItemCreateRequest instanceof MonitoredItemCreateRequest);

    function handle_error(statusCode: StatusCode): MonitoredItemCreateResult {
      return new MonitoredItemCreateResult({ statusCode });
    }

    const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;

    const node = addressSpace.findNode(itemToMonitor.nodeId);
    if (!node) {
      return handle_error(StatusCodes.BadNodeIdUnknown);
    }

    if (itemToMonitor.attributeId === AttributeIds.Value && !(node.nodeClass === NodeClass.Variable)) {
      // AttributeIds.Value is only valid for monitoring value of UAVariables.
      return handle_error(StatusCodes.BadAttributeIdInvalid);
    }

    if (itemToMonitor.attributeId === AttributeIds.INVALID) {
      return handle_error(StatusCodes.BadAttributeIdInvalid);
    }

    if (!itemToMonitor.indexRange.isValid()) {
      return handle_error(StatusCodes.BadIndexRangeInvalid);
    }

    // check dataEncoding applies only on Values
github node-opcua / node-opcua / packages / node-opcua-client-proxy / src / proxy.js View on Github external
session.read(nodesToRead, 1, function (err, dataValues) {

                if (!err) {

                    if (dataValues[0].statusCode === StatusCodes.BadNodeIdUnknown) {
                        //xx console.log(" INVALID NODE ", nodeId.toString());
                        return callback(new Error("Invalid Node " + nodeId.toString()));
                    }

                    clientObject = new ProxyObject(proxyManager, nodeId);

                    ///x console.log("xxxx ,s",results.map(function(a){ return a.toString();}));

                    clientObject.browseName = dataValues[0].value.value;
                    clientObject.description = (dataValues[1].value ? dataValues[1].value.value : "");
                    clientObject.nodeClass = dataValues[2].value.value;
                    //xx console.log("xxx nodeClass = ",clientObject.nodeClass.toString());

                    if (clientObject.nodeClass === NodeClass.Variable) {
                        return read_accessLevels(clientObject, callback);
                    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
assert(context instanceof SessionContext);
    assert(_.isFunction(callback));
    assert(writeValue.schema.name === "WriteValue");
    assert(writeValue.value instanceof DataValue);

    if (writeValue.value.value === null) {
      return callback(null, StatusCodes.BadTypeMismatch);
    }

    assert(writeValue.value.value instanceof Variant);

    const nodeId = writeValue.nodeId;

    const obj = engine.__findObject(nodeId);
    if (!obj) {
      return callback(null, StatusCodes.BadNodeIdUnknown);
    } else {
      obj.writeAttribute(context, writeValue, callback);
    }
  }