ListData EventPipe Example

 

This example allows selection of a server using the PI-SDK control (server pick list).  The Text1 text box is used to accept tag names from the user and clicking on Command1, "Add to PointList", opens the server if necessary as pidemo, retrieves the requested tag and adds it to a global PointList collection.  The contents of the PointList is displayed in List1.  Clicking on Command2 "Get EventPipe", retrieves the EventPipe from the PointList and enables a Timer object, Timer1.  The timer is set to execute based on the number of milliseconds set by the user in text box, Text2.  When the timer fires, the Events display list, List2 is cleared and then filled with events currently in the EventPipe.  The Command4 button, "Take All", removes all the events currently in the EventPipe. The Command3 button brings up the Connections dialog allowing addition of new servers. 

Build the ListData EventPipe example as follows:

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

2. Add a reference to the PI-SDK Control under the Project | Components menu.

3. Add the visual elements as shown in the picture with the names described in the text above.

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

Dim ptlist As New PointList
Dim currentServer As Server
Dim cnxn As New Connections
Dim evpipe As EventPipe
Private Sub Command1_Click()
On Error GoTo eh
   Set currentServer = PISrvPickList1.SelectedServer
   If Not currentServer.Connected Then
      cnxn.Login currentServer, "pidemo", "", False, False
   End If
   Dim pt As PIPoint
   Set pt = currentServer.PIPoints(Text1.Text)
   ptlist.Add pt
   DisplayPointList
Exit Sub
eh:
   MsgBox Err.Description
End Sub

Private Sub Command2_Click()
On Error GoTo eh
   Set evpipe = Nothing
   ' ask for some data attributes
   Dim nvsAttrs As New NamedValues
   nvsAttrs.Add "Questionable", 1
   nvsAttrs.Add "Substituted", 1
   nvsAttrs.Add "Annotated", 1
   Set ptlist.Data.RetrievalAttributes = nvsAttrs
   Set evpipe = ptlist.Data.EventPipe
   Timer1.Interval = Text2.Text
   Timer1.Enabled = True
Exit Sub
eh:
   MsgBox Err.Description
End Sub

Private Sub DisplayPointList()
   List1.Clear
   Dim pt As PIPoint
   For Each pt In ptlist
      List1.AddItem pt.PathName
   Next
End Sub

Private Sub Command3_Click()
   cnxn.ShowConnectionDialog False
End Sub

Private Sub Command4_Click()
evpipe.TakeAll
List2.Clear
End Sub

Private Sub Timer1_Timer()
On Error GoTo eh
   If Not evpipe Is Nothing Then
   List2.Clear
   Dim l As Long
   Dim evobj As PIEventObject
   Dim ptval As PointValue
   Dim strTemp As String
   Dim nvsAttrs As NamedValues
   Dim bQuestionable As Boolean
   Dim bSubstituted As Boolean
   Dim bAnnotated As Boolean
      For l = 1 To evpipe.Count
         Set evobj = evpipe.Peek(l)
         Set ptval = evobj.EventData
         strTemp = ptval.PIPoint.PathName + " | "
         strTemp = strTemp + CStr(ptval.PIValue.TimeStamp.LocalDate) + " | "
         strTemp = strTemp + CStr(ptval.PIValue.Value)
         Set nvsAttrs = ptval.PIValue.ValueAttributes
         bQuestionable = nvsAttrs.Item("Questionable")
         bSubstituted = nvsAttrs.Item("Substituted")
         bAnnotated = nvsAttrs.Item("Annotated")
         If bQuestionable Then
            strTemp = strTemp + " | " + "Q"
         Else
            strTemp = strTemp + " | " + "N"
         End If
         If bSubstituted Then
            strTemp = strTemp + " | " + "S"
         Else
            strTemp = strTemp + " | " + "N"
         End If
         If bAnnotated Then
            strTemp = strTemp + " | " + "A"
         Else
            strTemp = strTemp + " | " + "N"
         End If
         List2.AddItem strTemp
      Next
   End If
Exit Sub
eh:
   MsgBox Err.Description
End Sub

Enabling Operational Intelligence