How to use the node-opcua-date-time.getCurrentClock function in node-opcua-date-time

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 / 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);
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
function _apply_default_timestamps(dataValue: DataValue): void {
    const now = getCurrentClock();
    assert(dataValue instanceof DataValue);

    if (!dataValue.sourceTimestamp) {
        dataValue.sourceTimestamp = now.timestamp;
        dataValue.sourcePicoseconds = now.picoseconds;
    }
    if (!dataValue.serverTimestamp) {
        dataValue.serverTimestamp = now.timestamp;
        dataValue.serverPicoseconds = now.picoseconds;
    }
}
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_object.ts View on Github external
public readAttribute(context: SessionContext, attributeId: AttributeIds): DataValue {
        const now = getCurrentClock();
        const options: DataValueLike = {};
        switch (attributeId) {
            case AttributeIds.EventNotifier:
                assert(isValidByte(this.eventNotifier));
                options.value = { dataType: DataType.Byte, value: this.eventNotifier };
                options.serverTimestamp = now.timestamp;
                options.serverPicoseconds = now.picoseconds;
                options.statusCode = StatusCodes.Good;
                break;
            default:
                return BaseNode.prototype.readAttribute.call(this, context, attributeId);
        }
        return new DataValue(options);
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_object.js View on Github external
UAObject.prototype.readAttribute = function (context, attributeId) {

    assert(context instanceof SessionContext);

    const now = getCurrentClock();
    const options = {};
    switch (attributeId) {
        case AttributeIds.EventNotifier:
            assert(ec.isValidByte(this.eventNotifier));
            options.value = {dataType: DataType.Byte, value: this.eventNotifier};
            options.serverTimestamp = now.timestamp;
            options.serverPicoseconds = now.picoseconds;
            options.statusCode = StatusCodes.Good;
            break;
        default:
            return BaseNode.prototype.readAttribute.call(this, context, attributeId);
    }
    return new DataValue(options);
};
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
function _apply_default_timestamps(dataValue) {
    const now = getCurrentClock();
    assert(dataValue instanceof DataValue);

    if (!dataValue.sourceTimestamp) {
        dataValue.sourceTimestamp = now.timestamp;
        dataValue.sourcePicoseconds = now.picoseconds;
    }
    if (!dataValue.serverTimestamp) {
        dataValue.serverTimestamp = now.timestamp;
        dataValue.serverPicoseconds = now.picoseconds;
    }
}

node-opcua-date-time

pure nodejs OPCUA SDK - module date-time

MIT
Latest version published 3 months ago

Package Health Score

86 / 100
Full package analysis