How to use the node-opcua-data-value.DataValue function in node-opcua-data-value

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-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.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-aggregates / source / interpolate.ts View on Github external
const steppedValue = (previousDataValue: DataValue): DataValue => {
        if (!previousDataValue.statusCode) {
            throw new Error("Expecting statusCode");
        }
        const interpValue = new DataValue({
            sourceTimestamp: interval.startTime,
            statusCode: StatusCodes.Bad,
            value: previousDataValue.value,
        });
        interpValue.statusCode =
            StatusCode.makeStatusCode(StatusCodes.UncertainDataSubNormal, "HistorianInterpolated");
        return interpValue;
    };
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
timestamped_get() {
                    const value = prepareVariantValue(dataTypeNodeId, self.$extensionObject[name]);
                    propertyNode._dataValue.statusCode = StatusCodes.Good;
                    propertyNode._dataValue.value.value = value;
                    return new DataValue(propertyNode._dataValue);
                },
                timestamped_set(dataValue, callback) {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_data_type.ts View on Github external
public readAttribute(context: SessionContext | null, attributeId: AttributeIds): DataValue {

        assert(!context || context instanceof SessionContext);

        const options: DataValueLike = {};
        switch (attributeId) {
            case AttributeIds.IsAbstract:
                options.statusCode = StatusCodes.Good;
                options.value = { dataType: DataType.Boolean, value: !!this.isAbstract };
                break;
            default:
                return super.readAttribute(context, attributeId);
        }
        return new DataValue(options);
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
private _readDataType(): DataValue {
        assert(this.dataType instanceof NodeId);
        const options = {
            statusCode: StatusCodes.Good,
            value: {
                dataType: DataType.NodeId,
                value: this.dataType
            }
        };
        return new DataValue(options);
    }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
func = function (callback) {
            const dataValue = new DataValue({statusCode: StatusCodes.BadUserAccessDenied});
            callback(null, dataValue);
        }
    } else {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / base_node.js View on Github external
case AttributeIds.WriteMask:
            options.value = {dataType: DataType.UInt32, value: this.getWriteMask()};
            break;

        case AttributeIds.UserWriteMask:
            options.value = {dataType: DataType.UInt32, value: this.getUserWriteMask()};
            break;

        default:
            options.value = null;
            //xx debugLog("class Name ", this.constructor.name, (" BaseNode : '" + this.browseName + "' nodeid=" + this.nodeId.toString()).yellow, " cannot get attribute ", AttributeNameById[attributeId], "(", attributeId, ")");
            options.statusCode = StatusCodes.BadAttributeIdInvalid;
            break;
    }
    //xx options.serverTimestamp = new Date();
    return new DataValue(options);
};
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_method.js View on Github external
const self = this;
    const options = {};
    switch (attributeId) {
        case AttributeIds.Executable:
            options.value = {dataType: DataType.Boolean, value: self.getExecutableFlag(context)};
            options.statusCode = StatusCodes.Good;
            break;
        case AttributeIds.UserExecutable:
            options.value = {dataType: DataType.Boolean, value: self.getExecutableFlag(context)};
            options.statusCode = StatusCodes.Good;
            break;
        default:
            return BaseNode.prototype.readAttribute.call(this, context, attributeId);
    }
    return new DataValue(options);
};