Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "node-opcua-variant in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-opcua-variant' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

context: SessionContext,
      callback: MethodFunctorCallback) => {

        // xx console.log("In Event Generator Method");
        // xx console.log(this.toString());
        // xx console.log(context.object.toString());

        // xx console.log("inputArguments ", inputArguments[0].toString());

        const message = inputArguments[0].value || "Hello from Event Generator Object";
        const severity = inputArguments[1].value || 0;

        const myEventType = namespace.addressSpace.findEventType("MyEventType", namespace.index);
        context.object.raiseEvent(myEventType, {
            message: {
                dataType: DataType.LocalizedText,
                value: { text: message }
            },
            severity: {
                dataType: DataType.UInt32,
                value: severity
            }

        });
        // console.log(require("util").inspect(context).toString());
        const callMethodResult = {
            outputArguments: [],
            statusCode: StatusCodes.Good
        };
        callback(null, callMethodResult);
    });
it("should bind an xml-preloaded Extension Object Variable : ServerStatus ", function (done) {
        // in this test, we verify that we can easily bind the Server_ServerStatus object
        // the process shall automatically bind variables and substructures recursively
        var VariableIds = require("node-opcua-constants").VariableIds;
        var makeNodeId = require("node-opcua-nodeid").makeNodeId;

        var serverStatus = addressSpace.findNode(makeNodeId(VariableIds.Server_ServerStatus));
        serverStatus.browseName.toString().should.eql("ServerStatus");

        // before bindExtensionObject is called, startTime property exists but is not bound
        serverStatus.should.have.property("startTime");
        serverStatus.startTime.readValue().value.dataType.should.eql(DataType.Null);
        serverStatus.readValue().value.dataType.should.eql(DataType.Null);

        //Xx value.startTime.should.eql(DataType.Null);
        //xx debugLog("serverStatus.startTime =",serverStatus.startTime.readValue().value.toString());


        serverStatus.bindExtensionObject();

        serverStatus.readValue().value.value.startTime.toISOString().should.eql("1601-01-01T00:00:00.000Z");
        serverStatus.startTime.readValue().value.value.toISOString().should.eql("1601-01-01T00:00:00.000Z");

        serverStatus.readValue().value.value.startTime = new Date(Date.UTC(1800, 0, 1));
        serverStatus.readValue().value.value.startTime.toISOString().should.eql("1800-01-01T00:00:00.000Z");
        serverStatus.startTime.readValue().value.value.toISOString().should.eql("1800-01-01T00:00:00.000Z");
it("should bind an xml-preloaded Extension Object Variable : ServerStatus ", function (done) {
        // in this test, we verify that we can easily bind the Server_ServerStatus object
        // the process shall automatically bind variables and substructures recursively
        var VariableIds = require("node-opcua-constants").VariableIds;
        var makeNodeId = require("node-opcua-nodeid").makeNodeId;

        var serverStatus = addressSpace.findNode(makeNodeId(VariableIds.Server_ServerStatus));
        serverStatus.browseName.toString().should.eql("ServerStatus");

        // before bindExtensionObject is called, startTime property exists but is not bound
        serverStatus.should.have.property("startTime");
        serverStatus.startTime.readValue().value.dataType.should.eql(DataType.Null);
        serverStatus.readValue().value.dataType.should.eql(DataType.Null);

        //Xx value.startTime.should.eql(DataType.Null);
        //xx debugLog("serverStatus.startTime =",serverStatus.startTime.readValue().value.toString());


        serverStatus.bindExtensionObject();

        serverStatus.readValue().value.value.startTime.toISOString().should.eql("1601-01-01T00:00:00.000Z");
        serverStatus.startTime.readValue().value.value.toISOString().should.eql("1601-01-01T00:00:00.000Z");

        serverStatus.readValue().value.value.startTime = new Date(Date.UTC(1800, 0, 1));
        serverStatus.readValue().value.value.startTime.toISOString().should.eql("1800-01-01T00:00:00.000Z");
        serverStatus.startTime.readValue().value.value.toISOString().should.eql("1800-01-01T00:00:00.000Z");


        serverStatus.startTime.setValueFromSource({dataType: DataType.DateTime, value: new Date(Date.UTC(2100, 0, 1))});
// setup data
    const sourceTimestamp = makeDate(time);

    if (value === undefined || value === null) {

        return new DataValue({
            sourceTimestamp,
            statusCode,
            value: undefined,
        });

    } else if (typeof value === "boolean") {
        return new DataValue({
            sourceTimestamp,
            statusCode,
            value: {dataType: DataType.Boolean, value},
        });

    } else {
        return new DataValue({
            sourceTimestamp,
            statusCode,
            value: {dataType: DataType.Float, value},
        });
    }
}
const variant = new Variant({ dataType: DataType.Boolean, value });
        this._map[idKey] = variant;

        // also change varName with human readable text
        const twoStateNode = this._node_index[hrKey];
        if (!twoStateNode) {
            throw new Error("Cannot find twoState Varaible with name " + varName);
        }
        if (!(twoStateNode instanceof UATwoStateVariable)) {
            throw new Error("Cannot find twoState Varaible with name " + varName + " " + twoStateNode);
        }

        const txt = value ? twoStateNode._trueState : twoStateNode._falseState;

        const hrValue = new Variant({
            dataType: DataType.LocalizedText,
            value: coerceLocalizedText(txt)
        });
        this._map[hrKey] = hrValue;

        const node = this._node_index[idKey];

        // also change ConditionNode if we are on currentBranch
        if (this.isCurrentBranch()) {
            assert(twoStateNode instanceof UATwoStateVariable);
            twoStateNode.setValue(value);
            // xx console.log("Is current branch", twoStateNode.toString(),variant.toString());
            // xx console.log("  = ",twoStateNode.getValue());
        }
        this.emit("value_changed", node, variant);
    }
export function encodeDataValue(dataValue: DataValue, stream: OutputBinaryStream): void {
  const encodingMask = getDataValue_EncodingByte(dataValue);
  assert(_.isFinite(encodingMask) && encodingMask >= 0 && encodingMask <= 0x3F);
  // write encoding byte
  encodeUInt8(encodingMask, stream);

  // write value as Variant
  if (encodingMask & DataValueEncodingByte.Value) {
    if (!dataValue.value) {
      dataValue.value = new Variant();
    }
    if (!dataValue.value.encode) {
      // tslint:disable-next-line:no-console
      console.log(" CANNOT FIND ENCODE METHOD ON VARIANT !!! HELP", JSON.stringify(dataValue, null, " "));
    }
    dataValue.value.encode(stream);
  }
  // write statusCode
  if (encodingMask & DataValueEncodingByte.StatusCode) {
    encodeStatusCode(dataValue.statusCode, stream);
  }
  // write sourceTimestamp
  if ((encodingMask & DataValueEncodingByte.SourceTimestamp) && (dataValue.sourceTimestamp !== null)) {
    encodeHighAccuracyDateTime(dataValue.sourceTimestamp, dataValue.sourcePicoseconds, stream);
  }
  // write sourcePicoseconds
});
      }

      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,
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.
        */
