コード例 #1
0
 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);
     }
 }
コード例 #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);
            }
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: oba-mlittle/FDACore
        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);
            }
        }
コード例 #4
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());
        }
コード例 #5
0
        private bool Browse(OpcNodeInfo node, TreeNodeCollection treeNodes)
        {
            var result = false;

            try {
                var treeNode = treeNodes.Add(node.DisplayName.Value);

                if (node is OpcObjectNodeInfo)
                {
                    treeNode.ImageIndex = 0;

                    if (node.Reference.TypeDefinitionId == Opc.Ua.ObjectTypeIds.FolderType)
                    {
                        treeNode.ImageIndex = 1;
                    }
                }
                else if (node is OpcMethodNodeInfo)
                {
                    treeNode.ImageIndex = 2;
                }
                else if (node is OpcVariableNodeInfo)
                {
                    treeNode.ImageIndex = 3;

                    if (node.Reference.ReferenceType == OpcReferenceType.HasProperty)
                    {
                        treeNode.ImageIndex = 4;
                    }
                }

                treeNode.Tag = node;

                treeNode.Nodes.Add("Browsing...");
                result = true;
            }
            catch (OpcException ex) {
                this.ShowMessage("Browse", "Failed to browse: " + ex.Message);
            }

            return(result);
        }
コード例 #6
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);
                    }
                }
            }
        }
コード例 #7
0
 private static void Browse(OpcNodeInfo node)
 {
     Program.Browse(node, 0);
 }
コード例 #8
0
 private bool Browse(OpcNodeInfo node)
 {
     this.nodesTreeView.Nodes.Clear();
     return(this.Browse(node, this.nodesTreeView.Nodes));
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: erllon/OPC-Server-Client
    public static void Main()
    {
        string             stringEntered = "";
        bool               exitSession   = false;
        List <OpcNodeInfo> listOfNodes;

        using (var client = new OpcClient("opc.tcp://localhost:4840"))
        {
            client.Connect();

            while (true)//(!exitSession)
            {
                Console.WriteLine("Available commands: 'view' 'edit' 'disconnect'");
                Console.Write("Enter a command from the above list: ");
                stringEntered = Convert.ToString(Console.ReadLine());

                switch (stringEntered)
                {
                case "view":
                {
                    Console.WriteLine("Enter the name(s) of the node(s) separated by whitespace(s):");
                    string             fullString   = Console.ReadLine();
                    List <OpcNodeInfo> nodeInfoList = AddNodesToList(fullString, client);
                    Console.WriteLine("****************************");
                    foreach (OpcNodeInfo infoElement in nodeInfoList)
                    {
                        //Start here!
                    }
                    Console.WriteLine("****************************");

                    DisplayNodeInfo(nodeInfoList);
                    break;
                }

                case "editValue":
                {
                    //EditNodeValue();
                    break;
                }

                case "disconnect":
                {
                    client.Disconnect();
                    Console.WriteLine("Session is exiting...");
                    exitSession = true;
                    break;
                }

                default:
                {
                    Console.WriteLine(stringEntered + " is not an accepted command");
                    break;
                }
                }
                string[] splittedString = stringEntered.Split(" ");
                listOfNodes = new List <OpcNodeInfo>(); //or initialize it when declared and clear the list here?
                OpcNodeInfo machineNode;
                foreach (string substring in splittedString)
                {
                    machineNode = client.BrowseNode($"ns=2;");
                    // if(!machineNode.Name.IsNull)
                    // {
                    OpcNodeInfo jobnode = machineNode.Child("Job");
                    listOfNodes.Add(machineNode);
                    //}
                }
                OpcBrowseNode             test           = new OpcBrowseNode("s=Message");
                IEnumerable <OpcNodeInfo> infoAboutNodes = client.BrowseNodes(test);
                foreach (string element in splittedString)
                {
                    List <OpcReadNode> liste = new List <OpcReadNode>();
                    liste.Add(new OpcReadNode("s=Message"));
                    //OpcNodeInfo info = client.BrowseNode($"ns=2;s=Message");
                    List <OpcBrowseNode> liste2 = new List <OpcBrowseNode>();
                    //OpcBrowseNode test = new OpcBrowseNode("s=Message");
                    IEnumerable <OpcNodeInfo> info = client.BrowseNodes(test);
                    Console.WriteLine("\n**********************************");
                    Console.WriteLine("Writing the infoElements...");
                    Console.WriteLine("**********************************\n");

                    foreach (OpcNodeInfo infoElement in info)
                    {
                        Console.WriteLine("NodeID: " + infoElement.NodeId);
                        Console.WriteLine("InfoElement:: " + infoElement.ToString() + "\n");
                    }
                    var nodeOfInterest = client.ReadNode($"ns=2;s={stringEntered}");
                    if (nodeOfInterest.Value != null)
                    {
                        Console.Write($"The value of the node is: {nodeOfInterest.Value}\t");
                        Console.WriteLine($"The ID of the node is: {nodeOfInterest.DataTypeId}\n");
                    }
                }

                if (client.State == OpcClientState.Connected)
                {
                    var temperature = client.ReadNode("ns=2;s=Temperature");
                    var message     = client.ReadNode("ns=2;s=Message");
                    var level       = client.ReadNode("ns=2;s=Level");
                    Console.WriteLine($"Current Temperature is {temperature} °C");
                    Console.WriteLine($"Current message is {message}");
                    Console.WriteLine($"Level: {level}");
                }

                Thread.Sleep(1000);
            }
        }
    }