AnsweredAssumed Answered

[Help] Send string values to PI using datalink

Question asked by victor.valdez on Dec 6, 2016
Latest reply on Dec 7, 2016 by victor.valdez

Hi all,

 

I've been able to send integer values to PI using datalink without any issue.  The issue now is when i want to send string values to PI.  I already changed  the point-type of my tag (float 32 to string) but still PI server rejects the values.  I include the program below as well as the screenshot of the issue.

 

Sub input_data_Alarm()

   Dim i As Integer

   Dim B As String

   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

   B = Worksheets("Alarm_SVTP").Cells(i + 4, 26)

   'numoftags = 1000   'count number of tags'

   'server is in E8

   sServer = Worksheets("Alarm_SVTP").Cells(2, 5).Text

   While B > 0

      'resultCell is in column 5 (E)

      Set resultCell = Worksheets("Alarm_SVTP").Cells(i + 4, 5)

      'valueCell is in column 4 (D)

      Set valueCell = Worksheets("Alarm_SVTP").Cells(i + 4, 4)

      'tagname is in column 3 (C)

      sTagname = Worksheets("Alarm_SVTP").Cells(i + 4, 3).Text

      'timestamp is in column 2 (B)

      stime = Worksheets("Alarm_SVTP").Cells(i + 4, 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

      B = Worksheets("Alarm_SVTP").Cells(i + 4, 26)

     

   Wend

  

 

   i = 0

   B = Worksheets("Alarm_SVTP").Cells(i + 4, 26)

   While B > 0

      rowstr = Format(i + 4)

      buf = "Alarm_SVTP!H" & rowstr

      Range(buf).Select

      buf = "=PIExTimeVal($C$" & rowstr & ",$B" & rowstr & ",""" & sServer & """)"

      Selection.FormulaArray = buf

      i = i + 1

      B = Worksheets("Alarm_SVTP").Cells(i + 4, 26)

   Wend

   Range("H4").Select

 

End Sub

 

Capture.PNG

Outcomes