8 Replies Latest reply on Jun 1, 2015 8:40 PM by asorokina

    Any PISDK alternative to TimedValues method to get 'Exact time' values?

    Steve.Buckley

      I was excited to learn I could pass a PIValues collection as my source of timestamps into the TimedValues method, as in

       

      tag2PIValuesCollection = tag2PIPoint.Data.TimedValues(tag1PIValuesCollection).

       

      But then I was disappointed to find that the TimedValues method, unlike its Excel DataLink cousin, does not appear to have a switch to set the search as ExactTime, but rather is always Interpolated?!?

       

      In my use case, I have a dozen or so Lab tags, and need to examine each of them to confirm that it has matching values timestamp-by-timestamp when compared to the 'master tag' of the set i.e. I am looking for extra or missing data points: each tag in the set should have the exact same timestamps over a given range. Because of that, Interpolated will not work.

       

      Have I missed finding the 'switch' to set the TimedValues search to be ExactTime? If not, is there an alternative method to accomplish this short of some kind of point-by-point traversal of all the timestamps after using <tag>.Data.RecordedValues(startTime, endTime) for each tag?

        • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
          dtayler

          HI Steve,

           

          It looks like there is an optional argument you can pass when calling the 'TimedValues' method which forces it to return the actual times of the recorded values rather than the passed times. The bShowDiscreteTimes argument is optional - here's the description:

           

          "If this is set true for discrete points, return the actual times of the recorded values rather than the passed times. Discrete points return values at or before each time requested.[Optional. Default is false]"

           

          This sounds like it might be what you're after. Give it a try and let me know if it helps.

           

          Cheers,

          Dave

          • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
            pthivierge

            Hi Steve,

             

            What Datalink does can definitely be reproduced, either using PI SDK or AF SDK ( the recommended programming approach today).

             

            But I believe before we go with a solution there are more questions that need to be answered if we want a good solution for you.  The more we know the best we can help

            • What is your application language? (C#,VB.net, VBA with Excel?)
            • You have a dozen of tags that you need to compare with a Master tag: Is that all you have?, How many events do you have in each tag for the time period you are looking at?
            • Are you using AF?
            • Do you have a code example of what you have so far?

             

            There are couples ideas I already have in mind such as:

            • Since you dont' have much data, just get recorded values and place them in a dictionary of [timestamp,value], and do the comparison logic yourself
            • use AFAttributes that you configure like this  "\\PIServer\SINUSOID;TimeMethod=ExactTime" to do the comparison ... Requires either Datalink or AFSDK
            • use a FilterExpression with RecordedValues
            • Make several calls with ArcValue with rtCompressed Mode, but you will need to handle the error it returns when there is no value.

             

            Waiting for more details...

              • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
                Eugene Lee

                I like Patrice's first idea. You could use something like Enumerable.Except once you have a list of the Master Tag's timestamps and another list of timestamps of the tag you are trying to compare.

                 

                 

                Enumerable.Except(TSource) Method (IEnumerable(TSource), IEnumerable(TSource)) (System.Linq)

                  • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
                    Steve.Buckley

                    Thanks, David, Patrice and Eugene! I think the dictionary is the route I will need to take.

                     

                    To Patrice's question, I am upgrading some old VB server-side code (pre-AF), and putting it in an ACE container to get the scheduler function and so that users can easily add additional contexts via MDB which the users are familiar with. So the app is written in VB.Net (2012). Each tag would have a maximum of 1500 values to wade through. AF2010 is available; however I need these values written to tags as there are many many existing reports that expect to find the results from these calculations in tags.


                    If I recall correctly, ACE targets .Net 2.0, and the function Eugene suggested requires .Net 3.5, so I will need to change the project properties to target .Net 3.5.

                     

                        '=== Private Methods ===

                        Private Sub GetData(succeeded As Boolean)

                            succeeded = False

                            Try

                                'get the PIValues collection in order of most recent as index 1 to oldest as highest index

                                Data = Tag.Data.RecordedValues(NewestTimestamp.AddSeconds(1), OldestTimestamp.AddSeconds(-1))

                                succeeded = True

                            Catch ex As Exception

                                LogPIACEMessage(MessageLevel.mlErrors,

                                                    "Could not get PIValues for input tag: " & Tag.Name & "; " & ex.Message, ContextHelper.MyBaseName)

                            End Try

                        End Sub

                     

                     

                        Private Sub GetMatchingData(piValsCollection As PIValues, succeeded As Boolean)

                            succeeded = False

                            Try

                                'get the PIValues collection based on timestamps from another PIValues collection

                                Data = Tag.Data.TimedValues(piValsCollection)

                                succeeded = True

                            Catch ex As Exception

                                LogPIACEMessage(MessageLevel.mlErrors,

                                                    "Could not get Timed PIValues for input tag: " & Tag.Name & "; " & ex.Message, ContextHelper.MyBaseName)

                            End Try

                        End Sub

                     

                    Trying to avoid hijacking my own thread, perhaps these two Q's should be separate posts:

                    • AF does not have the equivalent of an ACE scheduler, correct?
                    • Is there a button on the editor to enable inserting code snippets? Couldn't get [Code] [/Code] to work...
                      • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
                        Eugene Lee

                        The closest thing to an ACE scheduler for AF would be Asset-based Analytics.

                         

                        https://livelibrary.osisoft.com/LiveLibrary/content/en/PIServer2014-v1/GUID-97E879EB-7F25-4F44-B552-B607851058F5

                         

                        For code snippets, you have to use the advanced editor and then click on ">>" -> Syntax Highlighting and choose your language like such. We have also feedback the lack of VB before in the list of languages.

                         

                           '=== Private Methods ===
                            Private Sub GetData(succeeded As Boolean)
                                succeeded = False
                                Try
                                    'get the PIValues collection in order of most recent as index 1 to oldest as highest index
                                    Data = Tag.Data.RecordedValues(NewestTimestamp.AddSeconds(1), OldestTimestamp.AddSeconds(-1))
                                    succeeded = True
                                Catch ex As Exception
                                    LogPIACEMessage(MessageLevel.mlErrors,
                                                        "Could not get PIValues for input tag: " & Tag.Name & "; " & ex.Message, ContextHelper.MyBaseName)
                                End Try
                            End Sub
                        
                        
                            Private Sub GetMatchingData(piValsCollection As PIValues, succeeded As Boolean)
                                succeeded = False
                                Try
                                    'get the PIValues collection based on timestamps from another PIValues collection
                                    Data = Tag.Data.TimedValues(piValsCollection)
                                    succeeded = True
                                Catch ex As Exception
                                    LogPIACEMessage(MessageLevel.mlErrors,
                                                        "Could not get Timed PIValues for input tag: " & Tag.Name & "; " & ex.Message, ContextHelper.MyBaseName)
                                End Try
                            End Sub
                        
                        • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
                          pthivierge

                          Hi Steve,

                           

                          .Net 2.0 is the minimal framework version required for PI Ace, you can use 3.5 version.

                          See PI Ace release note here.

                           

                          Just let us know in case you need more help.

                           

                          Regards,.

                    • Re: Any PISDK alternative to TimedValues method to get 'Exact time' values?
                      asorokina

                      Hi Steve,

                       

                      We'd like to follow up on this thread. Please let us know if you have further questions about the topic, and if not, could you mark one of posts above as Correct?