How to use node-opcua-factory - 10 common examples

To help you get started, we’ve selected a few node-opcua-factory 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-for-conformance-testing / src / address_space_for_conformance_testing.js View on Github external
function _findDataType(dataTypeName) {
    const builtInDataTypeName = findBuiltInType(dataTypeName);
    const dataType = DataType[builtInDataTypeName.name];
    // istanbul ignore next
    if (!dataType) {
        throw new Error(" dataType " + dataTypeName + " must exists");
    }
    return dataType;
}
github node-opcua / node-opcua / packages / node-opcua-data-model / source / result_mask.ts View on Github external
import { registerEnumeration } from "node-opcua-factory";

export enum ResultMask {
    ReferenceType=  0x01,
    IsForward=      0x02,
    NodeClass=      0x04,
    BrowseName=     0x08,
    DisplayName=    0x10,
    TypeDefinition= 0x20
}
export const schemaResultMask = {
    name: "ResultMask",

    enumValues: ResultMask
};
export const _enumerationResultMask: Enum = registerEnumeration(schemaResultMask);

// The ReferenceDescription type is defined in 7.24.
// @example
//      makeNodeClassMask("Method | Object").should.eql(5);
export function makeResultMask(str: string): ResultMask {
    const flags = str.split(" | ");
    let r = 0;
    for (const flag of flags) {
        r |= (ResultMask as any)[flag];
    }
    return r as ResultMask;
}
github node-opcua / node-opcua / packages / node-opcua-data-model / source / localized_text.ts View on Github external
return new LocalizedText({ locale: null, text: value });
    }
    if (value instanceof LocalizedText) {
        return value;
    }
    if (!value.hasOwnProperty("text")) {
        // tslint:disable:no-console
        console.log("value = ", value);
        throw new Error("cannot coerce to coerceLocalizedText");
    }
    return new LocalizedText(value);
}

// --------------------------------------------------------------------------------------------
// see Part 3 - $8.5 page 63
const schemaLocalizedText = buildStructuredType({
    name: "LocalizedText",

    baseType: "BaseUAObject",

    fields: [
        {
            name: "locale",

            fieldType: "LocaleId"
        },
        {
            name: "text",

            fieldType: "UAString",

            defaultValue: () => null
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
                        field.fieldType = "NumericRange";
                        // xx console.log(" NumericRange detected here !");
                    } else {
                        field.fieldType = fieldTypeName;
                    }
                    if (!hasBuiltInType(fieldTypeName)) {
                        throw new Error("Unknown basic type " + fieldTypeName);
                    }
                    field.category = FieldCategory.basic;
                    break;
            }
        }
    }

    structuredTypeSchema = buildStructuredType(structuredType as StructuredTypeOptions);
    typeDictionary.structuredTypes[name] = structuredTypeSchema;
    return structuredTypeSchema;

}
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
} else if (hasStructuredType(fieldTypeName)) {
                        field.category = FieldCategory.complex;
                        field.schema = getStructuredTypeSchema(fieldTypeName);

                    } else {
                        field.category = FieldCategory.basic;
                        // try in this
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
                        } else {
                            if (hasBuiltInType(fieldTypeName)) {
                                field.category = FieldCategory.basic;
                            } else {
                                field.category = FieldCategory.complex;
                            }
                        }
                    }
                    break;
                case "opc":
                    if ((fieldTypeName === "UAString" || fieldTypeName === "String") && field.name === "IndexRange") {
                        field.fieldType = "NumericRange";
                        // xx console.log(" NumericRange detected here !");
                    } else {
                        field.fieldType = fieldTypeName;
                    }
                    if (!hasBuiltInType(fieldTypeName)) {
                        throw new Error("Unknown basic type " + fieldTypeName);
                    }
                    field.category = FieldCategory.basic;
                    break;
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
const prefix = getNamespacePart(fieldType);
            const fieldTypeName = adjustFieldTypeName(removeNamespacePart(fieldType)!);

            switch (prefix) {
                case "tns":

                    field.fieldType = fieldTypeName;
                    const enumeratedType = typeDictionary.enumeratedTypes[fieldTypeName];
                    if (enumeratedType) {
                        field.category = FieldCategory.enumeration;
                        field.schema = enumeratedType;

                    } else {
                        // must be a structure then ....
                        field.category = FieldCategory.complex;
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("cannot find schema for ", fieldTypeName);
                        }
                    }
                    break;
                case "ua":
                    field.fieldType = fieldTypeName;
                    if (hasBuiltInType(fieldTypeName)) {
                        field.category = FieldCategory.basic;
                        field.schema = getBuildInType(fieldTypeName);
                    } else if (hasStructuredType(fieldTypeName)) {
                        field.category = FieldCategory.complex;
                        field.schema = getStructuredTypeSchema(fieldTypeName);
github node-opcua / node-opcua / packages / node-opcua-address-space / src / nodeset_to_xml.ts View on Github external
assert(value instanceof Variant);

    const dataTypeNode = addressSpace.findNode(node.dataType);
    if (!dataTypeNode) {
        return;
    }
    const dataTypeName = dataTypeNode.browseName.toString();

    const baseDataTypeName = (DataType as any)[DataType[value.dataType]];

    // console.log("nodeset_to_xml #_dumpValue Cannot find ", dataTypeName,node.dataType.toString());
    if (!hasStructuredType(dataTypeName)) {
        return;
    } // this is not a extension object

    const schema = getStructuredTypeSchema(dataTypeName);

    function encodeXml(value1: any) {
        _dumpVariantExtensionObjectValue_Body(xw, schema, value1);
    }

    xw.startElement("Value");

    // determine if dataTypeName is a ExtensionObject
    const isExtensionObject = dataTypeName === "LocalizedText" ? false : true;

    if (isExtensionObject) {

        if (value.arrayType === VariantArrayType.Array) {
            xw.startElement("ListOf" + baseDataTypeName);
            value.value.forEach(_dumpVariantExtensionObjectValue.bind(null, xw, schema));
            xw.endElement();
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
field.category = FieldCategory.complex;
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("cannot find schema for ", fieldTypeName);
                        }
                    }
                    break;
                case "ua":
                    field.fieldType = fieldTypeName;
                    if (hasBuiltInType(fieldTypeName)) {
                        field.category = FieldCategory.basic;
                        field.schema = getBuildInType(fieldTypeName);
                    } else if (hasStructuredType(fieldTypeName)) {
                        field.category = FieldCategory.complex;
                        field.schema = getStructuredTypeSchema(fieldTypeName);

                    } else {
                        field.category = FieldCategory.basic;
                        // try in this
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
                        } else {
                            if (hasBuiltInType(fieldTypeName)) {
                                field.category = FieldCategory.basic;
                            } else {
                                field.category = FieldCategory.complex;
                            }
                        }
                    }
