Пример #1
0
 private static void Update(IVariableTypeFactory nodeDesign, UAVariableType nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent)
 {
     nodeDesign.ArrayDimensions = nodeSet.ArrayDimensions.ExportString(string.Empty);
     nodeDesign.DataType        = nodeContext.ExportBrowseName(nodeSet.DataType, DataTypes.Number);
     nodeDesign.DefaultValue    = nodeSet.Value;
     nodeDesign.ValueRank       = nodeSet.ValueRank.GetValueRank(traceEvent);
 }
Пример #2
0
 private void Update(IVariableTypeFactory nodeDesign, UAVariableType nodeSet)
 {
     nodeDesign.ArrayDimensions = nodeSet.ArrayDimensions.ExportString(string.Empty);
     nodeDesign.DataType        = AS.ExportBrowseName(NodeId.Parse(nodeSet.DataType), DataTypes.Number);
     nodeDesign.DefaultValue    = nodeSet.Value;
     nodeDesign.ValueRank       = nodeSet.ValueRank.GetValueRank(Log.TraceEvent);
 }
Пример #3
0
        /// <summary>
        /// Get the clone from the types derived from this one.
        /// </summary>
        /// <returns>An instance of <see cref="T:UAOOI.SemanticData.UANodeSetValidation.XML.UANode" />.</returns>
        protected override UANode ParentClone()
        {
            UAVariableType _ret = new UAVariableType()
            {
                Value           = this.Value,
                DataType        = this.DataType,
                ValueRank       = this.ValueRank,
                ArrayDimensions = this.ArrayDimensions
            };

            base.CloneUAType(_ret);
            return(_ret);
        }
