ListData Snapshot 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 Snapshots", retrieves the Snapshots from the PointList clears the snapshot display list, List2, and error display list, List3, and then fills the lists with the snapshot events and any errors returned by the server.  

Build the ListData Snapshot 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.

Public ptlist As New PointList
Dim cnxn As New Connections
Dim currentServer As Server

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
   ' temporarily set the timeouts low for testing
   currentServer.ConnectTimeout = 5
   currentServer.Timeout = 10
   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
   List2.Clear
   List3.Clear
   Dim lstData As ListData
   Set lstData = ptlist.Data
   Dim nvsErr As NamedValues
   Dim pvsSnaps As PointValues
   Set pvsSnaps = lstData.Snapshot(nvsErr)
   If nvsErr.Count > 0 Then
      Dim nv As NamedValue
      For Each nv In nvsErr
         Dim strError As String
         strError = nv.Name + " | " + CStr(Hex(CLng(nv.Value)))
         List3.AddItem strError
      Next
   End If
   Dim ptValue As PointValue
   Dim pv As PIValue
   Dim pt As PIPoint
   For Each ptValue In pvsSnaps
      Set pv = ptValue.PIValue
      If IsError(pv.Value) Then
         List2.AddItem ptValue.PIPoint.PathName + " | " + _
            "Error: " + CStr(Hex(CLng(pv.Value)))
      Else
         List2.AddItem ptValue.PIPoint.PathName + " | " + _
            CStr(ptValue.PIValue.TimeStamp.LocalDate) + " | " + _
            CStr(ptValue.PIValue.Value)
      End If
   Next
Exit Sub
eh:
      MsgBox Err.Description
End Sub

Private Sub Command3_Click()
cnxn.ShowConnectionDialog
End Sub

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


Enabling Operational Intelligence