Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Problem with TagName list generation in DA

More
02 Oct 2024 06:09 #13196 by SZL
Hello,

I try your code and I create a List for LeafItems. The elements of this list will contains the proper tagnames.

At first glance, my code looks similar to yours, but I'm not going to look for the difference now, because yours works.

Thank you very much for fast solution!

Have a nice day!
The following user(s) said Thank You: support

Please Log in or Create an account to join the conversation.

More
01 Oct 2024 20:05 #13195 by support
Hello.

The proper code for recursive browsing is here: opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Late...wse%20nodes%20recursively.html .

You are doing multiple things wrong, so it does not make sense to go and correct them separately. I suggest you start with the example and modify it for your purpose.

I hope this helps.

Best regards

Please Log in or Create an account to join the conversation.

More
01 Oct 2024 19:37 #13194 by SZL
Hello,

i use this code to browse all tags in a DA server:
  public class OpcDANode
  {
      public bool IsRoot { get; set; } = false;
      public List<OpcDANode> ChildNodes { get; set; } = new List<OpcDANode>();
      public DANodeElement Node { get; set; }
 
      public bool HasChildNodes => ChildNodes.Count > 0;
 
      public string TagNameFull { get; set; }
 
      public string TagNameLastPart => Node?.Name ?? string.Empty;
 
      public bool IsLeaf => Node?.IsLeaf ?? false;
 
      public OpcDANode(DANodeElement node = null)
      {
          Node = node;
          TagNameFull = node?.ItemId ?? string.Empty;
      }
  }
 
   public async Task<List<OpcDANode>> GetAllNodesAsync()
 {
     var rootNode = new OpcDANode
     {
         IsRoot = true,
         TagNameFull = "Root"
     };
 
     try
     {
         BrowseRecursiveNodesPro(rootNode, true);
     }
     catch (Exception ex)
     {
         Log.Error("Error while browsing OPC DA items: {ErrorMessage}", ex.Message);
         throw;  
     }
 
     return new List<OpcDANode>() { rootNode };
 }
 
        private void BrowseRecursiveNodesPro(OpcDANode parentNode, bool isFirstRun = true, bool skipFirstlevelFromTagName = true)
       {
           if (isFirstRun)
           {
               parentNode.IsRoot = true;   
               parentNode.TagNameFull = parentNode.Node?.ItemId ?? "Root";   
           }
 
           var nodeFilter = new DABrowseParameters(); 
           DANodeElementCollection nodeElementCollection = new DANodeElementCollection();
 
           try
           {
               nodeElementCollection = _client.BrowseNodes(Server, isFirstRun ? "" : parentNode.TagNameFull, nodeFilter);
           }
           catch (OpcException oex)
           {
               Log.Logger.Error(oex, $"OPC Exception while browsing nodes at node {parentNode?.TagNameFull ?? "root"}.");
               return;
           }
           catch (Exception ex)
           {
               Log.Logger.Error(ex, $"Error browsing OPC nodes at node {parentNode?.TagNameFull ?? "root"}.");
               return;
           }
 
           foreach (var nodeElement in nodeElementCollection)
           {
               if (nodeElement != null)
               {
                   var childNode = new OpcDANode
                   {
                       Node = nodeElement,
                       IsRoot = false
                   };
 
                   if (isFirstRun)
                   {
                       childNode.TagNameFull = $"{nodeElement.ItemId}";
                   }
                   else
                   {
                       childNode.TagNameFull = $"{parentNode.TagNameFull}.{nodeElement.ItemId}";
                   }
 
                   parentNode.ChildNodes.Add(childNode);
 
                   if (nodeElement.IsBranch && nodeElement.ItemId != "SimulateEvents")
                   {
                       BrowseRecursiveNodesPro(childNode, false);
                   }
               }
           }
       }

I install a Matrikon OPC Server Simulator for testing.

Please see the attachment for folder (branch) structure.



The problem is that the "Simulation Items" is not part of the tagname, therefore my code throws exception because it will not find the tagname that contains "Simulation Items".

So my code generates this tagname: "Simulation Items.Bucket Brigade.ArrayOfReal8", but the correct tagname is: "Bucket Brigade.ArrayOfReal8".
I try to define the difference at object level between "Simulation Items" and "Bucket Brigade", but there are no property difference. Both is a branch.

Can you help me please what is this "Simulation Items" part, it is a namespace or something? Why the full tagname not contains this part?
How can I detect programatically that full tagname must contains "Simulation Items" or not?

Thank you!
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.051 seconds