9 Replies Latest reply on Oct 11, 2011 7:51 AM by michaelh

    Writing to History with PI Ace

    mikeloria

       I recently started embracing PI Ace and found some tremendous advantages in using it. I am a C# programmer so I was using event pipes and OLEDB Provider to accomplish what I needed to do. I recently converted my code over into PI Ace but I am having trouble writing multiple values to an output tag.

       

      Is there a limitation in doing this?

       

      Here is a code snippet:

       
      'get the 10 foot data
      
      '1) Get the tach count at a given footage interval (0,10,20,30)
      
      '2) Determine the time for the tach count based on a tachCounter PIPoint
      
      '3) Write the footage to the PIAcePointAllias point at the given time when the tachcounter is equal to the calculated value
      
       
      
       
      
              Dim ValueToWriteToPI As Integer
      
              Dim CalculationValue As Integer
      
              Dim ValueTimeForEachPiValueIamWriting As PITimeServer.PITime
      
              Dim i As Integer
      
       
      
              ValueToWriteToPI = 0
      
              CalculationValue = 0
      
       
      
              i = 0
      
              While (i < 2000)
      
                      CalculationValue = TachcountConstant + Convert.ToInt32(i * 731.79656)
      
                      ValueTimeForEachPiValueIamWriting = tachCounter.FindEQ("*-2h", "*", CalculationValue)
      
                      PIACEPointAlias.Value(ValueTimeForEachPiValueIamWriting) = ValueToWriteToPI
      
       
      
                  i = i + 10
      
       
      
              End While
      

       

       

      PIACEPointAlias is the alias that I am trying to write to and it is an int32. I am basically calculating a new time based on the time when another PIpoint (tachCounter) is equal to a certain value.

       

       

       

      I also have a question on findEQ. I am assuming that it will interpolate? is that coorect? I tried findGE and findLE but got strange results. What I am doing is using a tach count and converting it to a footage and writing equally spaced fottages into PI for statistical and reporting purposes.

       

       

       

      Thank you so much in advance for your help in this.

        • Re: Writing to History with PI Ace
          mikeloria

           

           

          I just fixed the above code so it is more readable

           

           

            • Re: Writing to History with PI Ace
              mikeloria

              I think I know what I was doing wrong:

               

              I was using PITIME datatype directly in writing to PI:

               

              PIACEPOINT.Value(PITIMEVariable) = 1234

               

              I think it should be PIACEPOINT.Value(PITIMEVariable.localdate) = 1234

               

              I have no running data as the line is shutdown so I am waiting to test this out.

                • Re: Writing to History with PI Ace
                  michaelh

                  Using a PITime object as timestamp should be fine, but you're missing

                   

                     MyACEPoint.PutValue()

                   

                  in the loop.

                   

                  By default ACE only writes output values once, after exiting the Sub AceCalculations.
                  To inhibit this implicit final (duplicate in your case)  .PutValue() you can set

                   

                     MyACEPoint.SendDataToPI = false

                   

                  after your last  .Putvalue()

                    • Re: Writing to History with PI Ace
                      michaelh

                      ... the other question is rather influenced by the definition of your tachcounter tag. But usually it should interpolate.

                       

                      As a hint, use either the good old pipetester.exe utility or the SMT Performance Equations tool, to enter a PE function like

                       

                         findeq('sinusoid','Y', 'T', 50.0)

                      and test evaluate, to see how it works, interactively.

                       

                      PIACE will behave the same with Sinusoid.findeq("Y","T", 50.0)

                        • Re: Writing to History with PI Ace
                          mikeloria

                          The PutValue method was exactly what I was missing, thank you so much

                           

                          I am still getting an error though when I am trying to add 10 milliseconds to the PITime and write a 0 to the PIACEPOINT.

                           

                          'write a 0 value 1 seconds after the produced coil tail end

                          footageTime.LocalDate = footageTime.LocalDate.AddMilliseconds(10)

                          TrimProdTenFootMarkers.Value(footageTime) = 0

                          TrimProdTenFootMarkers.PutValue()

                          TrimProdTenFootMarkers.SendDataToPI =

                           

                          False

                           

                          Is there something wrong with the above code that you can see?

                           

                          Also, one more:

                           

                          For the findEQ method of the PIACEPoint, I would like to use PITIme. Is that possible? I would like to offset the PITime

                           

                          by 1 second just like I am trying to do above. It seemed the only thing that works in the FindEQ method is a time object

                           

                          such as "*-1d" or "*"

                           

                          Thank you so much

                            • Re: Writing to History with PI Ace
                              michaelh

                              Mike Loria

                              I am still getting an error though when I am trying to add 10 milliseconds to the PITime and write a 0 to the PIACEPOINT.

                              footageTime.LocalDate = footageTime.LocalDate.AddMilliseconds(10)
                              TrimProdTenFootMarkers.Value(footageTime) = 0

                               

                              Should be ok, which error do you get ?

                              Mike Loria

                              For the findEQ method of the PIACEPoint, I would like to use PITIme. Is that possible?

                              Sure. The result of FindEQ is a PITime, and the start and endtime parameters can be string, datetime, double or PITime.

                               

                              You can easily supply the result of a FindXX as parameter to another one.

                               

                              You just have to catch the case if there's no matching value to find / interpolate, which throws a "Calculation Failed" exception. 

                               

                               

                                • Re: Writing to History with PI Ace
                                  mikeloria

                                  Say if I have data for a PI tag such as:

                                   

                                  9:20:10          4

                                   

                                  9:21:23        12

                                   

                                  9:21:45        35

                                   

                                  And I want to find the timestamp that best represents when the value was equal to 7. It would be a linear interpolation of the timestamps of when the value was 4 and when the value was 12. What is the best way to do this? In my case, the values are always increasing so i do not have to worry about a senario where the values go from 4 to 12 to 3 to 30 to 1.......   I do though have to take a large samples with the find function. Could be from 0 to 10,000 with 100s of values in between.

                                   

                                  Does FindEQ or some other method do this for PIACEPoints?

                                   

                                  If I cannot get the interpolated timestamp, I am more than happy to take the timestamp that is closest to the value and would be happy with the value always being a little less or equal or great than or equal. Is this what FindGE and FindLE will do? I thought I was getting a timestamp that was way off because it would return the first timestamp of the value found that could be many values away form the search criteria.

                                   

                                   

                                   

                                  Thank You,

                                    • Re: Writing to History with PI Ace
                                      Ahmad Fattahi

                                      Mike,

                                       

                                      The returned PITime object corresponding to the first timestamp, within a specified time range, when an archive value for the point is equal to a specified target value. In case of numeric values it does interpolate existing archive values in searching for the value of interest.

                                       

                                      By the same token FindGE/FindLE find the first time when the value of the tag gets Greater than or Equal/Less than or Equal the specified value. Finding the "closest" value should be implemented and interpreted by the logic in your code.

                                      • Re: Writing to History with PI Ace
                                        michaelh

                                        Mike Loria

                                        Does FindEQ or some other method do this for PIACEPoints?

                                        If I cannot get the interpolated timestamp, I am more than happy to take the timestamp that is closest to the value and would be happy with the value always being a little less or equal or great than or equal

                                         

                                        As Ahmad explained, the first answer is "YES". ( why do you ask ?) 
                                        The goal is that you should not need to care about what is "really" stored in archive or what is compressed out. Ask for any value at any time, PI server would do linear interpolation for you.

                                         

                                        If you'd really need the closest recorded event before a given time, PIACEPOINT.PrevEvent is what you're looking for. 
                                        (PrevVal would give you the value at that time directly.)