PIPoints Programming Example

 

This example, during the Form_Load, connects to the default server, clears out the text boxes and fills a combo box with the supported point type names. This example uses the PIConstants and PIConstant collections to populate a combo box with string names for the PointTypeConstants enumeration. During the PIPoints.Add method, the PIConstant collection is again used to determine the enumeration value of the selected string.

The example allows the user to enter a tag name in Text1, select a point type and click Command1 to add a new point to the system. The PIPoints.Add call uses the optional NamedValues collection of additional attribute settings during the create.

 

Entering a tag name in Text2 and clicking Command2 will attempt to remove the PIPoint with the entered tag name using PIPoints.Remove.

Entering old and new tag names in Text3 and Text4 and clicking Command3 will call PIPoints.Rename to change the tag name of the PIPoint.

 

Build the PIPoints example as follows:

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

2. Add the visual elements as shown in the picture. Make sure the numbered element names (label1, list1, &ldots;) match those shown.

 

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

  Option Explicit
Dim srv As Server

Private Sub Command1_Click()
On Error GoTo handler
  If Text1.Text = "" Then
    MsgBox "Please enter a tagname for the new PIPoint"
    Exit Sub
  End If
  Dim ptType As PointTypeConstants
  ptType = PIConstants("PointTypeConstants")(Combo1.Text).Value
  Dim nvAttrs As New NamedValues
  nvAttrs.Add "descriptor", "My new point"
  srv.PIPoints.Add Text1.Text, "classic", ptType, nvAttrs
Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub Command2_Click()
On Error GoTo handler
  If Text2.Text = "" Then
    MsgBox "Please enter a tag name for the PIPoint to remove"
    Exit Sub
  End If
  srv.PIPoints.Remove Text2.Text
Exit Sub
handler:
  MsgBox Err.Description

End Sub

Private Sub Command3_Click()
On Error GoTo handler
  If Text3.Text = "" Or Text4.Text = "" Then
    MsgBox "Please enter an old and new tag name for the rename"
    Exit Sub
  End If
  srv.PIPoints.Rename Text3.Text, Text4.Text
Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub Form_Load()
On Error GoTo handler
  Set srv = Servers.DefaultServer
  srv.Open
  ClearEntries
  ShowPointTypes
Exit Sub
handler:
  MsgBox Err.Description
End Sub
Private Sub ClearEntries()
  Text1.Text = ""
  Text2.Text = ""
  Text3.Text = ""
  Text4.Text = ""
End Sub
Private Sub ShowPointTypes()
On Error GoTo handler
  Dim cnst As PIConstant
  Set cnst = PIConstants("PointTypeConstants")
  Dim nvType As NamedValue
  Dim i As Long
  Dim indx As Long
  indx = 0
  i = 0
  For Each nvType In cnst
    Combo1.AddItem nvType.Name
    If nvType.Value = pttypFloat32 Then
      indx = i
    End If
    i = i + 1
  Next
  Combo1.ListIndex = indx
Exit Sub
handler:
  MsgBox Err.Description
End Sub
Enabling Operational Intelligence