AnsweredAssumed Answered

How to write values to PI-Archive on VBA

Question asked by siz07 on Sep 2, 2015
Latest reply on Sep 4, 2015 by stang

Hello.

This code will write data to PI-server(from help):

 

Private Sub Command1_Click()
'Dim srv_write As Server
Dim ptval As PIPoint
Dim vals As New PIValues, piVal As PIValue
Dim nvAtts As New NamedValues
Dim piErr As PIErrors
On Error GoTo eMsg
  Me.MousePointer = vbHourglass
  Label6.Caption = "Connecting to " & Text1.Text
  DoEvents
  ' If we have not connected or server name has changed,
  ' connect to the server.
  If srv_write Is Nothing Then
    Set srv_write = PISDK.Servers.Item(Text1.Text)
    srv_write.Open
  ElseIf srv_write.Name <> Text1.Text Then
    Set srv_write = PISDK.Servers.Item(Text1.Text)
    srv_write.Open
  End If
  If Check1.Value <> 0 Then nvAtts.Add "questionable", 1
  If Len(Text5.Text) > 0 Then nvAtts.Add "annotations", Text5.Text
  vals.ReadOnly = False
  Set piVal = vals.Add(Text3.Text, Text4.Text, nvAtts)
  vals.ReadOnly = True
  Label6.Caption = "Writing value with " & piVal.ValueAttributes.Count
  DoEvents
  Set ptval = srv_write.PIPoints.Item(Text2.Text)
  Set piErr = ptval.Data.UpdateValues(vals, GetdmMode(Combo1))
  If Not piErr Is Nothing Then
    If piErr.Count > 0 Then
      Err.Description = "Received " & piErr.Count & " error: " & _
        piErr.Item(1).Description
      Err.Raise -1, "UpdateValues", Err.Description
    End If
  End If
  ' Check for valid time range
  If Len(Text11.Text) > 0 Then
  Else
    Dim piTfmt As New PITimeFormat
    ' Need to generate a range
    piTfmt.InputString = Text3.Text
    Text11.Text = CStr(piTfmt.AddIntervals("m", -1))
    Text12.Text = CStr(piTfmt.AddIntervals("m", 1))
  End If
  ' Refill list box.
  Call Command2_Click
       Label6.Caption = "Success"
  Me.MousePointer = vbDefault
  Exit Sub
eMsg:
Me.MousePointer = vbDefault
Label6.Caption = Err.Description
End Sub

 

We have PI-collective by using two servers.

Sometimes this script does not write Values on second server. Buffering is enabled on my pc,

On VB net we can create connection with PI-collective as memberopen and write separately.

But on VBA code do not work. Example if we connect as

 

Set picol = PISDK.Servers("PI")
Set srv = picol.MemberOpen(picolmem, "")
Set srv2 = picol.MemberOpen(picolmem2, "")

 

In a line 28, we see an error and the script stops.

 

How can use UpdateValue method with memberopen connection on VBA?

Outcomes