How to use node-opcua-data-value - 10 common examples

To help you get started, we’ve selected a few node-opcua-data-value 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 / test / helpers / helpers.ts View on Github external
value: number | boolean | null,
    statusCode: StatusCode
): DataValue {
    // 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},
        });
    }
}
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
self._dataValue.statusCode = self._dataValue.statusCode || StatusCodes.Good;

    // repair missing timestamps
    if (!dataValue.serverTimestamp) {
        self._dataValue.serverTimestamp = old_dataValue.serverTimestamp;
        self._dataValue.serverPicoseconds = old_dataValue.serverPicoseconds;
    }
    if (!dataValue.sourceTimestamp) {
        self._dataValue.sourceTimestamp = old_dataValue.sourceTimestamp;
        self._dataValue.sourcePicoseconds = old_dataValue.sourcePicoseconds;
    }

    // if (dataValue.value.arrayType ===VariantArrayType.Array) {
    //     console.log("xxxx UAVariable emit value_changed ??".bgRed, old_dataValue.value.toString(),dataValue.value.toString());
    // }
    if (!sameDataValue(old_dataValue, dataValue)) {
        //xx if(this.nodeId.toString()=== "ns=2;s=Scalar_Static_Int32") {
        //xx     console.log("UAVariable emit value_changed");
        //xx }
        self.emit("value_changed", self._dataValue, indexRange);
    }
};
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
const indexRange = nodeToRead.indexRange;
    const dataEncoding = nodeToRead.dataEncoding;

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

    timestampsToReturn = (timestampsToReturn !== undefined) ? timestampsToReturn : TimestampsToReturn.Neither;

    const obj = engine.__findObject(nodeId!);

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

      // check access
      //    BadUserAccessDenied
      //    BadNotReadable
      //    invalid attributes : BadNodeAttributesInvalid
      //    invalid range      : BadIndexRangeInvalid
      try {
        dataValue = obj.readAttribute(context, attributeId, indexRange, dataEncoding);
        assert(dataValue.statusCode instanceof StatusCode);
        if (!dataValue.isValid()) {
          console.log("Invalid value for node ", obj.nodeId.toString(), obj.browseName.toString());
        }

      } catch (err) {
        console.log(" Internal error reading  NodeId       ", obj.nodeId.toString());
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
const old_dataValue = this._dataValue;

        this._dataValue = dataValue;
        this._dataValue.statusCode = this._dataValue.statusCode || StatusCodes.Good;

        // repair missing timestamps
        if (!dataValue.serverTimestamp) {
            this._dataValue.serverTimestamp = old_dataValue.serverTimestamp;
            this._dataValue.serverPicoseconds = old_dataValue.serverPicoseconds;
        }
        if (!dataValue.sourceTimestamp) {
            this._dataValue.sourceTimestamp = old_dataValue.sourceTimestamp;
            this._dataValue.sourcePicoseconds = old_dataValue.sourcePicoseconds;
        }

        if (!sameDataValue(old_dataValue, dataValue)) {
            this.emit("value_changed", this._dataValue, indexRange);
        }
    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
assert(dataValue.statusCode instanceof StatusCode);
        if (!dataValue.isValid()) {
          console.log("Invalid value for node ", obj.nodeId.toString(), obj.browseName.toString());
        }

      } catch (err) {
        console.log(" Internal error reading  NodeId       ", obj.nodeId.toString());
        console.log("                         AttributeId  ", attributeId.toString());
        console.log("                        ", err.message);
        console.log("                        ", err.stack);
        return new DataValue({ statusCode: StatusCodes.BadInternalError });
      }

      // Xx console.log(dataValue.toString());

      dataValue = apply_timestamps(dataValue, timestampsToReturn, attributeId);

      return dataValue;
    }
  }
