6 Replies Latest reply on Dec 7, 2011 3:34 AM by Bineesh

    retrieve PI tag Annotations usinf PI SDK

    Bineesh

      Hi team,

       

      Could you please help me with a sample code for retrieving Annotations  for a tag using PI SDK

       

      regards

       

      Bineesh

        • Re: retrieve PI tag Annotations usinf PI SDK
          Bineesh

          Hi all,

           

          forgot to mention, Im developing in C# and using new, structured way (spreadsheet / Excel-look)

          • Re: retrieve PI tag Annotations usinf PI SDK
            Bineesh

            Hi all,

             

            forgot to mention, Im developing in C# and using new, structured way (spreadsheet / Excel-look)

              • Re: retrieve PI tag Annotations usinf PI SDK
                andreas

                Have you had a look here or here?

                  • Re: retrieve PI tag Annotations usinf PI SDK
                    Bineesh

                    Hi,

                     

                    I have tried the code:

                     
                    PISDK.PIData piData;
                    PISDK.PIValue piValue;
                    piData = snapPoint.Data;
                    PISDK.PIAnnotations retAnns = new PISDK.PIAnnotations();
                    PISDKCommon.NamedValues retrievalAttributes = new PISDKCommon.NamedValues();
                    object oAnnotationsString = "Annotations";
                    retrievalAttributes.Add("Annotations", ref oAnnotationsString);
                    snapPoint.Data.RetrievalAttributes = retrievalAttributes;
                    piValue = piData.ArcValue((object)valPiValue.TimeStamp.LocalDate, PISDK.RetrievalTypeConstants.rtCompressed, null);
                    PISDKCommon.NamedValue nvAnnotations = piValue.ValueAttributes.get_Item(ref oAnnotationsString);
                    if (nvAnnotations.Value is PISDK.PIAnnotations)
                    {
                        retAnns = (PISDK.PIAnnotations)nvAnnotations.Value;
                    }
                    

                     

                     

                    But this is giving me the value as 'System.__ComObject}'. is there any way I can convert this to original value..

                     

                    Please suggest

                     

                    Bineesh

                      • Re: retrieve PI tag Annotations usinf PI SDK

                        Basically, what you got there is a collection of annotations (a collection of PIAnnotation objects). All you need to do is loop through it and look into each individual PIAnnotation object's Value property.

                         
                        foreach (PIAnnotation ann in retAnns)
                          // Do something with ann.Value;
                        

                         

                         

                        If you still get a System.__ComObject from ann.Value, then that means whatever wrote that annotation wrote a COM object into it; you'll have to track that original writer of the annotation to understand how to interpret the object.

                          • Re: retrieve PI tag Annotations usinf PI SDK
                            Bineesh

                            Thanks all,

                             

                            Im able to achieve this using below code snippet:

                             
                            retrievalAttributes.Add("Annotations", ref oAnnotationsString);
                            snapPoint.Data.RetrievalAttributes = retrievalAttributes;
                            DataTable table1 = new DataTable("Annotations");
                            table1.Columns.Add("Value");
                            table1.Columns.Add("Name");
                            table1.Columns.Add("Description");
                            table1.Clear();
                            dataGridView1.DataSource = "";
                            
                            try
                            {
                                piValue = piData.ArcValue((object)valPiValue.TimeStamp.LocalDate,
                                        PISDK.RetrievalTypeConstants.rtCompressed, null);
                            
                                PISDKCommon.NamedValue nvAnnotations = piValue.ValueAttributes.get_Item(ref oAnnotationsString);
                            
                                if (nvAnnotations.Value is PISDK.PIAnnotations)
                                {
                                    retAnns = (PISDK.PIAnnotations)nvAnnotations.Value;
                                }
                            
                                foreach (PISDK.PIAnnotation curAnn in retAnns)
                                {
                                    string annValue = curAnn.Value.ToString();
                                    string annName = curAnn.Name.ToString();
                                    string annDescription = curAnn.Description.ToString();
                                    table1.Rows.Add(annValue, annName, annDescription);
                                }
                                
                                dataGridView1.DataSource = table1;
                            }