How to use the node-opcua-factory.hasEnumeration function in node-opcua-factory

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-convert-nodeset-to-javascript / src / convert_nodeset_to_types.js View on Github external
function generateEnumerationCode(dataType, filename) {
    assert(typeof filename === "string");

    const dataTypeName = dataType.browseName.name.toString();
    assert(!hasEnumeration(dataTypeName));

    // create the enumeration file
    const f = new LineFile();
    f.write("// namespace " + dataType.namespaceUri.toString());
    f.write('const factories  = require("node-opcua-factory");');
    f.write('const makeNodeId = require("node-opcua-nodeid").makeNodeId;');

    f.write("const " + dataTypeName + "_Schema = {");
    f.write("  id:  makeNodeId(" + dataType.nodeId.value + "," + dataType.nodeId.namespace + "),");
    f.write("  name: '" + dataTypeName + "',");
    f.write("  namespace: '" + dataType.nodeId.namespace + "',");

    f.write("  enumValues: {");
    dataType.definition.forEach(function(pair) {
        f.write("     " + pair.name + ": " + pair.value + ",");
    });
github node-opcua / node-opcua / packages / node-opcua-convert-nodeset-to-javascript / src / convert_nodeset_to_types.js View on Github external
function makeEnumeration(dataType, bForce) {
    assert(dataType);
    assert(dataType.hasOwnProperty("browseName"));
    assert(dataType.browseName instanceof QualifiedName);
    assert(_.isArray(dataType.definition));

    const dataTypeName = dataType.browseName.name.toString();
    if (hasEnumeration(dataTypeName)) {
        return getEnumeration(dataTypeName).typedEnum;
    }
    //const Enumeration_Schema = {
    //    id: dataType.nodeId,
    //    name: dataType.browseName.toString(),
    //    enumValues: {}
    //};
    //
    //dataType.definition.forEach(function (pair) {
    //    Enumeration_Schema.enumValues[pair.name] = parseInt(pair.value, 10);
    //});

    const namespace = dataType.namespaceUri;
    const filename = getSchemaSourceFile(namespace, dataType.browseName.toString(), "enum");

    generateEnumerationCode(dataType, filename);