How to use the node-opcua-status-code.StatusCodes.BadTypeMismatch 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-address-space / src / ua_variable.ts View on Github external
if (!err) {

                correctedDataValue = correctedDataValue || dataValue;
                assert(correctedDataValue instanceof DataValue);
                // xx assert(correctedDataValue.serverTimestamp);

                if (indexRange && !indexRange.isEmpty()) {

                    if (!indexRange.isValid()) {
                        return callback!(null, StatusCodes.BadIndexRangeInvalid);
                    }

                    const newArr = correctedDataValue.value.value;
                    // check that source data is an array
                    if (correctedDataValue.value.arrayType !== VariantArrayType.Array) {
                        return callback!(null, StatusCodes.BadTypeMismatch);
                    }

                    // check that destination data is also an array
                    assert(check_valid_array(this._dataValue.value.dataType, this._dataValue.value.value));
                    const destArr = this._dataValue.value.value;
                    const result = indexRange.set_values(destArr, newArr);

                    if (result.statusCode.isNot(StatusCodes.Good)) {
                        return callback!(null, result.statusCode);
                    }
                    correctedDataValue.value.value = result.array;

                    // scrap original array so we detect range
                    this._dataValue.value.value = null;
                }
                this._internal_set_dataValue(correctedDataValue, indexRange);
github node-opcua / node-opcua / packages / node-opcua-address-space / source / helpers / argument_list.ts View on Github external
// istanbul ignore next
        if (doDebug) {
            debugLog("verifyArguments_ArgumentList checking argument " + i +
              "\n        argDefinition is    : " + JSON.stringify(argDefinition) +
              "\n        corresponding arg is: " + JSON.stringify(arg));
        }
        if (!isArgumentValid(addressSpace, argDefinition, arg)) {
            // istanbul ignore next
            if (doDebug) {
                debugLog("verifyArguments_ArgumentList \n" +
                  "         The client did specify a argument with the wrong data type.\n" +
                  chalk.white("          expected : ") + argDefinition.dataType + "\n" +
                  chalk.cyan("          actual   :") + arg.dataType);
            }
            inputArgumentResults.push(StatusCodes.BadTypeMismatch);
            errorCount += 1;
        } else {
            inputArgumentResults.push(StatusCodes.Good);
        }
    }
    assert(inputArgumentResults.length === methodInputArguments.length);

    const ret = {
        inputArgumentResults,
        statusCode: errorCount === 0 ? StatusCodes.Good : StatusCodes.BadInvalidArgument
    };

    return ret;
}
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
public checkVariantCompatibility(value: Variant): StatusCode {
        // test dataType
        if (!this._validate_DataType(value.dataType)) {
            return StatusCodes.BadTypeMismatch;
        }
        return StatusCodes.Good;
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / data_access / ua_analog_item.ts View on Github external
public checkVariantCompatibility(value: Variant): StatusCode {

        assert(value instanceof Variant);
        // test dataType
        if (!this._validate_DataType(value.dataType)) {
            return StatusCodes.BadTypeMismatch;
        }

        // AnalogDataItem
        if (this.instrumentRange) {
            if (!validate_value_range(this.instrumentRange.readValue().value.value, value)) {
                return StatusCodes.BadOutOfRange;
            }
        }
        return StatusCodes.Good;
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
if (!err) {

            correctedDataValue = correctedDataValue || dataValue;
            assert(correctedDataValue instanceof DataValue);
            //xx assert(correctedDataValue.serverTimestamp);

            if (indexRange && !indexRange.isEmpty()) {

                if (!indexRange.isValid()) {
                    return callback(null, StatusCodes.BadIndexRangeInvalid);
                }

                const newArr = correctedDataValue.value.value;
                // check that source data is an array
                if (correctedDataValue.value.arrayType !== VariantArrayType.Array) {
                    return callback(null, StatusCodes.BadTypeMismatch);
                }

                // check that destination data is also an array
                assert(check_valid_array(self._dataValue.value.dataType, self._dataValue.value.value));
                const destArr = self._dataValue.value.value;
                const result = indexRange.set_values(destArr, newArr);

                if (result.statusCode.isNot(StatusCodes.Good)) {
                    return callback(null, result.statusCode);
                }
                correctedDataValue.value.value = result.array;

                // scrap original array so we detect range
                self._dataValue.value.value = null;
            }
            self._internal_set_dataValue(correctedDataValue, indexRange);
github node-opcua / node-opcua / packages / node-opcua-server / src / server_engine.js View on Github external
ServerEngine.prototype.writeSingleNode = function (context, writeValue, callback) {

    const engine = this;
    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);
    assert(engine.addressSpace instanceof AddressSpace); // initialize not called

    const nodeId = writeValue.nodeId;

    const obj = engine.__findObject(nodeId);
    if (!obj) {
        return callback(null, StatusCodes.BadNodeIdUnknown);
    } else {
        obj.writeAttribute(context, writeValue, callback);
    }
};
github node-opcua / node-opcua / packages / node-opcua-address-space / src / data_access / ua_multistate_discrete.ts View on Github external
public checkVariantCompatibility(value: Variant): StatusCode {
        if (!this._validate_DataType(value.dataType)) {
            return StatusCodes.BadTypeMismatch;
        }
        if (this.enumStrings) {
            const arrayEnumStrings = this.enumStrings.readValue().value.value;
            // MultiStateDiscreteType
            assert(value.dataType === DataType.UInt32);
            if (value.value >= arrayEnumStrings.length) {
                return StatusCodes.BadOutOfRange;
            }
        }
        return StatusCodes.Good;
    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
public writeSingleNode(
    context: SessionContext,
    writeValue: WriteValue,
    callback: (err: Error | null, statusCode?: StatusCode) => void
  ) {

    const engine = this;
    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);
    }
  }