4 Replies Latest reply on Dec 5, 2011 1:15 PM by cmanhard

    Getting tag info from Tag Data Reference attributes.

    AlistairFrith

      Second time lucky since it ate the text the first time!

       

      We have a C# function that returns the tagnames associated with each PIPoint data reference attribute of a given AF element. See below

       
      public KeyValuePair[] ReturnElementTagReferences(AFElement e)
      {
          List<> kvpl = new List<>();
      
          if (e != null)
          {
              try
              {
                  foreach (AFAttribute at in e.Attributes)
                  {
                      if (at.DataReference != null)
                      {
                          //PISDK.PIPoint p = (PISDK.PIPoint)at.RawPIPoint;
                          kvpl.Add(new KeyValuePair(at.Name, at.DataReference.ToString()));
                          if (p != null)
                              kvpl.Add(new KeyValuePair(at.Name.ToString(), p.Name.ToString()));
                      }
                  }
              }
              catch (Exception ex)
              {
                  LogMessage("Error ReturnElementTagReferences : " + ex.Message + "\nSource: " + ex.Source + "\n" + ex.InnerException);
                  kvpl = null;
              }
          }
          if (kvpl.Count > 0)
              return kvpl.ToArray();
          else
              return null;
      
      }
      

       

       

      This works fine when called from C# but when called from a VB.Net application, it returns tag names of the form

       

      \\MyPIServer?d015c285-b527-4fbe-820f-a43c445d5e11\sinusoid

       

      instead of the tag name that we see in C#. Interestingly, in VB the data reference Description property is "Unable to create the PISDK. PI Data References will not function." when called from VB.Net when it says "PI Tag" when called from C#.

       

      Does anyone have any idea what is going on here?

       

      --- Alistair.

       

       

       

      <edit>

       

      We have now created a separate VB.Net application to call this C# function and it works as expected. So it's not a difference between VB and C# but something in the real VB project is screwing this up!

       

      </edit>

        • Re: Getting tag info from Tag Data Reference attributes.
          MvanderVeeken

          Alistar,

           

          Just to be sure that I understand it correctly:

           

          You have a Visual Studio Solution (your original application) that has a VB.NET project and a C# Project which includes the sample code you presented above. This solution has the issue you described above.

           

          Next to that you build a 'test' project that includes a simple VB.NET project and the same C# project mentioned above. This one presents no issue, and gives the correct result.

           

          Are these conclusions/assumptions correct?

           

          Also I'm wondering why you are using an array (and List<T>) of KeyValuePair<T1, T2> instead of using a Dictionary<T1, T2>? Is this because you expect duplicate keys?

            • Re: Getting tag info from Tag Data Reference attributes.
              AlistairFrith

              Yes, that's pretty much it. And yes, I think that duplicate keys are a possibility.

               

              Except that, as mentioned in the edit above, the dummy VB project built by my colleague works. He has also tried taking my VB project and running it on his machine and it fails for him too.

               

              --- Alistair.

                • Re: Getting tag info from Tag Data Reference attributes.
                  AlistairFrith

                  Here's the code I am using to call that function. And in fact, I can see the error message a little earlier....

                   
                  For Each childElement As OSIsoft.AF.Asset.AFElement In children
                      '
                      ' ...
                      '
                  
                      Dim attribute As OSIsoft.AF.Asset.AFAttribute = childElement.Attributes.Item("L0_TagName")
                      sValue = attribute.GetValue().Value.ToString()    ' <-- here, sValue becomes "Unable to create the PISDK. PI Data References will not function."
                      sConfig = attribute.ConfigString.ToString()            ' <-- here, sConfig becomes "\\MyPIServer?d015c285-b527-4fbe-820f-a43c445d5e11\sinusoid"
                  
                      Dim tagReferences() As System.Collections.Generic.KeyValuePair(Of String, String)
                      tagReferences = AFH.ReturnElementTagReferences(childElement)
                      sConfig = tagReferences(0).Value
                  
                      '
                      ' ...
                      '
                  Next childElement
                  

                   

                   

                  In this code, I have already retrieved a list of AF elements in 'children' but each one has this error. Why would it be "Unable to create the PISDK"? Is it something to do with references? 

                   

                   

                   

                  --- Alistair.