5 Replies Latest reply on Nov 12, 2015 7:26 PM by Arti Rajagopalan

    Reset tag value to zero at noon using ACE

    Arti Rajagopalan

      Hi,

       

        I'm working on an ACE calculation that does a time-weighted average of total discharge over a period of 24 hours. The calculation period is from 12:00 PM today to 11.59 AM tomm . The calculation should reset the PI tag value to zero at noon every day. How do I accomplish this? My current logic doesn't seem to work for all time stamps:

       

      Dim startTime As PITime = Noon(Me.ExeTime)

      Dim startTimeUTC As AFTime = New AFTime(startTime.UTCSeconds)

       

      If (lastCalculationTime.UtcSeconds >= startTimeUTC ) Then  'Check if lastCalculationTime in UTC is less than UTC second at noon

                      lastCalculationTime = startTimeUTC

                      lastCalculatedValue = 0.0

                  End If

       

      Any assistance is truly appreciated.

       

      Thanks,

      Arti

        • Re: Reset tag value to zero at noon using ACE
          Asle Frantzen

          A quick 'n dirty trick: Your ACE output tag can be a Performance Equation tag.

           

          If you create a time scheduled PE tag where the expression is 0.0 and the scan class is 00:00:00 you will have it reset to 0 from the PE scheduler, and you don't have to define this within the bounds of your ACE project.

           

           

          If you don't want to do that, I'd have to ask if your ACE calculation is time scheduled or naturally schedule (triggered from one or more PI tags)?

          1 of 1 people found this helpful
          • Re: Reset tag value to zero at noon using ACE
            Arti Rajagopalan

            This piece of code works for me:

             

            Dim lastArchiveTime As AFTime = Nothing

            lastArchiveTime = New AFTime(discharge.PrevEvent)

             

            Dim snapshotTime As AFTime = hesElement.Attributes("discharge").Attributes("value").GetValue.Timestamp

            Dim startTime As PITime = Noon(Me.ExeTime)

            Dim afStartTime As AFTime = New AFTime(startTime.UTCSeconds) 'current day noon timestamp in UTC

             

            Try

                            If DaySec(lastArchiveTime) < 43200 And DaySec(snapshotTime) > 43200 Then

                                lastCalculatedValue = 0.0

                                lastCalculatedValueDQ = ""

                                afDischargeTotal = New AFValue(lastCalculatedValue, afStartTime)

                                afDischargeTotalDQ = New AFValue(dischargeTotalForPeriodDQ, afStartTime)

                                hesElement.Attributes("dischargeTotal").Attributes("value").SetValue(afDischargeTotal)

                                hesElement.Attributes("dischargeTotal").Attributes("qualityCode").SetValue(afDischargeTotalDQ)

                                PIACEBIFunctions.LogPIACEMessage(OSIsoft.PI.ACE.MessageLevel.mlErrors, "***[6] Have executed the code for noon reset  " & dischargeTotalForPeriod.ToString & " : ", Context)

                            End If

                            Catch ex As Exception

                            PIACEBIFunctions.LogPIACEMessage(OSIsoft.PI.ACE.MessageLevel.mlErrors, "***[6] Error with noon reset code " & calcTime.ToString & " : ", Context)

                        End Try