IGetPoints2 Example

 

 

This example, when Run button is clicked, connects to the specified server and executes a query as defined by the user. Both listboxes are cleared at this point. When the execution finishes, the first listbox is filled with tags (names) that matched the search criteria. The second listbox is filled with attribute values and names whenever the user selects (clicks) a PIPoint from the list.

The form contains 2 user selectable items:

- Server (name, default = localhost)

- tag name/mask for tag selection (default = sinu*).

Build this Server example as follows:

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

2. Add the visual elements as shown in the picture. Make sure the numbered element names (Text, Button, ListBox) match those shown.

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

 Option Explicit

Dim srv As Server ' server object
Dim nvs As NamedValues ' list of attribute names to get
 

' Run button click - execute the call and cache the pointlist
Private Sub Command1_Click()
    On Error GoTo err
    Dim pList As PointList, getEx As IGetPoints2
    Dim pPoint As PIPoint

    Set srv = PISDK.Servers(Text1.Text)
    srv.Open
    Set getEx = srv
    List1.Clear
    List2.Clear

    Set pList = getEx.GetPoints2("tag='" & Text2.Text & "'", nvs, useGetPoints)
    For Each pPoint In pList
        List1.AddItem pPoint.Name
    Next
    Exit Sub
err:
    MsgBox "Error in call:" & err.Description
End Sub

Private Sub List1_Click()
    Dim pPoint As PIPoint, pAttrs As NamedValues
    Dim pAtt As NamedValue
    On Error Resume Next

    List2.Clear
    Set pPoint = srv.PIPoints(List1.Text) ' get the selected PIPoint from Server - could use the returned pointlist too
    Set pAttrs = pPoint.PointAttributes.GetAttributes ' fetch returned attributes as NamedValues
    For Each pAtt In pAttrs ' run thru all attributes
        List2.AddItem pAtt.Name & ": " & CStr(pAtt.Value) ' show name and value
    Next
End Sub

' loading...set default values and build the attribute list (need Classic point classes at minimum)
' Note: The actual call will also return tagname, pointid/number and optionally description and pointtype
Private Sub Form_Load()
    Text1.Text = "localhost"
    Text2.Text = "sinu*"
    Set nvs = New NamedValues
    nvs.Add "archiving", 1
    nvs.Add "compdev", 1
    nvs.Add "convers", 1
    nvs.Add "compmax", 1
    nvs.Add "descriptor", 1
    nvs.Add "engunits", 1
    nvs.Add "excdev", 1
    nvs.Add "excmin", 1
    nvs.Add "excmax", 1
    nvs.Add "exdesc", 1

    nvs.Add "filtercode", 1

    nvs.Add "location1", 1
    nvs.Add "location2", 1
    nvs.Add "location3", 1
    nvs.Add "location4", 1
    nvs.Add "location5", 1

    nvs.Add "pointsource", 1
    nvs.Add "creator", 1
    nvs.Add "compressing", 1
    nvs.Add "scan", 1
    nvs.Add "span", 1
    nvs.Add "squareroot", 1

    nvs.Add "totalcode", 1

    nvs.Add "typicalvalue", 1
    nvs.Add "zero", 1
End Sub

 

Enabling Operational Intelligence