private void Browse(string id_opcclient, OpcNodeInfo node, int level = 0)
 {
     if (node.Children().Count() == 0)
     {
         if (repo._context.sys_opcs.Where(t => t.id_opcclient == id_opcclient && t.opcnode == node.NodeId.ToString()).Count() == 0)
         {
             var db = new DataBase.System.sys_opc_db()
             {
                 create_by    = getUserId(),
                 name         = node.Name.ToString(),
                 id_opcclient = id_opcclient,
                 opcnode      = node.NodeId.ToString(),
                 id           = Guid.NewGuid().ToString(),
                 status_del   = 1,
                 note         = "auto insert",
             };
             repo._context.sys_opcs.AddAsync(db);
             repo._context.SaveChanges();
         }
     }
     level++;
     foreach (var childNode in node.Children())
     {
         Browse(id_opcclient, childNode, level);
     }
 }
Beispiel #2
0
        private static void Browse(OpcNodeInfo node, int level)
        {
            //// In general attributes and children are retrieved from the server on demand. This
            //// is done to reduce the amount of traffic and to improve the preformance when
            //// searching/browsing for specific attributes or children. After attributes or
            //// children of a node were browsed they are stored internally so that subsequent
            //// attribute and children requests are processed without any interaction with the
            //// OPC UA server.

            // Browse the DisplayName attribute of the node. It is also possible to browse
            // multiple attributes at once (see the method Attributes(...)).
            var displayName = node.Attribute(OpcAttribute.DisplayName);

            Console.WriteLine(
                "{0}{1} ({2})",
                new string(' ', level * 4),
                node.NodeId.ToString(OpcNodeIdFormat.Foundation),
                displayName.Value);

            // Browse the children of the node and continue browsing in preorder.
            foreach (var childNode in node.Children())
            {
                Program.Browse(childNode, level + 1);
            }
        }
Beispiel #3
0
        private void Browse(OpcNodeInfo node, int level = 0)
        {
            Console.WriteLine("{0}{1}({2})",
                              new string('.', level * 4),
                              node.Attribute(OpcAttribute.DisplayName).Value,
                              node.NodeId);

            level++;

            foreach (var childNode in node.Children())
            {
                Browse(childNode, level);
            }
        }
Beispiel #4
0
        private static IEnumerable <(OpcNodeId ParentId, OpcMethodNodeInfo Node)> BrowseMethods(OpcNodeInfo node)
        {
            var parentId = node.NodeId;

            foreach (var childNode in node.Children())
            {
                if (childNode is OpcMethodNodeInfo methodNode)
                {
                    yield return(parentId, methodNode);
                }
                else
                {
                    foreach (var childMethod in BrowseMethods(childNode))
                    {
                        yield return(childMethod);
                    }
                }
            }
        }
Beispiel #5
0
        private static int GetLastJob(OpcNodeInfo jobsNode)
        {
            var readJobs = new List <OpcReadNode>();

            foreach (var childNode in jobsNode.Children())
            {
                if (childNode is OpcVariableNodeInfo jobNode)
                {
                    readJobs.Add(new OpcReadNode(jobNode.NodeId, OpcAttribute.BrowseName));
                }
            }

            var client = jobsNode.Context.Client;

            return((from value in client.ReadNodes(readJobs)
                    where value.Status.IsGood
                    let jobName = value.As <OpcName>().Value
                                  let jobId = int.Parse(jobName.Substring("JOB".Length))
                                              select jobId).Max());
        }