Пример #1
0
 public UANodeConverter(string filename, NamespaceTable SessionNamespaceURIs)
 {
     using (Stream stream = new FileStream(filename, FileMode.Open)){
         m_UANodeset       = UANodeSet.Read(stream);
         m_aliases         = m_UANodeset.Aliases;
         m_namespaceURIs   = m_UANodeset.NamespaceUris;
         out_nodeset       = new List <Node>();
         session_namespace = SessionNamespaceURIs;
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Read OPC-UA NodesSet xml file and parse it into a UANodeSet object
            string nodesetxmlfilepath = "..\\..\\assets\\miab10-nodeset2.xml";

            Stream stream = new FileStream(nodesetxmlfilepath, FileMode.Open);

            Opc.Ua.Export.UANodeSet nodeSet = Opc.Ua.Export.UANodeSet.Read(stream);

            Dictionary <string, UANode> nodeDict = new Dictionary <string, UANode>();

            foreach (var item in nodeSet.Items)
            {
                nodeDict.Add(item.NodeId, item);
            }

            if (nodeDict.ContainsKey("ns=2;s=Beijer.nsuri=TagProvider;s=Tags"))
            {
                UAObject tagsObject = nodeDict["ns=2;s=Beijer.nsuri=TagProvider;s=Tags"] as UAObject;

                DTDLInterface di = new DTDLInterface();
                di.Extends = null;
                di.Id      = "dtmi:opcfoundation:org:UA:MiaB:Tags;1";

                var varRefs = Array.FindAll(tagsObject.References,
                                            varNodeRef => varNodeRef.ReferenceType == "HasComponent" && varNodeRef.IsForward);
                foreach (var item in varRefs)
                {
                    UAVariable       uaVar       = nodeDict[item.Value] as UAVariable;
                    DTDLPropertyItem dpi         = new DTDLPropertyItem();
                    string[]         nodeIdParts = uaVar.NodeId.Split(';');
                    dpi.Name   = nodeIdParts[2].Substring(2);
                    dpi.Schema = "integer";
                    di.Contents.Add(dpi);
                }

                Console.WriteLine("Hello World!");
                JsonSerializerOptions options = new JsonSerializerOptions
                {
                    WriteIndented        = true,
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    IgnoreNullValues     = true,
                };
                // This is a workaround for the lack of polymorphic serialization in System.Text.Json
                // The suggested workaround in the docs (use object to declare the child item) did not work for me
                // But this custom serializer does
                options.Converters.Add(new HeterogenousListConverter <DTDLContentItem, List <DTDLContentItem> >());
                string ts = JsonSerializer.Serialize(di, options);
                System.IO.File.WriteAllText(".\\dtmi_opcfoundation_org_UA_MiaB-Tags-interface-1.json", ts);
            }
        }
Пример #3
0
        public UANodeConverter(JObject config, NamespaceTable SessionNamespaceURIs)
        {
            _config = config.ToObject <nodesConfigWrapper>().nodesLoader;

            using (Stream stream = new FileStream(_config.filename, FileMode.Open)){
                m_UANodeset       = UANodeSet.Read(stream);
                m_aliases         = m_UANodeset.Aliases;
                m_namespaceURIs   = m_UANodeset.NamespaceUris;
                out_nodeset       = new List <Node>();
                session_namespace = SessionNamespaceURIs;
            }

            selector = new NodesSelector(_config);
        }