github node-opcua / node-opcua / packages / node-opcua-server / source / monitored_item.ts View on Github external
//             this.node.listenerCount("value_changed"),this.node.nodeId.toString());
    // xx   console.log("events ---- ",this.node.eventNames().join("-"));
    // xx    console.log("indexRange = ",indexRange ? indexRange.toString() :"");
    // xx    console.log("this.itemToMonitor.indexRange = ",this.itemToMonitor.indexRange.toString());

    if (!hasSemanticChanged && indexRange && this.itemToMonitor.indexRange) {
      // we just ignore changes that do not fall within our range
      // ( unless semantic bit has changed )
      if (!NumericRange.overlap(indexRange as NumericalRange0, this.itemToMonitor.indexRange)) {
        return; // no overlap !
      }
    }

    assert(this.itemToMonitor, "must have a valid itemToMonitor(have this monitoredItem been disposed already ?");
    // extract the range that we are interested with
    dataValue = extractRange(dataValue, this.itemToMonitor.indexRange);

    // istanbul ignore next
    if (doDebug) {
      debugLog("MonitoredItem#recordValue",
        this.node!.nodeId.toString(),
        this.node!.browseName.toString(), " has Changed = ", !sameDataValue(dataValue, this.oldDataValue!));
    }

    // if semantic has changed, value need to be enqueued regardless of other assumptions
    if (hasSemanticChanged) {
      return this._enqueue_value(dataValue);
    }

    const useIndexRange = this.itemToMonitor.indexRange && !this.itemToMonitor.indexRange.isEmpty();

    if (!skipChangeTest) {
github node-opcua / node-opcua / packages / node-opcua-server / src / monitored_item.js View on Github external
//             self.node.listenerCount("value_changed"),self.node.nodeId.toString());
    //xx   console.log("events ---- ",self.node.eventNames().join("-"));
    //xx    console.log("indexRange = ",indexRange ? indexRange.toString() :"");
    //xx    console.log("self.itemToMonitor.indexRange = ",self.itemToMonitor.indexRange.toString());

    if (!hasSemanticChanged && indexRange && self.itemToMonitor.indexRange) {
        // we just ignore changes that do not fall within our range
        // ( unless semantic bit has changed )
        if (!NumericRange.overlap(indexRange,self.itemToMonitor.indexRange)) {
            return; // no overlap !
        }
    }

    assert( self.itemToMonitor,"must have a valid itemToMonitor(have this monitoredItem been disposed already ?");
    // extract the range that we are interested with
    dataValue = extractRange(dataValue, self.itemToMonitor.indexRange);

    // istanbul ignore next
    if (doDebug) {
        debugLog("MonitoredItem#recordValue", self.node.nodeId.toString(), self.node.browseName.toString(), " has Changed = ", !sameDataValue(dataValue, self.oldDataValue));
    }

    // if semantic has changed, value need to be enqueued regardless of other assumptions
    if (hasSemanticChanged) {
        return self._enqueue_value(dataValue);
    }

    const useIndexRange = self.itemToMonitor.indexRange && !self.itemToMonitor.indexRange.isEmpty();

    if (!skipChangeTest) {
        const hasChanged = !sameDataValue(dataValue, self.oldDataValue);
        if (!hasChanged) {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
}
    }

    // if (variant.hasOwnProperty("value")) {
    //     if (variant.dataType === DataType.UInt32) {
    //         if (!_.isFinite(variant.value)) {
    //             throw new Error("Expecting an number");
    //         }
    //     }
    // }

    variant = Variant.coerce(variant);

    const now = coerceClock(sourceTimestamp, 0);

    const dataValue = new DataValue({
        sourceTimestamp: now.timestamp,
        sourcePicoseconds: now.picoseconds,
        serverTimestamp: now.timestamp,
        serverPicoseconds: now.picoseconds,
        statusCode: statusCode || StatusCodes.Good
    });
    dataValue.value = variant;
    self._internal_set_dataValue(dataValue, null);
};
github node-opcua / node-opcua / packages / node-opcua-server / src / monitored_item.js View on Github external
if (!hasSemanticChanged && indexRange && self.itemToMonitor.indexRange) {
        // we just ignore changes that do not fall within our range
        // ( unless semantic bit has changed )
        if (!NumericRange.overlap(indexRange,self.itemToMonitor.indexRange)) {
            return; // no overlap !
        }
    }

    assert( self.itemToMonitor,"must have a valid itemToMonitor(have this monitoredItem been disposed already ?");
    // extract the range that we are interested with
    dataValue = extractRange(dataValue, self.itemToMonitor.indexRange);

    // istanbul ignore next
    if (doDebug) {
        debugLog("MonitoredItem#recordValue", self.node.nodeId.toString(), self.node.browseName.toString(), " has Changed = ", !sameDataValue(dataValue, self.oldDataValue));
    }

    // if semantic has changed, value need to be enqueued regardless of other assumptions
    if (hasSemanticChanged) {
        return self._enqueue_value(dataValue);
    }

    const useIndexRange = self.itemToMonitor.indexRange && !self.itemToMonitor.indexRange.isEmpty();

    if (!skipChangeTest) {
        const hasChanged = !sameDataValue(dataValue, self.oldDataValue);
        if (!hasChanged) {
            return;
        }
    }
github node-opcua / node-opcua / packages / node-opcua-server / source / monitored_item.ts View on Github external
// istanbul ignore next
    if (doDebug) {
      debugLog("MonitoredItem#recordValue",
        this.node!.nodeId.toString(),
        this.node!.browseName.toString(), " has Changed = ", !sameDataValue(dataValue, this.oldDataValue!));
    }

    // if semantic has changed, value need to be enqueued regardless of other assumptions
    if (hasSemanticChanged) {
      return this._enqueue_value(dataValue);
    }

    const useIndexRange = this.itemToMonitor.indexRange && !this.itemToMonitor.indexRange.isEmpty();

    if (!skipChangeTest) {
      const hasChanged = !sameDataValue(dataValue, this.oldDataValue!);
      if (!hasChanged) {
        return;
      }
    }

    if (!apply_filter.call(this, dataValue)) {
      debugLog("filter did not pass");
      return;
    }

    if (useIndexRange) {
      // when an indexRange is provided , make sure that no record happens unless
      // extracted variant in the selected range  has really changed.

      // istanbul ignore next
      if (doDebug) {