11 Replies Latest reply on Jul 11, 2017 7:40 AM by VarbanVarbanov

    retrieve future data from attribute with af sdk

    VarbanVarbanov

      Hi, probably an easy question, but i couldnt find an answer after some research. I have an attribute , referencing a PI Point with future data. I try to retrieve the value in the future using this method (using AF Sdk 2016): https://techsupport.osisoft.com/Documentation/PI-AF-SDK/html/M_OSIsoft_AF_Data_AFListData_InterpolatedValue.htm I receive "No Data" both when I try exact date when I have value in PI and also a date after the moment when I have latest value. I would excpect that the value will be returned in both cases. Can anyone tell me what is the problem and how to retrieve future data from pi point referencing attribute. Thank you in advance!

        • Re: retrieve future data from attribute with af sdk
          rsun

          Hi Varban,

          If you are getting the AFValue from an attribute, you should use AFData_InterpolatedValue method instead of AFListData_InterpolatedValue method. Here is the detail https://techsupport.osisoft.com/Documentation/PI-AF-SDK/html/M_OSIsoft_AF_Data_AFData_InterpolatedValue.htm

          The other question I have is do you get "No Data" when looking at data in the past?

          Thanks,

          Ricky

          • Re: retrieve future data from attribute with af sdk
            VarbanVarbanov

            Hi Ricky, thanks for your suggestion, but i don't see why this should be different (at least from the perspective of AF Sdk user). In my case I have list of attributes, so am using the method i mentioned. However I changed it with your suggestion and still got same result:

             

            return attsList.Data.InterpolatedValue(time);

             

            replaced with:

             

             

            var valuesList = new List<AFValue>();

            foreach (var att in attsList)

            {

                        var value = att.Data.InterpolatedValue(time, null);

                        valuesList.Add(value);

              }
            return valuesList

             

            (Sorry for the quotes cannot find the mark as C# option in the editor)

             

            Regarding your question - yes I succesfully retrieve the values which are in the past. I'm including a screen shot from PI SMT.

             

            ForOsiSoft.png

             

            So I'm succesfully retrieving the 32 value, but cannot get the 55 value (tried with both dates and relative strings)

              • Re: retrieve future data from attribute with af sdk
                Rick Davin

                Hi Varban,

                 

                You said you are on PI AF 2016 (2.8.0).  What version of PI Data Archive are you using?

                 

                For your code snippet of attsList.Data.InterpolatedValue(time);, what are the times you are passing?

                 

                In your example where 55 was not retrieved, what happened?  Was an exception thrown, or did you receive an AFValue of some digital state?  What was the timestamp of the AFValue? (Okay, I see your original post says a "No Data" is returned.  I still want to know the timestamps coming back.)

                 

                With AF 2.8.0, there are methods RecordedValueAtTimes and InterpolatedValueAtTimes available for PIPoint, AFAttribute.Data (AFData), PIPointList, and AFAttributeList.Data (AFListData).  For optimal performance, PI Data Archive 2016 (3.4.400 or greater) is required.

                 

                Have you tried using the PIPoint directly?  Such as att.PIPoint.InterpolatedValue?

                 

                Are you using element versions?

                 

                If the future PIPoint stepped?  What is the data type of your future tag?

                 

                The concept of "latest value" is not so clear cut with future tags.  That's why Snapshot became obsolete to be replaced with CurrentValue.  Have you tried using other methods such as PIPoint.EndOfStream?  How about an RDA call such as

                 

                    att.PIPoint.RecordedValue(AFTime.Now, AFRetrievalMode.After)

                 

                If it's not obvious from some of my questions, I'm trying to see if there are differences between the AFAttribute related calls versus PIPoint, as well as RecordedValue versus InterpolatedValue.

                 

                Finally, to format lines of code on PISquare, you were so close with Quotes.   Using Advanced Editor, click on >> on the tool bar, then Syntax Highlighting, and finally C#.

                1 of 1 people found this helpful
              • Re: retrieve future data from attribute with af sdk
                VarbanVarbanov

                Hi Rick, thank you very much for your questions. Hope we will get to the solution soon. Please, see the answers to each question below:

                 

                You said you are on PI AF 2016 (2.8.0).  What version of PI Data Archive are you using?

                 

                The Archive is version 2015 - 3.4.395.80

                 

                For your code snippet of attsList.Data.InterpolatedValue(time);, what are the times you are passing?

                 

                I tried with several possible times, exact time - 6/30/2018, time after this time passed as Data Time and relative time, e.g *+10000h

                 

                In your example where 55 was not retrieved, what happened?  Was an exception thrown, or did you receive an AFValue of some digital state?  What was the timestamp of the AFValue? (Okay, I see your original post says a "No Data" is returned.  I still want to know the timestamps coming back.)

                 

                As you say, I receive AFValue object with value of 'No Data' which is enumeration value from Enumeration Set 'System'. The date is as requested, for example +10000h returns:  {8/28/2018 6:53:44 AM}

                 

                With AF 2.8.0, there are methods RecordedValueAtTimes and InterpolatedValueAtTimes available for PIPoint, AFAttribute.Data (AFData), PIPointList, and AFAttributeList.Data (AFListData).  For optimal performance, PI Data Archive 2016 (3.4.400 or greater) is required.

                 

                Same result with :


                att.Data.InterpolatedValuesAtTimes(new List<AFTime>() {time}, null, null, true);

                 

                Have you tried using the PIPoint directly?  Such as att.PIPoint.InterpolatedValue?

                 

                Same result with:

                att.PIPoint.InterpolatedValue(time);
                And besides, i would prefer to not use PiPoint since the attribute may not have PiPoint reference, but have Analysis or static value, etc. Of course this could be checked, but generally this functionality should work equally for all kind of attributes and for future and real time data time series if referenced.

                 

                 

                Are you using element versions?

                 

                No, i don't (elements of course has version but i do not change the versions or use them explicitly in any way).

                 

                If the future PIPoint stepped?  What is the data type of your future tag?

                 

                Type is float 32. Yes it is step. I changed it to Off , but same result.

                 

                The concept of "latest value" is not so clear cut with future tags.  That's why Snapshot became obsolete to be replaced with CurrentValue.  Have you tried using other methods such as PIPoint.EndOfStream?  How about an RDA call such as

                  att.PIPoint.RecordedValue(AFTime.Now, AFRetrievalMode.After)

                 

                Both methods you mention work and return 55 value. However this is not the functionality I want.

                 

                Finally, to format lines of code on PISquare, you were so close with Quotes.   Using Advanced Editor, click on >> on the tool bar, then Syntax Highlighting, and finally C#.

                 

                I have used often the Syntax Highting, however i think it is not present currently (cannot see >> and the only arrow displays languages only). I have only one editor option. Don't know if the problem is that I'm replying and not posting, updated web site, browser, something else or I just cannot see it, but this is the result i have:

                 

                ToolBar.png

                1 of 1 people found this helpful
                  • Re: retrieve future data from attribute with af sdk
                    Rick Davin

                    For syntax highlighting:

                     

                    2017-07-07 08_23_06-retrieve future data from attribute with af sdk _ PI Square.png

                    • Re: retrieve future data from attribute with af sdk
                      Rick Davin

                      Hi Varban,

                       

                      I cannot reproduce your problem.  Note however that I am using PI AF Client 2017 SP1 (AF 2.9.1) and PI Data Archive 2016 R2.

                       

                      If your PIPoint is stepped, the AFValue.Value returned will not actually be interpolated.  It will grab the AFValue at or before the requested time, and assign the requested time as the "interpolated" Timestamp.

                       

                      I created a future tag and entered 3 values in the data archive.  I ran this code:

                       

                      public void TestFuture(string dataArchiveName, string tagName)
                      {
                          var tag = GetFutureTag(dataArchiveName, tagName);
                          var att = new AFAttribute(tag);
                          UOM uom = null;
                      
                          var startTime = tag.RecordedValue(AFTime.MinValue, AFRetrievalMode.After).Timestamp;
                          var endTime = tag.EndOfStream().Timestamp;
                      
                          Console.WriteLine("PIPoint Recorded Values");
                          var arcValues = tag.RecordedValues(new AFTimeRange(startTime, endTime), AFBoundaryType.Inside, null, true, 0);
                          foreach (var pv in arcValues)
                          {
                              Console.WriteLine("  {0} {1}", pv.Timestamp.LocalTime, pv.Value);
                          }
                      
                          var times = new Dictionary<AFTime, string>();
                          times.Add(DateTime.UtcNow, "Now");
                          times.Add(DateTime.Today.AddMonths(-1), "Last Month");
                          times.Add(DateTime.Today.AddDays(-1), "Yesterday");
                          times.Add(DateTime.Today, "Today");
                          times.Add(DateTime.Today.AddDays(1), "Tomorrow");
                          times.Add(DateTime.Today.AddMonths(1), "Next Month");
                          times.Add(DateTime.Today.AddMonths(6), "In 6 Months");
                          times.Add(DateTime.Today.AddYears(1), "Next Year");
                          times.Add(endTime.LocalTime.Date, "Last Day");
                          if (endTime.LocalTime.Date != endTime.LocalTime)
                              times.Add(endTime, "Last Time");
                      
                          Console.WriteLine();
                          Console.WriteLine("Attribute Interpolated Values");
                          Console.WriteLine();
                          foreach (var time in times)
                          {
                              var pv = att.Data.InterpolatedValue(time.Key, uom);
                              Console.WriteLine("{0} {1}", time.Value, time.Key > endTime ? "(PAST END OF STREAM)" : "");
                              Console.WriteLine("  {0} {1}", pv.Timestamp.LocalTime, pv.Value);
                          }
                      }
                      

                       

                       

                      Keep in mind that this code could mess up everybody if the PIPoint has lots of values.  Since I knew my tag had 3 recorded values, it was safe for me to run.

                       

                      Console Output

                      PIPoint Recorded Values

                        6/1/2017 10:07:19 AM 27

                        7/6/2017 9:53:57 AM 32

                        7/1/2018 4:38:12 PM 55

                       

                      Attribute Interpolated Values

                       

                      Now

                        7/7/2017 9:06:06 AM 32.06172

                      Last Month

                        6/7/2017 12:00:00 AM 27.7971

                      Yesterday

                        7/6/2017 12:00:00 AM 31.94106

                      Today

                        7/7/2017 12:00:00 AM 32.03751

                      Tomorrow

                        7/8/2017 12:00:00 AM 32.10135

                      Next Month

                        8/7/2017 12:00:00 AM 34.01652

                      In 6 Months

                        1/7/2018 12:00:00 AM 43.78656

                      Next Year (PAST END OF STREAM)

                        7/7/2018 12:00:00 AM No Data

                      Last Day

                        7/1/2018 12:00:00 AM 54.95575

                      Last Time

                        7/1/2018 4:38:12 PM 55

                       

                       

                      I don't know if your issues are because of the PI Data Archive version.  Is it feasible for you to upgrade?  If not, then a last gasp effort would be to at least reboot the machine hosting the data archive.  In my olden days as customer, if my code was producing absolutely baffling results that should not be occurring, a reboot sometimes cured the problem.  Not always but enough to cause such a reboot once every couple of years.

                      1 of 1 people found this helpful
                    • Re: retrieve future data from attribute with af sdk
                      VarbanVarbanov

                      Hi Rick, thank you very much for your efforts to reproduce the issue.
                      I doubt restart will help, because the issue were originally found on other environment than the one I'm testing.
                      Yes, you are right about the interpolation (even further - in the example we are talking about, the result should be the same regardless of interpolated or not, because we are asking for value at or after the lates recorded). However in my case the same code shoud work with both step and no step time series and give the according results (latest recorded or interpolated), so not using interpolated values is not an option.

                       

                      I'll try with upgrade, but in the meantime if anyone can explain this behaviur it will be much appreciated.

                       

                      Regarding the editor - here is how it looks on my screen, regardless of if i chose reply to original question or reply to you - use "advanced editor" is not present. I would suspect some browser incopatability (using Chrome):

                       

                      Rick.png

                      • Re: retrieve future data from attribute with af sdk
                        Rick Davin

                        Hi Varban,

                         

                        I would direct you to:  Future Data Link

                         

                        Approximately halfway down the page is the heading Querying for Future Data.  Look at the last paragraph in that section.

                         

                        There are differences in data retrieval behavior between historical PI tags and PI tags that support future data (this applies to both PIPoints and AFAttributes backed by PIPoints). In particular, interpolation queries and “Auto” retrieval mode (which is the default configuration of the PI Point Data Reference) will return a NoData event for historical tags if queried at a timestamp past the end-of-stream and in the future, whereas future tags will return a NoData event for any query after the end-of-stream event, regardless if it is in the past or future. RecordedValues and PlotValues calls to historical tags generate a NoData event at current time when a time range extends into the future, whereas future tags will not.

                         

                        Allow me to highlight the relevant phrase:

                         

                        whereas future tags will return a NoData event for any query after the end-of-stream event, regardless if it is in the past or future.

                         

                         

                        I have mentioned in a reply earlier today that your usage of new AFTime("*+10000h") will be over 1 month past your EndOfStream.  According to the documentation, a NoData event will be returned.

                        1 of 1 people found this helpful
                        • Re: retrieve future data from attribute with af sdk
                          VarbanVarbanov

                          Hi Rick, thank you very much, this explains the bahavior (and it is not the DST bug, although good to know).