Пример #4
0
        // OPC UA defines variables, views and objects, as well as associated variabletypes, datatypes, referencetypes and objecttypes
        // In addition, OPC UA defines methods and properties
        public static void Generate(UANodeSet nodeSet)
        {
            // clear previously generated DTDL
            _map.Clear();
            _interfaceList.Clear();
            _contentsList.Clear();
            _nodeList.Clear();
            _nodesetNamespaceURI = nodeSet.NamespaceUris[0];

            CreateSchemaMap();

            // create DTDL interfaces and their contents
            foreach (UANode uaNode in nodeSet.Items)
            {
                UAVariable variable = uaNode as UAVariable;
                if (variable != null)
                {
                    if (uaNode.BrowseName.ToString() == "InputArguments")
                    {
                        continue;
                    }

                    // check if this node is part of the model
                    bool isPartOfModel = false;
                    foreach (Reference reference in variable.References)
                    {
                        if (reference.ReferenceType == "HasModellingRule")
                        {
                            isPartOfModel = true;
                            break;
                        }
                    }
                    if (isPartOfModel)
                    {
                        // ignore this node
                        continue;
                    }

                    DtdlContents dtdlTelemetry = new DtdlContents
                    {
                        Type   = "Telemetry",
                        Name   = Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", ""),
                        Schema = GetDtdlDataType(variable.DataType)
                    };

                    Tuple <DtdlContents, string> newTuple = new Tuple <DtdlContents, string>(dtdlTelemetry, variable.ParentNodeId);
                    if (!_contentsList.Contains(newTuple))
                    {
                        _contentsList.Add(newTuple);
                    }

                    Tuple <string, string, string> newNodeTuple;
                    if (variable.BrowseName.Length > 0)
                    {
                        newNodeTuple = new Tuple <string, string, string>(variable.BrowseName, GetDtdlDataType(variable.DataType.ToString()), variable.ParentNodeId ?? "");
                    }
                    else
                    {
                        newNodeTuple = new Tuple <string, string, string>(variable.NodeId.ToString(), GetDtdlDataType(variable.DataType.ToString()), variable.ParentNodeId ?? "");
                    }

                    string key = nodeSet.NamespaceUris[0] + "#" + variable.NodeId.ToString().Substring(variable.NodeId.ToString().IndexOf(';') + 1);
                    if (!_nodeList.ContainsKey(key))
                    {
                        _nodeList.Add(key, newNodeTuple);
                    }

                    continue;
                }

                UAMethod method = uaNode as UAMethod;
                if (method != null)
                {
                    // check if this node is part of the model
                    bool isPartOfModel = false;
                    foreach (Reference reference in method.References)
                    {
                        if (reference.ReferenceType == "HasModellingRule")
                        {
                            isPartOfModel = true;
                            break;
                        }
                    }
                    if (isPartOfModel)
                    {
                        // ignore this node
                        continue;
                    }

                    DtdlContents dtdlCommand = new DtdlContents
                    {
                        Type = "Command",
                        Name = Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", "")
                    };

                    Tuple <DtdlContents, string> newTuple = new Tuple <DtdlContents, string>(dtdlCommand, method.ParentNodeId);
                    if (!_contentsList.Contains(newTuple))
                    {
                        _contentsList.Add(newTuple);
                    }

                    Tuple <string, string, string> newNodeTuple;
                    if (method.BrowseName.Length > 0)
                    {
                        newNodeTuple = new Tuple <string, string, string>(method.BrowseName, "command", method.ParentNodeId ?? "");
                    }
                    else
                    {
                        newNodeTuple = new Tuple <string, string, string>(method.NodeId.ToString(), "command", method.ParentNodeId ?? "");
                    }

                    string key = nodeSet.NamespaceUris[0] + "#" + method.NodeId.ToString().Substring(method.NodeId.ToString().IndexOf(';') + 1);
                    if (!_nodeList.ContainsKey(key))
                    {
                        _nodeList.Add(key, newNodeTuple);
                    }

                    continue;
                }

                UAObject uaObject = uaNode as UAObject;
                if (uaObject != null)
                {
                    // check if this node is part of the model
                    bool isPartOfModel = false;
                    foreach (Reference reference in uaObject.References)
                    {
                        if (reference.ReferenceType == "HasModellingRule")
                        {
                            isPartOfModel = true;
                            break;
                        }
                    }
                    if (isPartOfModel)
                    {
                        // ignore this node
                        continue;
                    }

                    DtdlInterface dtdlInterface = new DtdlInterface
                    {
                        Id          = "dtmi:" + Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", "") + ";1",
                        Type        = "Interface",
                        DisplayName = Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", ""),
                        Contents    = new List <DtdlContents>()
                    };

                    Tuple <DtdlInterface, string, string> newTuple = new Tuple <DtdlInterface, string, string>(dtdlInterface, uaObject.NodeId, uaObject.ParentNodeId);
                    if (!_interfaceList.Contains(newTuple))
                    {
                        _interfaceList.Add(newTuple);
                    }

                    Tuple <string, string, string> newNodeTuple;
                    if (uaObject.BrowseName.Length > 0)
                    {
                        newNodeTuple = new Tuple <string, string, string>(uaObject.BrowseName, "object", uaObject.ParentNodeId ?? "");
                    }
                    else
                    {
                        newNodeTuple = new Tuple <string, string, string>(uaObject.NodeId.ToString(), "object", uaObject.ParentNodeId ?? "");
                    }

                    string key = nodeSet.NamespaceUris[0] + "#" + uaObject.NodeId.ToString().Substring(uaObject.NodeId.ToString().IndexOf(';') + 1);
                    if (!_nodeList.ContainsKey(key))
                    {
                        _nodeList.Add(key, newNodeTuple);
                    }

                    continue;
                }

                UAView view = uaNode as UAView;
                if (view != null)
                {
                    // we don't map views since DTDL has no such concept
                    continue;
                }

                UAVariableType variableType = uaNode as UAVariableType;
                if (variableType != null)
                {
                    // we don't map UA variable types, only instances. DTDL only has a limited set of built-in types.
                    continue;
                }

                UADataType dataType = uaNode as UADataType;
                if (dataType != null)
                {
                    // we don't map UA data types, only instances. DTDL only has a limited set of built-in types.
                    continue;
                }

                UAReferenceType referenceType = uaNode as UAReferenceType;
                if (referenceType != null)
                {
                    // we don't map UA reference types, only instances. DTDL only has a limited set of built-in types.
                    continue;
                }

                UAObjectType objectType = uaNode as UAObjectType;
                if (objectType != null)
                {
                    // we don't map UA object (custom) types, only instances. DTDL only has a limited set of built-in types.
                    continue;
                }

                throw new ArgumentException("Unknown UA node detected!");
            }

            AddComponentsToInterfaces();
            AddRelationshipsBetweenInterfaces();

            // generate JSON files
            foreach (Tuple <DtdlInterface, string, string> dtdlInterfaceTuple in _interfaceList)
            {
                string generatedDTDL = JsonConvert.SerializeObject(dtdlInterfaceTuple.Item1, Formatting.Indented);
                string dtdlPath      = Path.Combine(Directory.GetCurrentDirectory(), "JSON", Path.GetFileNameWithoutExtension(dtdlInterfaceTuple.Item1.DisplayName) + ".dtdl.json");
                System.IO.File.WriteAllText(dtdlPath, generatedDTDL);
            }
        }