6 Replies Latest reply on Jul 17, 2015 8:55 PM by aseck

    Reading Annotations with PISDK

    MaximeHT

      When I try to read annotations with this code :

       

       

            If bAvecAnnotation And Me._bAnnotated Then

                          ' oAFValue.GetAnnotation Disponible avec AFSDK pour .Net 4.0

                 ' Sinon, avec .Net 3.5

                 oPoint = CType(oAFAttribute.RawPIPoint, PISDK.PIPoint)

       

                          If oPoint IsNot Nothing Then

                      retVal = oPoint.Data.ArcValue(tDateLecture, PISDK.RetrievalTypeConstants.rtAtOrBefore)

                      retValAttr = retVal.ValueAttributes

       

                      Try

                           nvAnn = retValAttr.Item("annotations") --> contains only "Annoted", "Questionnable" or "Substituted" elements, but not "annotations"

                           retAnns = CType(nvAnn.Value, PISDK.PIAnnotations) ' contains annotations collection object

       

                           If retAnns.Count > 0 Then

                                      Me._sAnnotation = CType(retAnns(0), PISDK.PIAnnotation).Value.ToString()

                           End If

       

                      Catch oExAnno As Exception

                           'Pas d'annotations ... ==> RAF

                     End Try

       

                          End If

            End If

       

      Note that this code runs under ACE context.

      Is it necessary to use MTNVS (or MTNV) and a specific thread tor read and to write annotations with PI ACE code?

        • Re: Reading Annotations with PISDK
          MaximeHT

          Note that this code runs under ACE context.

          Is it necessary to use MTNVS (or MTNV) and a specific thread tor read and to write annotations with PI ACE code?

          • Re: Reading Annotations with PISDK
            aseck

            Hello Maxime,

             

            Following our email conversation (support case 638789), I am posting our exchange here so that we can benefit from everyone's input.

             

            Here are the follow-up questions asked:

             

            Q1: What is the impact in terms of performance if we implement a read thread and a thread to write annotations for a daily copy of a couple of hundreds tags? Of course, we can consider filtering to only copy annotations on annotated source tags, which would reduce the volume to a couple tags

             

            Q2: Until now, the daily copy was realized using AFSDK (AFValue object). The usage of PI SDK was only implemented recently to handle annotations, based on the examples in PISDK.chm, which does not mention resrictions with PI ACE developments. In the solution proposed in PI Square, the annotation is always written at the same time than the value. In that case, do I need to replace the write using AFValue with a PISDK write when an annotation is needed?

             

            Here are my (preliminary) answers:

             

            A1: Due to the lack of details on your application, I cannot answer this question in absolute terms. I am assuming your application is reading data (and annotations) from a writing PI Server and writing them to some other system (another PI Server?) I would say implementing separate threads would be more efficient, but you would need to test it. If you can filter to reduce the number of values to send, it is the best thing to do.

            However AFSDK is preferred over PISDK for multi-threaded applications due to the issues that can arise calling an object living in a Single Threaded Apartment aka STA (the PI SDK) from an application using a Multi Threaded Apartment (PI ACE). For more details on STA vs MTA, see https://msdn.microsoft.com/en-us/library/ms809971.aspx)

             

            A2: I wouldn't say "absolutely", but that would simplify your code writing. Is there a reason why your DLL cannot be compiled against .NET 4.5 or 4.0? If your limitation is PI ACE, there is a way to use .NET 4.0+ with it (see http://techsupport.osisoft.com/Troubleshooting/KB/KB00645). That way you can use AF Objects such as AFAnnotation or AFAnnotations

             

            On another train of thought, It would be good to have more details on your application to provide answers that are more in context. Especially, what does it do exactly, and is there a specific reason why it has to be compiled against .NET 3.5?

            • Re: Reading Annotations with PISDK
              aseck

              Hello Maxime,

               

              Were you able to make any progress, based on our last  suggestions? Please let us know