How to use the node-opcua-variant.DataType.ExtensionObject 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 / source / server_engine.ts View on Github external
});
      }

      bindStandardScalar(VariableIds.Server_EstimatedReturnTime,
        DataType.DateTime, () => minOPCUADate);

      // TimeZoneDataType
      const timeZoneDataType = addressSpace.findDataType(resolveNodeId(DataTypeIds.TimeZoneDataType))!;
      // xx console.log(timeZoneDataType.toString());

      const timeZone = new TimeZoneDataType({
        daylightSavingInOffset: /* boolean*/ false,
        offset: /* int16 */ 0
      });
      bindStandardScalar(VariableIds.Server_LocalTime,
        DataType.ExtensionObject, () => {
          return timeZone;
        });

      bindStandardScalar(VariableIds.Server_ServiceLevel,
        DataType.Byte, () => {
          return 255;
        });

      bindStandardScalar(VariableIds.Server_Auditing,
        DataType.Boolean, () => {
          return engine.isAuditing;
        });

      function bindServerDiagnostics() {

        bindStandardScalar(VariableIds.Server_ServerDiagnostics_EnabledFlag,
github node-opcua / node-opcua / packages / node-opcua-address-space / source / loader / load_nodeset2.ts View on Github external
function makeDefaultVariant(
    addressSpace: AddressSpacePublic,
    dataTypeNode: NodeId,
    valueRank: number
): VariantOptions | undefined {
    let variant: VariantOptions = { dataType: DataType.Null };
    const nodeDataType = addressSpace.findNode(dataTypeNode);

    if (nodeDataType) {
        const dataType = addressSpace.findCorrespondingBasicDataType(dataTypeNode);
        if (dataType === DataType.ExtensionObject) {
            // console.log("xxxxxxxxxx ", dataTypeNode.toString(addressSpace as any));
            return variant;
        }
        const dv = findSimpleType(DataType[dataType]).defaultValue;

        let arrayType: VariantArrayType = VariantArrayType.Scalar;
        const value = (typeof dv === "function") ? dv() : dv;
        //  if (dataType === DataType.ByteString ) { value = Buffer.alloc(0) }
        /*
        *  * n > 1                     : the Value is an array with the specified number of dimensions.
        *  * OneDimension (1):           The value is an array with one dimension.
        *  * OneOrMoreDimensions (0):    The value is an array with one or more dimensions.
        *  * Scalar (-1):                The value is not an array.
        *  * Any (-2):                   The value can be a scalar or an array with any number of dimensions.
        *  * ScalarOrOneDimension (-3):  The value can be a scalar or a one dimensional array.
        */
github node-opcua / node-opcua / packages / node-opcua-address-space / src / data_access / address_space_add_AnalogItem.js View on Github external
// use as automatically scaling a bar graph display
        // Sensor or instrument failure or deactivation can result in a return ed item value which is actually
        // outside  of  this range. Client software must be prepared to deal with this   possibility. Similarly a client
        // may attempt to write a value that is outside  of  this range back to the server. The exact behaviour
        // (accept, reject, clamp, etc.) in this case is server - dependent. However ,   in general servers  shall  be
        // prepared to handle this.
        //     Example:    EURange ::= {-200.0,1400.0}

        const euRange = namespace.addVariable({
            propertyOf: variable,
            typeDefinition: "PropertyType",
            browseName: {name:"EURange",namespaceIndex:0},
            dataType: "Range",
            minimumSamplingInterval: 0,
            value: new Variant({
                dataType: DataType.ExtensionObject, value: new Range(options.engineeringUnitsRange)
            }),
            modellingRule: options.modellingRule
        });


        const handler = variable.handle_semantic_changed.bind(variable);
        euRange.on("value_changed",handler);

        if (options.hasOwnProperty("instrumentRange")) {

            const instrumentRange =namespace.addVariable({
                propertyOf: variable,
                typeDefinition: "PropertyType",
                browseName: {name:"InstrumentRange",namespaceIndex:0},
                dataType: "Range",
                minimumSamplingInterval: 0,
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
self.bindVariable({
            timestamped_get: function () {
                self._dataValue.value.value = self.$extensionObject;
                const d = new DataValue(self._dataValue);
                d.value = new Variant(d.value);
                return d;
            },
            timestamped_set: function (dataValue, callback) {
                callback(null, StatusCodes.BadNotWritable);
            }
        }, true);

    }
    else {
        // verify that variant has the correct type
        assert(s.value.dataType === DataType.ExtensionObject);
        self.$extensionObject = s.value.value;
        assert(self.$extensionObject && self.$extensionObject.constructor, "expecting an valid extension object");
        assert(s.statusCode.equals(StatusCodes.Good));

        Constructor = addressSpace.getExtensionObjectConstructor(self.dataType);
        assert(Constructor);
        assert(self.$extensionObject.constructor.name === Constructor.name);
    }


    let property, field, camelCaseName;
    // ------------------------------------------------------
    // now bind each member
    // ------------------------------------------------------
    for (let fieldIndex = 0; fieldIndex < dt.definition.length; fieldIndex++) {
        field = dt.definition[fieldIndex];
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
function fix_ProgramStateMachineType_ProgramDiagnostics() {
          const nodeId = coerceNodeId("i=2399"); // ProgramStateMachineType_ProgramDiagnostics
          const variable = addressSpace.findNode(nodeId) as UAVariable;
          if (variable) {
            variable.setValueFromSource({
              dataType: DataType.ExtensionObject,
              value: new ProgramDiagnostic2DataType()
            });
          }
        }
        fix_ProgramStateMachineType_ProgramDiagnostics();
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
const self = this;
            this.bindVariable({
                timestamped_get() {
                    self._dataValue.value.value = self.$extensionObject;
                    const d = new DataValue(self._dataValue);
                    d.value = new Variant(d.value);
                    return d;
                },
                timestamped_set(dataValue, callback) {
                    callback(null, StatusCodes.BadNotWritable);
                }
            }, true);

        } else {
            // verify that variant has the correct type
            assert(s.value.dataType === DataType.ExtensionObject);
            this.$extensionObject = s.value.value;
            assert(this.$extensionObject && this.$extensionObject.constructor, "expecting an valid extension object");
            assert(s.statusCode.equals(StatusCodes.Good));

            Constructor = addressSpace.getExtensionObjectConstructor(this.dataType);
            assert(Constructor);
            assert(this.$extensionObject.constructor.name === Constructor.name);
        }

        let property: any;
        let camelCaseName: any;
        // ------------------------------------------------------
        // now bind each member
        // ------------------------------------------------------
        for (const field of dt.definition) {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
const dataTypeNodeId = addressSpace.findCorrespondingBasicDataType(field.dataType);
            assert(this.$extensionObject.hasOwnProperty(camelCaseName));

            if (doDebug) {
                const x = addressSpace.findNode(field.dataType)!.browseName.toString();
                const basicType = addressSpace.findCorrespondingBasicDataType(field.dataType);
                console.log(chalk.cyan("xxx"), " dataType",
                    w(field.dataType.toString(), 8),
                    w(field.name, 35),
                    "valueRank", chalk.cyan(w(field.valueRank, 3)),
                    chalk.green(w(x, 25)),
                    "basicType = ", chalk.yellow(w(basicType.toString(), 20)),
                    property.nodeId.toString(), property.readValue().statusCode.toString());
            }

            if (dataTypeNodeId === DataType.ExtensionObject) {
                assert(this.$extensionObject[camelCaseName] instanceof Object);
                this.$extensionObject[camelCaseName] = new Proxy(this.$extensionObject[camelCaseName], makeHandler(property));
                property._dataValue.value = new Variant({
                    dataType: DataType.ExtensionObject,
                    value: this.$extensionObject[camelCaseName]
                });
                property.bindExtensionObject();
                property.$extensionObject = this.$extensionObject[camelCaseName];

            } else {

                const dataTypeAsString = DataType[dataTypeNodeId];
                assert(typeof dataTypeAsString === "string");

                const preparedValue = prepareVariantValue(dataTypeNodeId, this.$extensionObject[camelCaseName]);
                property._dataValue.value = new Variant({
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
const x = addressSpace.findNode(field.dataType).browseName.toString();
            const basicType = addressSpace.findCorrespondingBasicDataType(field.dataType);
            console.log("xxx".cyan, " dataType",
                w(field.dataType.toString(), 8),
                w(field.name, 35),
                "valueRank", w(field.valueRank, 3).cyan,
                w(x, 25).green,
                "basicType = ", w(basicType.toString(), 20).yellow, property.nodeId.toString(),property.readValue().statusCode.toString());
        }


        if (dataTypeNodeId.value === DataType.ExtensionObject.value) {
            assert(self.$extensionObject[camelCaseName] instanceof Object);
            self.$extensionObject[camelCaseName] = new Proxy(self.$extensionObject[camelCaseName], makeHandler(property));
            property._dataValue.value = new Variant({
                dataType: DataType.ExtensionObject,
                value: self.$extensionObject[camelCaseName]
            });
            property.bindExtensionObject();
            property.$extensionObject = self.$extensionObject[camelCaseName];
        } else {
            const dataType = DataType.get(dataTypeNodeId.value);
            property._dataValue.value = new Variant({
                dataType: dataType,
                value: prepareVariantValue(dataType, self.$extensionObject[camelCaseName])
            });

            property.camelCaseName = camelCaseName;
            property.setValueFromSource = function (variant) {
                const inner_self = this;
                variant = Variant.coerce(variant);
                //xx console.log("PropertySetValueFromSource self", inner_self.nodeId.toString(), inner_self.browseName.toString(), variant.toString(), inner_self.dataType.toString());
github node-opcua / node-opcua / packages / node-opcua-address-space / src / loader / load_nodeset2.js View on Github external
finish: function () {
                    this.parent.parent.obj.value = {
                        dataType: DataType.ExtensionObject,
                        arrayType: VariantArrayType.Array,
                        value: this.listData
                    };

                },
                endElement: function (element) {
github node-opcua / node-opcua / packages / node-opcua-client-dynamic-extension-object / source / resolve_dynamic_extension_object.ts View on Github external
export async function resolveDynamicExtensionObject(
    variant: Variant,
    extraDataType: ExtraDataTypeManager
): Promise {

    if (variant.dataType !== DataType.ExtensionObject) {
        return;
    }
    if (variant.arrayType !== VariantArrayType.Scalar) {

        if (variant.value instanceof Array) {
            variant.value = (variant.value as any[]).map((v: any) => {

                if (!(v instanceof OpaqueStructure)) {
                    return v;
                }
                const obj = resolveDynamicExtensionObjectV(v as OpaqueStructure, extraDataType);
                return obj;
            });
        }
        return;
    }