IPointAttributes Example

 

 

This example, when Run button is clicked, connects to the specified server, builds a PointList based on user defined tag names and  then gets predefined PointAttributes for the tags. Both listboxes are cleared at this point. When the execution finishes, the first listbox is filled with tags (names) that were included in the PointList. 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)

- tags (name list) that will be included in the constructed PointList (must be valid tags)

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, Checkbox, Button, ListBox) match those shown.

3. Set the MultiLine property of the textbox "Text2" to True. The tag names in this box must be separated by linefeed.

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
Dim nvsRet As NamedValues ' list of actual attributes returned for the pointlist
Dim pList As PointList ' returned pointlist
Dim iPAttr As IPointAttributes
 

' Run button click - execute the call and cache the pointlist
Private Sub Command1_Click()
    On Error GoTo err
    Dim pPoint As PIPoint
    Dim tagName As String
    Dim tagIdx As Integer, endIdx As Integer
    Dim piErrs As PIErrors

    Set srv = PISDK.Servers(Text1.Text)
    srv.Open ' open server
    List1.Clear ' clear previous results
    List2.Clear
    Set pList = New PointList ' always create a new list
    tagIdx = 1
    ' create pointlist from the defined tag names. Parse the string..
    While tagIdx > 0
        Set pPoint = Nothing
        endIdx = InStr(tagIdx, Text2.Text, vbLf)    ' look for linefeed/RET
        If endIdx < 1 Then
            If Len(Text2.Text) > tagIdx Then
                Set pPoint = srv.PIPoints(Right(Text2.Text, Len(Text2.Text) - tagIdx + 1))
            End If
            tagIdx = endIdx
        Else
            Set pPoint = srv.PIPoints(Mid(Text2.Text, tagIdx, endIdx - tagIdx))
            tagIdx = endIdx + 1
        End If
        If Not pPoint Is Nothing Then pList.Add pPoint
    Wend
 

    ' Use the IPointAttributes interface to get all defined attributes for all defined points
    Set iPAttr = pList 'get IPointAttributes interface from PointList
    Set piErrs = iPAttr.GetSelectedAttributes(nvs, True, nvsRet) ' get all attributes as nested NamedValues

    For Each pPoint In pList
        List1.AddItem pPoint.Name ' list all tagnames in the selection list (list1)
    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