1 Reply Latest reply on Sep 19, 2017 8:02 PM by pmartin

    Writing Multiple Values at Multiple Timestamps with ACE


      I'm fairly new to vb and ACE so forgive any apparent mistakes.


      Background: I have two sets of values that I wish to use to generate an output value. One set is calculated daily, the other set is written to pi only on business days through manual logger, and some days there may be multiple values written for multiple times. Becuase of this, I have not found a way to us AF Analyses to write these values to pi without backfilling manually. So I'm trying to use ACE to do this.


      Question 1: Am I correct that ACE is the only way to write multiple values at multiple timestamps in a single calculation?


      Question 2 (The code): Here is my source code for the ACE calculation (I left out the declarations to minimize the post length). Debug works fine, but Test does produces a calc failed. I'm using some values from af attributes, and other from tags. Ace debug successfully creates two arrays, times and values. At the end of the code I would like it to write each of those time/value sets to PI.


      Imports OSIsoft.PI.ACE
      Imports PITimeServer
      Imports PISDK
      Imports OSIsoft.AF
      Imports OSIsoft.AF.Asset
      Imports OSIsoft.AF.Time
      Public Overrides Sub ACECalculations()
              afservers = New PISystems
              afserver = afservers("PISERVEA")
              db = afserver.Databases("mydatabase")
              E1 = db.Elements("\Element1")
              E2= db.Elements("\Element2")
              A1= E1.Attributes("Attribute1)
              A2= E2.Attributes("Attribute2")
              A3= E2.Attributes("Attribute3")
              E4 = db.Elements("\Element4")
              A4= PTestElement6.Attributes("Attribute4")
              E5= db.Elements("\Element5")
              A5= PTestElement7.Attributes("Attribute5")
              E6= db.Elements("\Element6")
              A6= PTestElement8.Attributes("Attribute6")
              E7= db.Elements("\Element7")
              A7= PTestElement9.Attributes("Attribute7")
              E8 = db.Elements("\Element8")
              A8= PTestElement10.Attributes("Attribute8")
               'Get Current Time
              ctime = DateValue(ptime.UtcTime.ToString)
               Loop through the last eight days
           For i = 0 To 7
                  If i <> 0 Then
                      ctime = ctime.AddDays(-1)
                      ptime = ctime.ToUniversalTime
                  End If
                          'Evaluate each Attribute to get the most current values timestamps
                            T4 = A4.GetValue(ptime).Timestamp.UtcTime.Date
                            T5 = A5.GetValue(ptime).Timestamp.UtcTime.Date
                            T6 = A6.GetValue(ptime).Timestamp.UtcTime.Date
                            T7 = A7.GetValue(ptime).Timestamp.UtcTime.Date
                            T8 = A8.GetValue(ptime).Timestamp.UtcTime.Date
                          'If all of the input tags have a value at the timestamp to be evaluated, then generate the output values and timestamps
                           If T4 = ctime And T5 = ctime And T6 = ctime And T7 = ctime And T8 = ctime Then
                                A1val = A1.GetValue(ptime).Value
                                 'A2 is a formula attribute that sums the values of A4-A8
                                A2val = A2.GetValue(ptime).Value
                                A3val= A3.GetValue(ptime).Value
                                Output(i) = A1* A2/ A3
                                Outputtime(i) = ctime.AddHours(0)
                  End If
      'This is the section I think may be giving me trouble in the ACE test (It works fine in debug)
      'Loop throught the time array and output value array to send each value to PI
              i = 0
      For i = 0 To 7
                  If Output(i) > 0 Then
                      OutpuTag.Value(Outputtime(i)) = Output(i)
                  End If
      OutputTag.SendDataToPI = False
      End Sub



      If you have any follow up questions, please let me know. Thanks

        • Re: Writing Multiple Values at Multiple Timestamps with ACE



          Within the standard OSIsoft products, yes, ACE is the only way to write to multiple Timestamps within the same calculation.  You can also use Analyses (if the one calculation part doesn't matter) or a custom AF SDK application. 


          As for the issue you are seeing, I believe seeing Calc Failed in the Test screen is the normal behavior when using the SendDataToPI = False flag.  See this work item.  Could you try to register it and see if the code performs as expected?