AnsweredAssumed Answered

PiPutVal Not Finding Tags

Question asked by tgschneider on Sep 23, 2019

I'm trying to write a series of tags using the PiPutVal code. I've copy pasted the code from the OSISoft supplied template, and only updated the sheet names and cell references. Below is the code I am using. When I run the macro, the result I get is "Tag not found" and the readback is "Attribute not found". I have already uploaded to one of the tags, successfully, using the exact template provided. I am also able to find the tags through the Datalink search, and running a CurrentValue query on all the tags yields a "Pt Created" result, and an ArchiveValue query reads "No Data", so the tags definitely exist, and there are no security issues that would prevent me (piadmin) from uploading data. I've tried both the IP address and the server name for the server, with no difference.

 

Any thoughts on what might be my issue? I've created and run several upload macros in the past without any issue.

 

'This subroutine is called by the <Send above values> button on the
'left hand side of the "PutVal" worksheet
Sub put_data1()
Dim i As Integer
Dim numoftags As Integer

'The following four variables are arguments to PIPutVal()
Dim sTagname As String 'Tagname
Dim stime As String 'Timestamp
Dim sServer As String 'PI server name
Dim valueCell As Range 'Cell reference containing value to be written
Dim resultCell As Range 'Cell reference to hold result
Dim apierr As Long
Dim rowstr As String
Dim buf As String

Dim macroResult As Variant
Dim timeCell As Range 'Cell reference to hold time of putval

i = 0
numoftags = 110 'we have three tags, from cell B4 to B6
'server is in E8
sServer = Worksheets("PutVal").Cells(8, 5).Text
While i < numoftags
'resultCell is in column 5 (E)
Set resultCell = Worksheets("PutVal").Cells(i + 9, 5)
'valueCell is in column 4 (D)
Set valueCell = Worksheets("PutVal").Cells(i + 9, 4)
'tagname is in column 3 (C)
sTagname = Worksheets("PutVal").Cells(i + 9, 3).Text
'timestamp is in column 2 (B)
stime = Worksheets("PutVal").Cells(i + 9, 2).Text

'Call the PIPutVal() macro function
'Note that we pass just a , for the PIServer argument; i.e., we
'are using the default PIServer
macroResult = Application.Run("PIPutVal", sTagname, valueCell, stime, sServer, resultCell)
'move down to the row number
i = i + 1
Wend

i = 0
While i < numoftags
rowstr = Format(i + 9)
buf = "F" & rowstr
Range(buf).Select
buf = "=PIArcVal($C$" & rowstr & ",$B$" & rowstr & ",0,""" & sServer & """,""exact time"")"
Selection.FormulaArray = buf
i = i + 1
Wend
End Sub

'This subroutine is called by the <Send above values> button on the
'bottom half of the "PutVal" worksheet to send to PI 3
Sub put_data2()
Dim i As Integer
Dim numoftags As Integer

'The following four variables are arguments to PIPutVal()
Dim sTagname As String 'Tagname
Dim stime As String 'Timestamp
Dim valueCell As Range 'Cell reference containing value to be written
Dim resultCell As Range 'Cell reference to hold result
Dim sServer3 As String 'PI3 server name
Dim apierr As Long
Dim rowstr As String
Dim buf As String
Dim Timeval As Double

Dim macroResult As Variant
Dim timeCell As Range 'Cell reference to hold time of putval

i = 0
numoftags = 38 'we have three tags, from cell C14 to C19

'timestamp is in row 14, column 2 (cell B14)
If (IsNumeric(Worksheets("PutVal").Cells(14, 2))) Then
Timeval = Worksheets("PutVal").Cells(14, 2).Value
stime = Format(Timeval)
Else
stime = Worksheets("PutVal").Cells(14, 2).Text
End If

'server is in E21
sServer3 = Worksheets("PutVal").Cells(58, 5).Text
i = 0
While i < numoftags
'resultCell is in column 5 (E)
Set resultCell = Worksheets("PutVal").Cells(i + 14, 5)
'valueCell is in column 4 (D)
Set valueCell = Worksheets("PutVal").Cells(i + 14, 4)
'tagname is in column 3 (C)
sTagname = Worksheets("PutVal").Cells(i + 14, 3).Text
'use the timestamp entered by user
stime = Worksheets("PutVal").Cells(14, 2).Text

'Call the PIPutVal() macro function
'Note that we pass just a , for the PIServer argument; i.e., we
'are using the default PIServer
macroResult = Application.Run("PIPutValx", sTagname, valueCell, stime, sServer3, resultCell)
'move down to the row number
i = i + 1
Wend

' read back from server
Sleep (10)
i = 0
While i < numoftags
rowstr = Format(i + 14)
buf = "G" & rowstr
Range(buf).Select
buf = "=PIArcVal($C$" & rowstr & ",$B$14" & ",0,""" & sServer3 & """,""exact time"")"
Selection.FormulaArray = buf
i = i + 1
Wend
End Sub

 

Results:

 

Outcomes