How to use the node-opcua-variant.isValidVariant function in node-opcua-variant

To help you get started, we’ve selected a few node-opcua-variant 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
assert(dataType !== null); // check invalid dataType

            let setter_func2 = null;
            if (setter_func) {
                setter_func2 = function (variant) {
                    const variable2 = !!variant.value;
                    setter_func(variable2);
                    return StatusCodes.Good;
                };
            }

            const nodeId = makeNodeId(id);

            // make sur the provided function returns a valid value for the variant type
            // This test may not be exhaustive but it will detect obvious mistakes.
            assert(isValidVariant(VariantArrayType.Scalar, dataType, func()));
            return bindVariableIfPresent(nodeId, {
                get: function () {
                    return new Variant({
                        dataType: dataType,
                        arrayType: VariantArrayType.Scalar,
                        value: func()
                    });
                },
                set: setter_func2

            });
        }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
let setter_func2 = null;
        if (setter_func) {
          setter_func2 = (variant: Variant) => {
            const variable2 = !!variant.value;
            setter_func(variable2);
            return StatusCodes.Good;
          };
        }

        const nodeId = makeNodeId(id);

        // make sur the provided function returns a valid value for the variant type
        // This test may not be exhaustive but it will detect obvious mistakes.

        /* istanbul ignore next */
        if (!isValidVariant(VariantArrayType.Scalar, dataType, func())) {

          errorLog("func", func());
          throw new Error("bindStandardScalar : func doesn't provide an value of type " + DataType[dataType]);
        }

        return bindVariableIfPresent(nodeId, {
          get() {
            return new Variant({
              arrayType: VariantArrayType.Scalar,
              dataType,
              value: func()
            });
          },
          set: setter_func2

        });
github node-opcua / node-opcua / packages / node-opcua-server / src / server_engine.js View on Github external
function bindStandardArray(id, variantDataType, dataType, func) {

            assert(_.isFunction(func));
            assert(variantDataType !== null); // check invalid dataType

            const nodeId = makeNodeId(id);

            // make sur the provided function returns a valid value for the variant type
            // This test may not be exhaustive but it will detect obvious mistakes.
            assert(isValidVariant(VariantArrayType.Array, dataType, func()));

            bindVariableIfPresent(nodeId, {
                get: function () {
                    const value = func();
                    assert(_.isArray(value));
                    return new Variant({
                        dataType: variantDataType,
                        arrayType: VariantArrayType.Array,
                        value: value
                    });
                },
                set: null // read only
            });
        }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
function bindStandardArray(
        id: number,
        variantDataType: DataType,
        dataType: any,
        func: () => any[]
      ) {

        assert(_.isFunction(func));
        assert(variantDataType !== null); // check invalid dataType

        const nodeId = makeNodeId(id);

        // make sur the provided function returns a valid value for the variant type
        // This test may not be exhaustive but it will detect obvious mistakes.
        assert(isValidVariant(VariantArrayType.Array, variantDataType, func()));

        bindVariableIfPresent(nodeId, {
          get() {
            const value = func();
            assert(_.isArray(value));
            return new Variant({
              arrayType: VariantArrayType.Array,
              dataType: variantDataType,
              value
            });
          },
          set: null // read only
        });
      }