How to use node-opcua-date-time - 10 common examples

To help you get started, we’ve selected a few node-opcua-date-time 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
public touchValue(optionalNow?: PreciseClock): void {
        const variable = this;
        const now = optionalNow || getCurrentClock();
        variable._dataValue.sourceTimestamp = now.timestamp;
        variable._dataValue.sourcePicoseconds = now.picoseconds;
        variable._dataValue.serverTimestamp = now.timestamp;
        variable._dataValue.serverPicoseconds = now.picoseconds;

        variable._dataValue.statusCode = StatusCodes.Good;

        if (variable.minimumSamplingInterval === 0) {
            // xx console.log("xxx touchValue = ",variable.browseName.toString(),variable._dataValue.value.value);
            if (variable.listenerCount("value_changed") > 0) {
                const clonedDataValue = variable.readValue();
                variable.emit("value_changed", clonedDataValue);
            }
        }
        if (variable.parent && variable.parent.nodeClass === NodeClass.Variable) {
            (variable.parent as UAVariable).touchValue(now);
github node-opcua / node-opcua / packages / node-opcua-data-value / source / datavalue.ts View on Github external
assert(dataValue.hasOwnProperty("serverTimestamp"));
  assert(dataValue.hasOwnProperty("sourceTimestamp"));

  let cloneDataValue = null;
  let now = null;
  // apply timestamps
  switch (timestampsToReturn) {
    case TimestampsToReturn.Neither:
      cloneDataValue = cloneDataValue || _partial_clone(dataValue);
      break;
    case TimestampsToReturn.Server:
      cloneDataValue = cloneDataValue || _partial_clone(dataValue);
      cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
      cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
      if (!cloneDataValue.serverTimestamp) {
        now = now || getCurrentClock();
        cloneDataValue.serverTimestamp = now.timestamp as DateTime;
        cloneDataValue.serverPicoseconds = now.picoseconds;
      }
      break;
    case TimestampsToReturn.Source:
      cloneDataValue = cloneDataValue || _partial_clone(dataValue);
      cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
      cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
      break;
    default:
      assert(timestampsToReturn === TimestampsToReturn.Both);
      cloneDataValue = cloneDataValue || _partial_clone(dataValue);
      cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
      cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
      if (!cloneDataValue.serverTimestamp) {
        now = now || getCurrentClock();
github node-opcua / node-opcua / packages / node-opcua-data-value / source / datavalue.ts View on Github external
function apply_timestamps2(
  dataValue: DataValue,
  timestampsToReturn: TimestampsToReturn,
  attributeId: AttributeIds
): DataValue {

  assert(attributeId > 0);
  assert(dataValue.hasOwnProperty("serverTimestamp"));
  assert(dataValue.hasOwnProperty("sourceTimestamp"));
  const cloneDataValue = new DataValue({});
  cloneDataValue.value = dataValue.value;
  cloneDataValue.statusCode = dataValue.statusCode;
  const now = getCurrentClock();
  // apply timestamps
  switch (timestampsToReturn) {
    case TimestampsToReturn.Server:
      cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
      cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
      cloneDataValue.serverTimestamp = now.timestamp as DateTime;
      cloneDataValue.serverPicoseconds = now.picoseconds;
      break;
    case TimestampsToReturn.Source:
      cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
      cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
      break;
    case TimestampsToReturn.Both:
      cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
      cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
      cloneDataValue.serverTimestamp = now.timestamp as DateTime;
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
UAVariable.prototype.writeValue = function (context, dataValue, indexRange, callback) {

    const self = this;
    if (!context) {
        context = SessionContext.defaultContext;
    }
    if (!dataValue.sourceTimestamp) {
        if (context.currentTime) {
            dataValue.sourceTimestamp = context.currentTime;
            dataValue.sourcePicoseconds = 0;
        } else {
            const clock = getCurrentClock();
            dataValue.sourceTimestamp = clock.timestamp;
            dataValue.sourcePicoseconds = clock.picoseconds;
        }
    }

    if (context.currentTime && !dataValue.serverTimestamp) {
        dataValue.serverTimestamp = context.currentTime;
        dataValue.serverPicoseconds = 0;
    }

    assert(context instanceof SessionContext);

    // adjust arguments if optional indexRange Parameter is not given
    if (!_.isFunction(callback) && _.isFunction(indexRange)) {
        callback = indexRange;
        indexRange = new NumericRange();
github node-opcua / node-opcua / packages / node-opcua-data-value / src / datavalue.js View on Github external
function apply_timestamps2(dataValue, timestampsToReturn, attributeId) {

    assert(attributeId > 0);
    assert(timestampsToReturn.hasOwnProperty("key"));
    assert(dataValue instanceof DataValue);
    assert(dataValue.hasOwnProperty("serverTimestamp"));
    assert(dataValue.hasOwnProperty("sourceTimestamp"));

    const cloneDataValue = new DataValue({});
    cloneDataValue.value = dataValue.value;
    cloneDataValue.statusCode = dataValue.statusCode;

    const now = getCurrentClock();
    // apply timestamps
    switch (timestampsToReturn) {
        case TimestampsToReturn.Server:
            cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
            cloneDataValue.serverPicoseconds = dataValue.serverPicoseconds;
            //xxif (true || !cloneDataValue.serverTimestamp) {
                cloneDataValue.serverTimestamp = now.timestamp;
                cloneDataValue.serverPicoseconds = now.picoseconds;
            //xx}
            break;
        case TimestampsToReturn.Source:
            cloneDataValue.sourceTimestamp = dataValue.sourceTimestamp;
            cloneDataValue.sourcePicoseconds = dataValue.sourcePicoseconds;
            break;
        case TimestampsToReturn.Both:
            cloneDataValue.serverTimestamp = dataValue.serverTimestamp;
github node-opcua / node-opcua / packages / node-opcua-address-space / src / historical_access / address_space_historical_data_node.ts View on Github external
historyData: new HistoryData({ dataValues }),
      statusCode: StatusCodes.Good
    });
    return callback(null, result2);
  }

  // todo add special treatment for when startTime > endTime
  // ( in this case series must be return in reverse order )

  let maxNumberToExtract = 0;
  let isReversed = false;
  let reverseDataValue = false;
  if (isMinDate(historyReadRawModifiedDetails.endTime!)) {
    // end time is not specified
    maxNumberToExtract = historyReadRawModifiedDetails.numValuesPerNode;
    if (isMinDate(historyReadRawModifiedDetails.startTime!)) {
      // end start and start time are not specified, this is invalid
      const result = new HistoryReadResult({
        statusCode: StatusCodes.BadHistoryOperationUnsupported // should be an error
      });
      return callback(null, result);
    }

  } else if (isMinDate(historyReadRawModifiedDetails.startTime!)) {
    // start time is not specified
    // end time is specified
    maxNumberToExtract = historyReadRawModifiedDetails.numValuesPerNode;
    isReversed = true;
    reverseDataValue = false;

    if (historyReadRawModifiedDetails.numValuesPerNode === 0) {
      // when start time is not specified
github node-opcua / node-opcua / packages / node-opcua-address-space / src / historical_access / address_space_historical_data_node.ts View on Github external
return callback(err);
      }

      // now make sure that only the requested number of value is returned
      if (historyReadRawModifiedDetails.numValuesPerNode >= 1) {
        if (dataValues.length === 0) {
          const result1 = new HistoryReadResult({
            historyData: new HistoryData({ dataValues: [] }),
            statusCode: StatusCodes.GoodNoData
          });
          return callback(null, result1);
        } else {
          const remaining = dataValues;
          dataValues = remaining.splice(0, historyReadRawModifiedDetails.numValuesPerNode);

          if (remaining.length > 0 && !isMinDate(historyReadRawModifiedDetails.endTime)) {
            continuationPoint = createContinuationPoint();
            context.continuationPoints = context.continuationPoints || {};
            context.continuationPoints[continuationPoint.toString("hex")] = {
              dataValues: remaining
            };
          }
        }
      }
      const result = new HistoryReadResult({
        continuationPoint: continuationPoint || undefined,
        historyData: new HistoryData({ dataValues }),
        statusCode: StatusCodes.Good
      });
      callback(null, result);
    });
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
if (!variant.dataType) {
            throw new Error("Variant must provide a valid dataType" + variant.toString());
        }
    }

    // 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-address-space / src / ua_variable.ts View on Github external
if (variant.dataType === null || variant.dataType === undefined) {
                throw new Error("Variant must provide a valid dataType" + variant.toString());
            }
        }

        // 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({
            serverPicoseconds: now.picoseconds,
            serverTimestamp: now.timestamp,
            sourcePicoseconds: now.picoseconds,
            sourceTimestamp: now.timestamp,
            statusCode: statusCode || StatusCodes.Good
        });
        dataValue.value = variant as Variant;
        this._internal_set_dataValue(dataValue);
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
UAVariable.prototype.touchValue = function (optionalNow) {
    const variable = this;
    const now = optionalNow || getCurrentClock();
    variable._dataValue.sourceTimestamp = now.timestamp;
    variable._dataValue.sourcePicoseconds = now.picoseconds;
    variable._dataValue.serverTimestamp = now.timestamp;
    variable._dataValue.serverPicoseconds = now.picoseconds;

    variable._dataValue.statusCode = StatusCodes.Good;

    if (variable.minimumSamplingInterval === 0) {
        //xx console.log("xxx touchValue = ",variable.browseName.toString(),variable._dataValue.value.value);
        if (variable.listenerCount("value_changed") > 0) {
            const clonedDataValue = variable.readValue();
            variable.emit("value_changed", clonedDataValue);
        }
    }
    if (variable.parent && variable.parent.nodeClass == NodeClass.Variable) {
        variable.parent.touchValue(now);

node-opcua-date-time

pure nodejs OPCUA SDK - module date-time

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis