AnsweredAssumed Answered

How do I obtain the nearest value to a specified timestamp from the PI Data Archive using the PI AF SDK

Question asked by DeepSkyMan on Dec 23, 2019
Latest reply on Dec 24, 2019 by DeepSkyMan

Hi there I have a requirement to return the nearest past value to a specified timestamp for a PIPoint.  How can I do this?

The following function returns the current value for the specified PIPoint:

 

 

    Public Function GetHalfHourPiData() As String
        Dim result As String = ""
        Dim piValues As PIValues = New PIValues
        Dim piValue As PIValue = Nothing

        ' Create the Attribute
        Dim myAttribute As New AFAttribute(_myDB)
        'Compile the collection of PI Data
        'For each point source
        For Each piPointSource In _piPointSources
            ''For each tag in the point source
            For Each piPoint In piPointSource.PointList
                myAttribute.Name = piPoint.Name
                myAttribute.Type = GetType(Double)
                piValue = New PIValue
                piValue.PointName = piPoint.Name
                piValue.Value = piPoint.CurrentValue.ValueAsDouble
                piValues.Add(piValue)
                If piValue.Value > 0 Then
                    Debug.Print(piValue.PointName.ToString)
                End If
            Next
        Next
        'Now generate the JSON package
        result = ToJSON(piValues)
        Return result
    End Function
Logically I need to replace the content in bold with something that allows me to specify the timestamp relevant to the value I am looking for.  I have looked at using the RecordedValue as in:

                afVal.Value = piPoint.RecordedValue(thisTime, AFRetrievalMode.Before)

The variable 'thisTime'  is of type DateTime.  This seems to return an object::
              
    AFValue="7.120267" UOM=Nothing Timestamp={23/12/2019 11:00:01} IsGood=True
    AdditionalInfo: Nothing
    Annotated: False
    Attribute: Nothing
    IsGood: True
    PIPoint: PIPoint '"KMB Testing~TOT~Rhydlydan~132-33kV T1~1T0~MW Imp~DA30"' 91379
    Questionable: False
    Status: Substituted Or Good {216}
    Substituted: True
    Timestamp: {23/12/2019 11:00:01}
    UOM: Nothing
    Value: 7.12026739
    ValueType: {Name = "Single" FullName = "System.Single"}
    ValueTypeCode: Single {13}

whereas I am looking for the discreet floating point value '"7.120267" for the specific PIPoint.  How do I reference the AFValue property itself?
Kind Regards
Paul J..

Outcomes