2 Replies Latest reply on Mar 26, 2018 3:57 AM by dmoler

    Need to find latest event when tag value is equal to True.

    AnimeshK

      HI All,

       

      I am writing a .net code using AF SDK, and want to fetch tag value and time stamp.

      I need timestamp of a latest "True" value in a PiPoint.

        • Re: Need to find latest event when tag value is equal to True.
          Eugene Lee

          Hi Animesh,

           

          You can do it like this.

           

          var afvals = AFCalculation.CalculateAtTimes(myPIServer, "FindEq('stringtest','*','y-24mo',\"True\")", new List<AFTime> { new AFTime("*") } );
          Console.WriteLine(DateTime.Parse( afvals[0].Value.ToString()).ToLocalTime());
          

           

          myPIServer is your PIServer variable. Substitute 'stringtest' for the name of your tag.

           

          Data:

          Results:

          • Re: Need to find latest event when tag value is equal to True.
            dmoler

            Hi Animesh,

             

            Another option for answering this query is to use RecordedValuesByCount with a filter expression. In your case it would be something like:
                 AFValues lastTrueValue = piPoint.RecordedValuesByCount(startTime: new AFTime("*"), count: 1, forward: false, boundaryType: AFBoundaryType.Inside, filterExpression: "'.'=\"True\"", includeFilteredValues: false);

             

            What this means is: Find 1 value searching backwards from now where the value is "True" (a '.' in a filter expression refers to the tag being filtered), don't include any extra value at or after now and don't include markers for filtered values.

            1 of 1 people found this helpful