PIAnnotations example

 

Option Explicit

Private Sub Command1_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 = myData.Snapshot
'
' 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
 

Enabling Operational Intelligence