github node-opcua / node-opcua / packages / node-opcua-schemas / source / tools.ts View on Github external
} else {
                        // must be a structure then ....
                        field.category = FieldCategory.complex;
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("cannot find schema for ", fieldTypeName);
                        }
                    }
                    break;
                case "ua":
                    field.fieldType = fieldTypeName;
                    if (hasBuiltInType(fieldTypeName)) {
                        field.category = FieldCategory.basic;
                        field.schema = getBuildInType(fieldTypeName);
                    } else if (hasStructuredType(fieldTypeName)) {
                        field.category = FieldCategory.complex;
                        field.schema = getStructuredTypeSchema(fieldTypeName);

                    } else {
                        field.category = FieldCategory.basic;
                        // try in this
                        field.schema = getOrCreateStructuredTypeSchema(fieldTypeName, typeDictionary);
                        if (!field.schema) {
                            // tslint:disable-next-line:no-console
                            console.log("What should I do ??", fieldTypeName, " ", hasStructuredType(fieldTypeName));
                        } else {
                            if (hasBuiltInType(fieldTypeName)) {
                                field.category = FieldCategory.basic;
                            } else {
                                field.category = FieldCategory.complex;
                            }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / nodeset_to_xml.ts View on Github external
if (!value) {
        return;
    }

    assert(value instanceof Variant);

    const dataTypeNode = addressSpace.findNode(node.dataType);
    if (!dataTypeNode) {
        return;
    }
    const dataTypeName = dataTypeNode.browseName.toString();

    const baseDataTypeName = (DataType as any)[DataType[value.dataType]];

    // console.log("nodeset_to_xml #_dumpValue Cannot find ", dataTypeName,node.dataType.toString());
    if (!hasStructuredType(dataTypeName)) {
        return;
    } // this is not a extension object

    const schema = getStructuredTypeSchema(dataTypeName);

    function encodeXml(value1: any) {
        _dumpVariantExtensionObjectValue_Body(xw, schema, value1);
    }

    xw.startElement("Value");

    // determine if dataTypeName is a ExtensionObject
    const isExtensionObject = dataTypeName === "LocalizedText" ? false : true;

    if (isExtensionObject) {