ListData.ArcValue Example

 

 

This example allows selection of a collection of points by launching the Tag Search dialog, the specification of a time and a mode and then the execution of the ArcValue call either synchronously or asynchronously.  When executed asynchronously the program displays the status of the call as it progresses in the list box (the 1 and 2 in the picture above) and tracks the progress of the call using a ProgressBar control. 

  

The picture above shows the form before execution.  To agree with the code name the Execute button Command1 and the Build Point List button Command2.  The text box for the date is named txtDate.  The checkbox for asynchronous behavior is named chkAsynch.  The ProgressBar is named ProgressBar1 and the empty label for showing the number of tags in the lower right of the form is named lblCount.

 

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.  Also add the component reference to Microsoft Windows Common Controls 5.0 (SP2) for the ProgressBar control.

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.

Option Explicit
Dim asynch As New PIAsynchStatus
Dim ld As ListData
Dim srv As Server
Dim WithEvents asynchEvt As PIAsynchStatus
Dim ptvals As PointValues
Dim nvsErrs As NamedValues
Dim ptlist As New PointList
Dim pctRetrieval As PIConstant

Private Sub asynchEvt_OnProgressChange(ByVal NewProgress As Double)
   ProgressBar1.Value = NewProgress
End Sub

Private Sub asynchEvt_OnStatusChange(ByVal NewStatus As PISDKCommon.CallStatusConstants)
   List1.AddItem CStr(NewStatus)
End Sub

Private Sub Command1_Click()
On Error GoTo eh
   List1.Clear
   If ptlist Is Nothing Or ptlist.Count = 0 Then
      MsgBox "Build a pointlist first please."
      Exit Sub
   End If
   Dim mode As RetrievalTypeConstants
   mode = pctRetrieval.Item(cmbMode.Text).Value
   If chkAsynch.Value = 1 Then
      If asynchEvt Is Nothing Then
         Set asynchEvt = asynch
      End If
      Timer1.Interval = 100
      Timer1.Enabled = True
      Dim ptvalsTemp As PointValues
      Dim nvsErrorsTemp As NamedValues
      Set ptvalsTemp = ld.ArcValue(txtDate.Text, mode, nvsErrorsTemp, asynch)
      Set ptvals = ptvalsTemp
      Set nvsErrs = nvsErrorsTemp
   Else
      Set ptvals = ld.ArcValue(txtDate.Text, mode, nvsErrs)
      ShowResults
   End If
Exit Sub
eh:
   MsgBox Err.Description
End Sub

Private Sub Command2_Click()
   Dim tagsearch As New tagsearch
   Dim ptlistSearch As PointList
   Set ptlistSearch = tagsearch.Show
   ptlist.Merge ptlistSearch
   
   Set ld = ptlist.Data

End Sub

Private Sub Form_Load()
   Set srv = Servers.DefaultServer
   ' load mode combo
   Dim nvConst As NamedValue
   Set pctRetrieval = PIConstants.Item("RetrievalTypeConstants")
   For Each nvConst In pctRetrieval
      cmbMode.AddItem nvConst.Name
   Next
   cmbMode.ListIndex = 0
   txtDate.Text = CStr(Now())
   
End Sub

Private Sub Timer1_Timer()
   DoEvents
   If asynch.Status = csComplete Or asynch.Status = csCompleteWithErrors Then
      Timer1.Enabled = False
      ShowResults
   End If
End Sub
Private Sub ShowResults()
      Dim ptval As PointValue
      For Each ptval In ptvals
         Dim strTemp As String
         strTemp = ptval.PIPoint.PathName + " | "
         strTemp = strTemp + CStr(ptval.PIValue.TimeStamp.LocalDate) _
               + " | "
         strTemp = strTemp + CStr(ptval.PIValue.Value)
         List1.AddItem strTemp
      Next
      Dim nvErr As NamedValue
      For Each nvErr In nvsErrs
         List1.AddItem "Server error: " + nvErr.Name + " | " + CStr(nvErr.Value)
      Next
      lblCount.Caption = CStr(ptvals.Count)
End Sub

Enabling Operational Intelligence