13 Replies Latest reply on Jan 25, 2015 6:58 AM by eloi1976

    Get timestamp tag and use it as starttime/endtime in batchview

    eloi1976

      We use batchview to compare the present batch with the golden batch. Each batch is divided into phases (heating, reaction,cooling,...) and I want to use the tag of these phases to define the starttime and endtime so that I can compare the present phase with the phase of the golden batch. I probably have to use VBA, but can't find a method to get a timestamp like FindEQ in excel

       

      Any ideas?

        • Re: Get timestamp tag and use it as starttime/endtime in batchview
          ashaw

          Hi Jeroen,

           

          I've moved your post to the PI Developers Club space because it looks like your question may be better addressed by community members here.

          It sounds like you ultimately want to be able to use performance equations in a PISDK setting. For starters you may want to look at the IPICalculation Interface in the PISDK.  This allows you to pass "expressions" like PEs in pisdk applications.

           

          The PISDK help reference can be found in C:\Program Files (x86)\PIPC\help\pisdk.chm

          If you search for IPICalc there are several examples that might help you get started.

          • Re: Get timestamp tag and use it as starttime/endtime in batchview
            dng

            Hi Jeroen,

             

            To get archived values for a PI tag, you can use the PI SDK methods PIPoint.Data to get the PIData object, and then use PIData.RecordedValues to obtain a PIValues Collection. Each PIValue in the PIValues Collection contains the TimeStamp property which returns a PITime object representing the timestamp of the archived value. You might also be interested in checking out this post: PI SDK Getting List of Timestamps for a particualar period

             

            What kinds of comparison between the present batch and golden batch are you trying to achieve? If the use case is known, we will be able to give more suggestions! Thanks!

              • Re: Get timestamp tag and use it as starttime/endtime in batchview
                gregor

                Hello Jeroen,

                 

                I've checked your user profile and it looks to me as if you would not be able to respond as long as your question would live in PI Developers Club space. Hence I've moved it back to where you've posted it originally.

                 

                Also I believe that what you are trying to do is standard functionality with PI Batch and you don't need to write a single line of code.

                 

                The Active Tag defines a batches sub-batches start and end. PI BatchView allows to select an existing batch as Golden Batch and to overlay other batches to compare process data against the process data of the Golden Batch. There exist learning videos at OSIsoft Youtube learning channel e.g. Batch analysis techniques using the PI BatchView add-in to ProcessBook. v3.1.2. I am not sure if this video covers using Golden Batches but expect one of the PI Batch related videos does. Can you please see if the functionality that you are looking for is already built into the standard. If it is not, please provide us additional information what exactly you would like to achieve and we will try to guide you. 

              • Re: Get timestamp tag and use it as starttime/endtime in batchview
                FranzK

                Hi Jeroen,

                 

                if you want to compare subbatches inside PI Batchview, you can use Align and Zoom. Go to Batch definition (doubleclick on Batch-View Plug). In Settings Tab you can choose Plot Time - Relative - Align and Zoom and with configure Button you can zoom in your prefered Subbatch.

                 

                If you want to use the time informations in another display e.g. to configure a standardtrend, you can use the choosen subbatch in the result window of Batch view as follows:

                If Results.SelectedItem.BatchItemType = pibvSubBatch Then

                            ' if you selected an subbatch - continue to define subbatch object

                            Dim subbatch As PISubBatch

                            Set subbatch = Results.SelectedItem.BatchItem

                                ' Open Display which gets the subbatch informations

                                Set myDisplay = Application.Displays.Open("\\PIServer1\Displays\Prozess\BatchView_Fermentationtime.pdi", True) '

                                ' transfer subbatch information to target display (Batch-View_Fermentationtime.pdi

                             Call myDisplay.InitDisplay(subbatch)

                            End If

                        End If

                 

                In the target Display you can use the following code to use the subbatch information:

                 

                Public Sub InitDisplay(pSubBatch As PISubBatch)

                   

                    On Error GoTo ErrorHandler

                   

                    ' transfer subbatch

                    Set subbatch = pSubBatch

                   

                   ' use Batch-Time Informations e.g. in an Text Box

                    TextBoxStartTime.text = subbatch.StartTime.LocalDate

                    If subbatch.EndTime Is Nothing Then

                        TextBoxEndTime.text = "subbatch still running"

                    Else

                        TextBoxEndTime.text = subbatch.EndTime.LocalDate

                    End If

                 

                   

                    ' show Batch-ID

                    TextBatchID.Contents = AsPIUnitBatch(subbatch.Parent).BatchID

                   

                    Exit Sub

                   

                ErrorHandler:

                    Call ErrorAction

                   

                End Sub

                 

                If you need the Subbatch Time informations in another object e.g. in an trend-object, you can use it also, but you have to keep in mind you use a symbol:

                    Dim StartTrend

                    Dim EndTrend

                 

                StartTrend = subbatch.StartTime.LocalDate

                EndTime = subbatch.EndTime.LocalDate

                thisDisplay.Symbols("Trend1").SetTimeRange StartTrend, EndTrend

                1 of 1 people found this helpful
                • Re: Get timestamp tag and use it as starttime/endtime in batchview
                  eloi1976

                  Thanks for all the answers! I've already looked at the option of using the batch gantt and the subbatches because that was exactly what I needed.(I didn't know that it existed until last week, everything I know about PI is by reading the help reference and searching the forum, sort of DIY ) But unfortunately it doesn't work, I can't expand to subbatches (menu has a light grey color). Is it our version of PI (3.2.0.0) or is it the way our batches are build  up , I dont know.

                  To be clear in what I want to achieve: we have a display with a batch trend and 6 command buttons (one for each unit). If you click on the button you get the batch trend (temp, pressure and weight) of the unit and the golden batch (with the same tags). I want to create an additional trend that shows the same tags as the batch trend (current batch of the unit and golden batch) but with the start and endtime of the phase/subbatch.

                  I'm now going to look at IPICalculation. I will post again when I have more results.

                  • Re: Get timestamp tag and use it as starttime/endtime in batchview
                    eloi1976

                    I've tried  2 different approaches:

                    First I've  created a 'FindEQ'-dataset with vba and it worked perfect. But when I try to read the value, to use it in my code, it comes up empty, I've searched the forum and it seems that it is impossible to read timestamps using  the GetValue-method.

                    Next I used the IPICalculation  and after a few tries I got a result, but not what I hoped for. The timestamp is in UTCseconds and I don't know how to use it to create trends. Another problem is that I can't dim an object as PITime (user-defined type not defined)

                     

                    Thanks in advance,

                     

                    Jeroen

                    • Re: Get timestamp tag and use it as starttime/endtime in batchview
                      eloi1976

                      Below you can find my code,  I succeeded in getting a timestamp. But instead of getting the start of when the tag meets a certain condition, I get the start of the batch (pStart in my code). When I use the filter as a dataset, it shows the right timestamp.

                       

                      Private Sub testTime(ByVal pStart As String, pEnd As String, pUnit As String)

                       

                      Dim MyTag As String

                      Dim str As String

                      Dim filter As String

                      Dim svr As Server

                      Dim ipiCalc As IPICalculation

                      Dim val As pivalues

                      Dim TagStart As Date

                       

                      MyTag = "RS:" & pUnit & "_OPERATION.PV"

                       

                      str = phasenr.GetValue(vrDate, vrStatus)

                       

                           'I have used both filters and they gave the same result

                      filter = "FindEq('" & MyTag & "','" & pStart & "','" & pEnd & "'," & str & ")"

                           'filter = "'" & MyTag & "' = " & str

                       

                      Set svr = PISDK.Servers.DefaultServer

                       

                      Set ipiCalc = svr

                       

                      Set val = ipiCalc.Calculate(pStart, pEnd, filter, stRecordedValues, "")

                       

                      TagStart = val(1).TimeStamp.LocalDate

                      TagStart = Format(TagStart, "dd-mm-yy hh:mm:ss ")

                       

                      End Sub

                        • Re: Get timestamp tag and use it as starttime/endtime in batchview
                          dng

                          Hi Jeroen,

                           

                          Based on what you are trying to accomplish, perhaps you would like to use the PIData.RecordedValues method. E.g.

                           

                              myTag = "BA:Active.1"
                              str = "Active"
                            
                              Set svr = PISDK.Servers("DNG-PI2012")
                              filter = "'" & myTag & "' = """ & str & """"
                                
                              Set ipiCalc = svr
                              Set val = svr.PIPoints(myTag).data.RecordedValues(pStart, pEnd, btInside, filter, fvRemoveFiltered)
                            
                              TagStart = val(1).TimeStamp.LocalDate
                          
                          

                           

                          Note that my tag is a digital tag. You might have to alter the filter string if your tag is a numeric tag. Hope it helps! Let us know how it goes!

                        • Re: Get timestamp tag and use it as starttime/endtime in batchview
                          eloi1976

                          Thanks Daphne,

                           

                          I tried your code but it always failed. So I did a count of "val"  and it came up 0. I tried to alter the filter but the count stayed  0. In the end I deleted the filter and put it after the PIData.RecordedValues method. Like this:

                           

                          Set val = pt.Data.RecordedValues(pStart, pEnd, btInside)

                              cnt = val.Count

                          If cnt = 0 Then

                              Exit Sub

                          End If

                          ReDim testTimes(1 To cnt) As Double

                          For l = 1 To cnt

                              If val(l).Value = str Then

                                  Exit For

                              End If

                          Next l

                             

                          TagStart = val(l).TimeStamp.LocalDate

                           

                          If l = cnt Then

                              TagEnd = pEnd

                              Else: l = l + 1

                                  TagEnd = val(l).TimeStamp.LocalDate

                          End If

                           

                          And it worked! I already tried to use the settimerange method to change the batchtrend but then the time mode changes to absolute and I want it to stay relative. I'm going  to try to paste two trends together to get what I want but getting the timestamps was (hopefully) the hardest part.