|
|
Rank: Member Groups: Member
Joined: 1/19/2010 Posts: 11 Location: Baton Rouge
|
I'm looking for a way to have PI Processbook find a min/max value of a point in PI (say a temperature probe) for the past 24 hours from current time. I'm aware of how to do this with PI Datalink in Excel, but is there a way to have this done so in can be displayed and kept updated on a Processbook Display? I alsor want this feature for some real-time calculations.
I've been looking through the VBA Object Browser and have not found anything built in to do this calculation.
I appreciate any help, Thank You
|
|
|
|
|
OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System. We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ or contact OSIsoft vCampus for more details.
|
|
|
Rank: Member Groups: Member
Joined: 1/19/2010 Posts: 11 Location: Baton Rouge
|
You know, I've spent a good portion of yesterday looking for this feature and within 10 minutes of signing up here and posting this question I discovered PI Calculations within Processbook.
Now, the next thing I'm looking for is a way to send PI Calculation a start and stop time, via VBA, and have it give me the Max or Min Value during that interval. This is the real question I am wanting a solution to. I'm wanting to stick it in an if...then statement, and, depending on some factors, find the max or min value of a point and return the value to me for calculations, where the results will be displayed in Processbook.
Now that I have posted that question I'll hopefully find the answer in 10 minutes.
|
|
|
Rank: Advanced Member Groups: Member
Joined: 12/3/2009 Posts: 71 Location: Germany/Pennsylvania
|
Congratulations! (discovering the datasets)
In fact there is more then one solution.
Before I start just one question: Are you familiar with PIPerfomanceEquations?
They can solve a lot of such problems without the use of VBA.
Do you need different start/end times then those you have on the display/trend(s) etc?
You can manipulate the datasets using VBA (but not start/end time directly) but I would prefer the use of PI-SDK. Are you used to the SDK?
If yes then you can use either Summaries or Summary Method (PIData object) if you have a single tag or ExpressionSummaries Method (IPICalculation interface) if you need to run a real perfomance equation. else have a look around here in the forum or let us know. endif
Michael
|
|
|
Rank: Member Groups: Member
Joined: 1/19/2010 Posts: 11 Location: Baton Rouge
|
Michael,
I have not done much work in PI and my VBA is not too strong, I mainly use it in Excel, but I'm trying to learn more.
I know absolutely nothing about the PIPerformanceEquations or PI-SDK.
Thinking about in, all I really need for what I'm wanting to do is have the current value of the tag (know how to do), the max value within the last 24 hours, and the value of the tag 24 hours ago (not quite got this one). But, learning how to pull max values within a specified time range and returning me those values would be nice and of future value.
I'm currently building these displays for my personal performance monitoring use before I share them, meaning I want to keep all changes on my computer and not have to change anything on the server.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Hello and welcome to the forum! Right, Michael raises some very good points. PI Datasets are great for seeing these summary values in real time and to react to changes in the displays time. If you need to do some more "custom" summary values then this is where VBA and PISDK comes in. In your case, seen as though it is mainly for personal development at the moment, you can experient to get what you need. Then it would be ideal to get some of the calculations in as Performance Equations...but that can come later. I just knocked up a little routine for you to get you started. You need a reference to the "PISDK 1.3 Type Library" and add the servers & points you need and you have your Maximum, Minimum etc. Code: Sub test()
Dim vValue As Variant vValue = GetSummary(PISDK.Servers("localhost").PIPoints("sinusoid"), "*-24h", "*", astMaximum)
If IsNumeric(vValue) Then Debug.Print vValue Else
End If
End Sub
Private Function GetSummary(ByVal PITag As PISDK.PIPoint, ByVal StartTime As String, ByVal EndTime As String, ByVal SummaryType As PISDK.ArchiveSummaryTypeConstants) As Variant
On Error GoTo GetSummary_Error
Dim Ret As Double: Ret = 0#
Dim TagValue As PISDK.PIValue Set TagValue = PITag.Data.Summary(StartTime, EndTime, SummaryType) If TagValue.IsGood Then Ret = TagValue.Value Else Dim DigState As PISDK.DigitalState Set DigState = TagValue.Value Ret = DigState.Name Set DigState = Nothing End If Set TagValue = Nothing
GetSummary = Ret
Exit Function GetSummary_Error: GetSummary = "#Err" Err.Raise "Error in Getsummary (" & Err.Number & ") " & Err.Description
End Function
If you need to go a step further and perform an Expression Summary (as Michael points out above) then let us know. Cheers, Rhys. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Member Groups: Member
Joined: 1/19/2010 Posts: 11 Location: Baton Rouge
|
Thank You for the help. When I have some time available, hopefully today, I'll play around with that code in my display.
|
|
|
Rank: Member Groups: Member
Joined: 1/19/2010 Posts: 11 Location: Baton Rouge
|
RJK Solutions,
I had some time and tried your code this afternoon. It is most excellent. Thank You.
I've found the help files for PI-SDK so hopefully I'll be able to learn some more about what objects it offers, though it usually takes me some time to figure out how to use them.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Hey Big, Yeah I remember the days when I read each page of the PISDK help files...I was a proper geek (still am I think!?!?)! In all honesty was probably best thing I did coupled with endless need for PISDK coding in projects. Now I just look for the new features OSI roll out in PISDK. Glad the code worked out for what you need, just post back if you need any further help/examples. Cheers, Rhys. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 2/28/2010 Posts: 9 Location: UK
|
I hope I'm not going to say something stupid now but how does the value of Ret get passed back to the vValue ? I'm still learning about VBA and PI (and probably always will be) and I thought you would always have to reference the name of the function to pass back the value. Thus Getsummary= Ret should be in the code somewhere ? If this is a mistake then please don't take my question as me trying to be smart, I'm not I'm just keen to try and understand new things.
|
|
|
Rank: Newbie Groups: Member
Joined: 2/28/2010 Posts: 9 Location: UK
|
Also if I wanted to return the time this min or max took place. Would I simply put in a somethign = TagValue.timestamp ? again how would I then get the timestamp passed back to the calling routine? Would I have to convert the Function in to a sub and pass it back as a variable in the header ?
|
|
|
Rank: Newbie Groups: Member
Joined: 2/28/2010 Posts: 9 Location: UK
|
I've typed the code in to functions (at first) and then Subs in VBa in Excel and it works very well, thanks and much faster than I thought it would for a few days of data. I do have another question now though. I'm using the code to find a Minimum of a valve between two dates (I changed AstMaximum to AstMinimum and it appeared to work). The correct min value gets spat out and displays properly on my spread sheet but the timestamp shows as a load of ######## in the relative cell. I've formatted the cell to show DD/MMM/YYYY HH:MM:SS but it wont show it and I'm thinking that maybe the returned numerical value for the timestamp seems too high to simply be a serial value of the date. The returned date value is 1266278400 and in real terms should be something like 16/02/2010 23:59 = 40226 . Any suggestions please ?
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
Hi Perfo, Firstly, you were correct. I had a typo in the function, which I have now altered. "GetSummary = Ret". For your last post, the time returned is a PI time. You will need to use the ".LocalDate" method to convert to a local date object. Cheers, Rhys. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 2/28/2010 Posts: 9 Location: UK
|
Thanks for the reply. I supose trying to learn more about VBA (particularly for PI) at the same time probably isn't the best option but then it's the only option I've got. Others maybe interested in my little project and I'm certainly keen for anyone to make suggestions or comments do you thik it would be worth me starting a new thread ?
Thanks again.
|
|
|
Rank: Newbie Groups: Member
Joined: 2/28/2010 Posts: 9 Location: UK
|
Needless to say the LocalDate thing worked perfect Thanks. I will have to try and find a list of all the objects I can use with PI, is there a book or something ? I'll start a thread on my little project but as I'm a newbie I don't want to break protocol and upset anyone so please feel free to delete it if I post in the wrong place or something.
|
|
|
Rank: Member Groups: Member
Joined: 1/19/2010 Posts: 11 Location: Baton Rouge
|
Perfo wrote:Needless to say the LocalDate thing worked perfect Thanks. I will have to try and find a list of all the objects I can use with PI, is there a book or something ? I'll start a thread on my little project but as I'm a newbie I don't want to break protocol and upset anyone so please feel free to delete it if I post in the wrong place or something. I'm in the same boat, just trying to learn all the objects available in PI. There is a good VBA helpfile for Processbook, as well as one for PI SDK. I get to the PI SDK help file through the "About PI-SDK". Another way is through the VBA Editor. Once a referenced is created to a project the objects from the library will show in the Object Browser. In the VBA Editor in the Help menu there should be access to the VBA help file for Processbook as well. Hope I wasn't too confusing.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 612 Location: Cheshire, United Kingdom.
|
There are numerous documents to read to get a good base of understanding for both ProcessBook/VBA and PISDK (see your "..\PIPC\Help\" directory). I would then highly recommend moving on to AF and the AFSDK & ANSDK. Depending on your company allowances, you might also want to consider signing up to OSISoft's vCampus - talk to the developers that create the SDK's and tools! Just remember to tell them I sent you if you sign up Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
|
Guest
|