david@realiv

DataSheet Control Insert the value of the PIAnnotations Unable to read

Discussion created by david@realiv on Sep 23, 2013
Latest reply on Sep 24, 2013 by lZheng

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?

Outcomes