10 Replies Latest reply on Feb 27, 2015 8:58 PM by dng

    How can I limit the number of values returned for RecordedValues?

    PSS_SD

      I've been converting from PI-API to PI-SDK. And I'm already on the part of getting values from PI.

       

      One of the PI-API methods to be converted is piar_compvalues. By using this method, you can specify the start, end and count of the values to be returned. I can see that there are 3 variations for RecordedValues: RecordedValues, RecordedValuesByCount and RecordedValuesAvailable.

       

      RecordedValues - You can specify Start and End date.

      RecordedValuesByCount - You can specify Start date and count.

      RecordedValuesAvailable - not very familiar with.

       

      With these three, I don't see any method which I can specify the Start and End date together with the count of max values to get.

       

      Is there any way to possibly get the behavior that I was expecting?

       

      Btw, I'm writing using c++.

       

      Thank you in advance!

        • Re: How can I limit the number of values returned for RecordedValues?
          dng

          Hi Eli,

           

          The recorded values methods in PI SDK do not expose the count parameter. Your observation is correct; you cannot specify the start and end time as well as the the maximum number of values to be returned. With that said, if you are developing a new application, we encourage you to use PI AF SDK instead of PI SDK. PI AF SDK (.NET) offers significant functional and performance improvement over PI SDK (COM). An equivalent AF SDK function to return a list of compressed values for a requested time range would be AFData.RecordedValues method in the OSIsoft.AF.Data Namespace. The count parameter is exposed in this method, which means you can specify the maximum number of return values on top of start and end time.

           

          Since PI AF SDK is a .NET library, one way is to create a wrapper to the .NET code in C++/CLI. You can check out some online resources, as well as this previous discussion: AN SDK C++.

          1 of 1 people found this helpful
            • Re: How can I limit the number of values returned for RecordedValues?
              PSS_SD

              Thanks for the quick response Daphne! But is there any way to achieve this behavior instead of switching to AF SDK and creating a wrapper?

               

              Any manual calculation will be fine with me, I think this will be much simpler than creating a wrapper for AF SDK. Correct me if I'm wrong .

                • Re: How can I limit the number of values returned for RecordedValues?
                  dng

                  Hi Eli,

                   

                  There are many advantages of using the PI AF SDK, and new enhancements will be added to PI AF SDK but not PI SDK (check out this previous post). If this is a start to many subsequent projects, I encourage you to start looking into switching to AF SDK because this will be useful in the long run.

                   

                  Regarding your question of getting the number of values by specifying start and end time as well as maximum count, what is your main concern? Are you trying to avoid getting too many values when specifying a time range? If your main concern is the number of counts, use the RecordedValuesByCount method to specify the start time and count. If your main concern is server load, you can use RecordedValuesByCount to specify the start time and count. Then check the timestamp for the last PIValues. If it is earlier than the end time needed, use RecordedValues to get the remaining values.

                    • Re: How can I limit the number of values returned for RecordedValues?
                      PSS_SD

                      Hi Daphne,

                       

                      I already started with the wrapper and I'm almost done. This is not a new project. I'm just updating an old c++ code(using PI-API). This is because we encountered numerous bugs that cause app crash. OSISoft recommended to use PISDK because it has support for multi-threading.

                       

                      Btw, I also need the PlotValues method for its Interval but unfortunately it doesn't have a count parameter. Any workaround for this?

                       

                      Thank you!

                        • Re: How can I limit the number of values returned for RecordedValues?
                          dng

                          Hi Eli,

                           

                          In the PlotValues method, you can specify the number of intervals to plot over. This method is designed to return a set of values over a time period that will produce the most accurate plot while minimizing the amount of data returned. For each interval, the data available is examined and significant values are returned. Each interval can produce up to 5 values if they are unique, the first value in the interval, the last value, the highest value, the lowest value and at most one exceptional point (bad status or digital state). Since the number of data points is optimized to generate the most accurate plot, we do not have a count parameter included in the method.

                           

                          In the "worst case" scenario, you will have (5 * number of intervals) values returned to your PlotValues call. You can therefore indirectly influence the number of values returned through the number of intervals parameter. Will that work for your application? If not, can you let me know what is the main reason for specifying a count parameter?

                  • Re: How can I limit the number of values returned for RecordedValues?
                    pthivierge

                    Hi Eli,

                     

                    I agree with Daphne and if you are creating a new application you should really use AF SDK.

                     

                    If you really can't, as a workaround, you could use the Summary method ( pipoint.Data.Summary(...) , astCount)

                    This will allow you to get the count of your values and possibly take further actions.


                    I am wondering why you need to get recorded values limited by count and a time range at the same time?

                    Could you use interpolated values instead?


                    We will do our best to help you, the more details we have the best solution we can find.

                      • Re: How can I limit the number of values returned for RecordedValues?
                        PSS_SD

                        Hi Patrice,

                         

                        I already did what Daphne suggested, to switch to AF-SDK and create a wrapper. I need to use methods that can limit the returned values with specified start and end dates because I use these values for populating charts.

                         

                        I'm almost done with the wrapper but have encountered another road block. PlotValues doesn't have the count parameter. Any other method or workaround for this? I need a method with Interval, start/end time and count that retrieves raw values.

                         

                        Thank you!

                          • Re: How can I limit the number of values returned for RecordedValues?
                            pthivierge

                            Hi Eli,

                             

                            As  Daphne Ng pointed out the method PlotValues an "intervals" parameter.

                             

                            public AFValues PlotValues(
                            AFTimeRange timeRange,
                            int intervals
                            )
                            
                            
                            
                            

                             

                            From AFSDK documentation (%PIHOME%\Help\AFSDK.chm):

                            The number of intervals to plot over. Typically, this would be the number of horizontal pixels in the trend.

                            For each interval, the data available is examined and significant values are returned. Each interval can produce up to 5 values if they are unique, the first value in the interval, the last value, the highest value, the lowest value and at most one exceptional point (bad status or digital state).

                            The PI Server imposes a limit on the maximum number of events that can be returned with a single call. By default this is set at 150,000. This behavior can be changed on the server by editing the server's PITimeout table and adding or editing the value associated with the parameter ArcMaxCollect.

                             

                            Intervals parameter then acts exactly as a fixed count of values, but it is more intelligent then simply give a single count parameter.

                            The maximum number of values you will get with the PlotValues call is: MaxValueCount=5*intervals.

                             

                            I hope this helps.

                        • Re: How can I limit the number of values returned for RecordedValues?
                          PSS_SD

                          Thank you Daphne Ng and Patrice Thivierge for your replies.

                           

                          I'm almost done with my wrapper and what's left is just how to handle AFPoints status. Is there any way to map the old status from PI-API to the new AFVAlueStatus? I can see that AFValueStatus enum is way lesser than the original API(can be seen in PISTATUS.H).

                           

                          Also the status of 0 in the SDK indicates that the point is BAD and in the API it indicates GOOD which is very odd.

                           

                          You two has always been helpful. Thank you very much!

                            • Re: How can I limit the number of values returned for RecordedValues?
                              dng

                              Hi Eli,

                               

                              The PISTATUS.H file enumerates the PI API error code, which is specific to PI API only. The idea is that instead of error codes, we can use symbolic names in the PI API code. On the other hand, the AFValueStatus Enumeration defines the possible status property for an AFValue retrieved. E.g. if you are retrieving an AF attribute with a PI Point data reference, you can determine whether the tag is good, substituted, bad, etc. from the status property. Since they are designed for different purposes, there is no one-to-one correlation between them, nor can they be mapped to each other.

                               

                              Regarding the status value between PI API and PI AF SDK, I am not too sure about the original design decision. My guess is that the PI API status of 0 indicates that no error during the operation, while AF SDK uses a different set of operation to determine whether an AF value is good or not. In PI AF SDK, the AFValueStatus enumeration is designed with bit-wise operation in mind, if you look at the bad, questionable, and good values in bits:
                                   bad:                  0000 0000

                                   questionable:     0100 0000
                                   good:                1100 0000

                              the quality of the AFValue can be easily determined using the quality mask of 1100 0000.

                               

                              If you are concerned about error handling in AF SDK, you can take a look at the exception information in the AF SDK reference guide.

                               

                              I hope that answers your original question. Let us know if you need more information!