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.
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!
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.
1 of 1 people found this helpful
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
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"
TextBoxEndTime.text = subbatch.EndTime.LocalDate
' show Batch-ID
TextBatchID.Contents = AsPIUnitBatch(subbatch.Parent).BatchID
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:
StartTrend = subbatch.StartTime.LocalDate
EndTime = subbatch.EndTime.LocalDate
thisDisplay.Symbols("Trend1").SetTimeRange StartTrend, EndTrend
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 (22.214.171.124) 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.
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,
did you add a reference to the PITimeServer assembly in your project? only if you add the reference you can use a PITime Object.
As an additional resource, you might want to check out an example in the PI BatchView Programming Help (PIPC\HELP\PIBatchViewProgramming.chm). Please select "Search" and look for the "Complete Example".
Regarding your issue with not being able to read timestamps with the GetValue method, have you considered getting the timestamps from the PISubBatch object itself?
If you could post your code snippet below, perhaps we can all help troubleshoot!
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 ")
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!
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
ReDim testTimes(1 To cnt) As Double
For l = 1 To cnt
If val(l).Value = str Then
TagStart = val(l).TimeStamp.LocalDate
If l = cnt Then
TagEnd = pEnd
Else: l = l + 1
TagEnd = val(l).TimeStamp.LocalDate
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.
I wonder why the filter did not work for you. Depending on how many values are usually filtered out, including a filter might be more efficient for the application because the entire collection of values do not need to be pushed to the client (filtering is done on the server side). Make sure the filter has the following syntax:
'Tag' = "string" (you'll need double quotes around the string)
Like you mentioned in your first post, I had to change the filter string. dim str as long, delete a couple of double quotes and now the filter works great.