ArchiveEventPipe Example

 

This example allows selection of a server and a tag whose archive events are to be monitored.  Pressing the Sign Up button locates the desired point and retrieves an ArchiveEventPipe for it.  The buttons below the line provide a mechanism to easily generate events for the entered tag and the list box displays the events as they arrive in the EventPipe.  Note Archive events are currently only retrieved by the SDK once every 60 seconds so after generating an event you may need to wait that long to see it displayed in the list box.

 

Build the ArchiveEventPipe example as follows:

1. Create a new project and add a reference to the PISDK library.

2. Add the visual elements as shown in the picture. The names for the objects shown are as follows:

Item Name
Server Pick List PISrvPickList1
Tag name text box Text2
Sign Up button Command1
Replace button cmdReplace
Insert button cmdInsert
Delete button cmdDelete
Value text box Text1
Time text box Text3
Listbox List1
Timer Timer1

 

3. Cut and paste the code below into the project.

Option Explicit

Dim aep As EventPipe
Dim pidata As pidata
Dim bSignedUp As Boolean

Private Sub cmdDelete_Click()
On Error GoTo eh
   Dim pt As New PITimeFormat
   If bSignedUp = False Then
      MsgBox "Press sign up first to capture events"
      Exit Sub
   End If
   pt.InputString = Text3.Text
   If Not pidata Is Nothing Then
      pidata.RemoveValues pt, pt, drRemoveAll
   End If
Exit Sub
eh:
MsgBox Err.Description

End Sub

Private Sub cmdInsert_Click()
On Error GoTo eh
   Dim pt As New PITimeFormat
   If bSignedUp = False Then
      MsgBox "Press sign up first to capture events"
      Exit Sub
   End If
   pt.InputString = Text3.Text
   If Not pidata Is Nothing Then
      pidata.UpdateValue Text1.Text, pt, dmInsertDuplicates
   End If
Exit Sub
eh:
MsgBox Err.Description
End Sub

Private Sub cmdReplace_Click()
On Error GoTo eh
   Dim pt As New PITimeFormat
   If bSignedUp = False Then
      MsgBox "Press sign up first to capture events"
      Exit Sub
   End If
   pt.InputString = Text3.Text
   If Not pidata Is Nothing Then
      pidata.UpdateValue Text1.Text, pt, dmReplaceDuplicates
   End If
Exit Sub
eh:
MsgBox Err.Description
End Sub

Private Sub Command1_Click()
Dim srv As Server
On Error GoTo eh
   List1.Clear
   Set srv = PISrvPickList1.SelectedServer
   Dim pt As PIPoint
   Set pt = srv.PIPoints(Text2.Text)
   Set pidata = pt.Data
   Dim pd2 As IPIData2
   Set pd2 = pidata
   Set aep = pd2.ArchiveEventPipe
   Timer1.Interval = 5000
   Timer1.Enabled = True
   bSignedUp = True
Exit Sub
eh:
MsgBox Err.Description
End Sub

Private Sub Form_Load()
Text2.Text = "sinusoid"
bSignedUp = False
End Sub

Private Sub Timer1_Timer()
On Error GoTo eh
   Dim EvObj As PIEventObject
'   Dim arrEvObj() As PIEventObject
   Dim arrEvObj As Variant
   Dim ptval As PointValue

   If aep.Count > 0 Then
'      Set evobj = aep.Take
'      Set ptval = evobj.EventData
'      MsgBox "got an event"
'      Debug.Print TypeName(aep.TakeAll)
      arrEvObj = aep.TakeAll
      Dim i As Integer
      Dim strType As String
      For i = LBound(arrEvObj) To UBound(arrEvObj)
         Set EvObj = arrEvObj(i)
         Set ptval = EvObj.EventData
         Select Case EvObj.Action
            Case eaAdd
               strType = "Add"
            Case eaUpdate
               strType = "Update"
            Case eaDelete
               strType = "Delete"
            Case eaEdit
               strType = "Edit"
            Case Else
               strType = "Unknown"
         End Select
         List1.AddItem ptval.PIPoint.Name + " | " + strType + " | " + _
             CStr(ptval.PIValue.Value) + " | " + CStr(ptval.PIValue.TimeStamp.LocalDate)
      Next
   End If
Exit Sub
eh:
MsgBox Err.Description
End Sub


   
Enabling Operational Intelligence