const inputArguments: Variant[] = inputArgsDef.map((arg: any) => {

            const dataType = convertNodeIdToDataType(arg.dataType);

            const arrayType = (arg.valueRank === 1) ? VariantArrayType.Array : VariantArrayType.Scalar;

            // 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});
        });
function _process_var(self,prefix,node) {
            const lowerName =prefix + lowerFirstLetter(node.browseName.name);
            // istanbul ignore next
            if (doDebug) { console.log("      "+lowerName.toString()); }
            visitedProperties[lowerName] = node;
            if (data.hasOwnProperty(lowerName)) {

                eventData.setValue(lowerName,node,data[lowerName]);
                //xx eventData[lowerName] = _coerceVariant(data[lowerName]);
            } else {

                // add a property , but with a null variant
                eventData.setValue(lowerName,node,{ dataType: DataType.Null});

                if (doDebug) {
                    if (node.modellingRule === "Mandatory") {
                        console.log("ERROR : AddressSpace#constructEventData(eventType,options) cannot find property ".red
                          + self.browseName.toString() + " => " + lowerName.cyan);
                    } else {
                        console.log("Warning : AddressSpace#constructEventData(eventType,options) cannot find property ".yellow
                          + self.browseName.toString() + " => " + lowerName.cyan);
                    }
                }
            }

        }

Is your System Free of Underlying Vulnerabilities?
Find Out Now