1 Reply Latest reply on Sep 24, 2013 2:40 PM by lZheng

    DataSheet Control Insert the value of the PIAnnotations Unable to read

    david@realiv

      Private Sub CommandButton1_Click()

       

       

       

      Dim myServer As Server

       

      Dim testTag As PIPoint

       

      Dim myAnns As PIAnnotations

       

      Dim integerAnn As PIAnnotation

       

      Dim floatAnn As PIAnnotation

       

      Dim myData As PIData

       

      Dim myVal As PIValue

       

      Dim myVals As New PIValues

       

      Dim retVal As PIValue

       

      Dim valTim As New PITime

       

      Dim myValAttr As New NamedValues

       

      Dim retValAttr As NamedValues

       

      Dim errStr As String

       

      Dim curVal As Double

       

      Dim nvAnn As NamedValue

       

      Dim retAnns As PIAnnotations

       

      Dim curAnn As PIAnnotation

       

       

       

      Set myServer = PISDK.Servers.DefaultServer

       

      myServer.Open

       

      '

       

      ' Add/find a test tag for adding an annotation to

       

      '

       

      Dim datavalue As PIData

       

      Dim s As String

       

      On Error Resume Next ' turn error checking off, in case the tag already exists

       

      Set myData = myServer.PIPoints("CEPH_M1008").Data'Datasheetcontrol insert data, annotation information, cannot read

       

      '

       

      ' Now retrieve the annotated value

       

      '

       

      ' Get the snapshot value

       

      '

       

      Set retVal = myData.ArcValue("2013-9-22 15:27:00", rtCompressed)

       

      '

       

      ' Check the annotations that came back

       

      '

       

      Set retValAttr = retVal.ValueAttributes

       

      Set nvAnn = retValAttr.Item("annotations")

       

      Set retAnns = nvAnn.Value ' contains annotations collection object

       

      For Each curAnn In retAnns

       

      MsgBox "Annotation name: " & curAnn.Name & " Value: " & curAnn.Value

       

      Next

       

       

       

       

       

      End Sub

       

       

       

      Private Sub CommandButton2_Click()

       

      Dim myServer As Server

       

      Dim testTag As PIPoint

       

      Dim myAnns As PIAnnotations

       

      Dim integerAnn As PIAnnotation

       

      Dim floatAnn As PIAnnotation

       

      Dim myData As PIData

       

      Dim myVal As PIValue

       

      Dim myVals As New PIValues

       

      Dim retVal As PIValue

       

      Dim valTim As New PITime

       

      Dim myValAttr As New NamedValues

       

      Dim retValAttr As NamedValues

       

      Dim errStr As String

       

      Dim curVal As Double

       

      Dim nvAnn As NamedValue

       

      Dim retAnns As PIAnnotations

       

      Dim curAnn As PIAnnotation

       

       

       

      Set myServer = PISDK.Servers.DefaultServer

       

      myServer.Open

       

      '

       

      ' Add/find a test tag for adding an annotation to

       

      '

       

      On Error Resume Next ' turn error checking off, in case the tag already exists

       

      Set testTag = myServer.PIPoints.Add("AnnotationTestTag", "Classic", pttypFloat32)

       

      Set testTag = myServer.PIPoints.Item("AnnotationTestTag")

       

      Set myData = testTag.Data ' Get the data object for the tag

       

      '

       

      ' Set the retrevial attributes.

       

      ' These may already be set from a previous run (since the tags are cached), so leave error checking off

       

      '

       

      myData.RetrievalAttributes.Add "Annotations", 1 ' set the annotations flag so we can retrieve it later

       

      On Error GoTo 0 ' turn error checking back on

       

      '

       

      ' Create an annotations collection to add to a value

       

      '

       

      Set myAnns = New PIAnnotations

       

      '

       

      ' Add two annotations to the collection

       

      '

       

      Set integerAnn = myAnns.Add("IntegerAnn", "Integer annotation", 1, False, "Integer")

       

      Set floatAnn = myAnns.Add("FloatAnn", "Float annotation", 1.23, False, "Float")

       

      '

       

      ' Create a value to send to the snapshot

       

      '

       

      myVals.ReadOnly = False

       

      valTim.SetToCurrent

       

      myValAttr.Add "annotations", myAnns ' add the annotations collection to the value

       

      curVal = valTim.UTCSeconds

       

      Set myVal = myVals.Add(valTim.LocalDate, curVal, myValAttr)

       

      myData.UpdateValue myVal, valTim

       

      '

       

      ' Now retrieve the annotated value

       

      '

       

      ' Get the snapshot value

       

      '

       

      Set retVal = myServer.PIPoints("AnnotationTestTag").Data.ArcValue("2013-9-23 13:21:51", rtCompressed)'Code manually inserted data annotation information, can be read out

       

      '

       

      ' Check the annotations that came back

       

      '

       

      Set retValAttr = retVal.ValueAttributes

       

      Set nvAnn = retValAttr.Item("annotations")

       

      Set retAnns = nvAnn.Value ' contains annotations collection object

       

      For Each curAnn In retAnns

       

      MsgBox "Annotation name: " & curAnn.Name & " Value: " & curAnn.Value

       

      Next

       

       

       

      End Sub

       

      The above two buttons to read different point information, one can read the value of the annotation, one cannot read why?

        • Re: DataSheet Control Insert the value of the PIAnnotations Unable to read
          lZheng

          Hello Quan Da Yong, 

           

          Looking at your code, for both commands, you are trying to retrieve the value at an exact timestamp. 

           
          CommandButton1:
          Set retVal = myData.ArcValue("2013-9-22 15:27:00", rtCompressed)
          CommandButton2:
          Set retVal = myServer.PIPoints("AnnotationTestTag").Data.ArcValue("2013-9-23 13:21:51", rtCompressed)
          

          It’s very likely that at the first timestamp "2013-9-22 15:27:00", there is no archive value, therefore the no annotation could be found.  If you change the value retrieval type to RetrievalTypeConstants.rtBefore, you will get the last archive value. 

           

          Some explanation about value retrieval type:

           

          rtCompressed

           

          Return a recorded value at the passed time or return an error if none exists. (For ArcValue)

           

          rtBefore

           

          Return the first recorded value before the passed time.

           

          For more information about value retrieval constant type, please refer to pisdk help - Retrieval Type Settings.

           

          Also I see you are trying to get the snapshot value with following code: 

           
          ' Get the snapshot value
          Set retVal = myData.ArcValue("2013-9-22 15:27:00", rtCompressed)
          

           This will not retrieve snapshot value, but an archive value at the specified timestamp if the value exists.  To retrieve snapshot value you can use:

           

          Set retVal = myData.Snapshot