YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Code in VB.net to display values between time range Options · View
jib2000
#1 Posted : Tuesday, November 11, 2008 1:04:15 AM
Rank: Newbie
Groups: Member

Joined: 11/11/2008
Posts: 4
I need help with writing code in VB.Net to display values of a point starting from when another value equals zero until that value equals zero again. In other words, I am trying to view "batch data" without setting up PIBatch. We have a cycle time counter so when the counter goes to zero, that is the end of the batch. I'd then like to view data such as max, min, etc for various points. If anyone can help, I'd be extremely thankful.
Sponsor  
 

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.
RJK Solutions
#2 Posted : Tuesday, November 11, 2008 9:05:35 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 617
Location: Cheshire, United Kingdom.
Hello jib2000,

So you would like to know the timestamp when the PI tag was 0 (End Time) and then search back in time until a 0 is encountered once again (Start Time)? Those timestamps will then be used for other PI tags to get your data - essentially an Event Frame.

Let me know if this is correct and I will post up an example for you.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
RJK Solutions
#3 Posted : Tuesday, November 11, 2008 9:50:57 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 617
Location: Cheshire, United Kingdom.
Here are 2 example functions that you could use to extract the data:

Code:
    Private Function RetrievePIValues(ByVal PITag As String, ByVal StartTime As String, ByVal EndTime As String) As PISDK.PIValues
        Dim Ret As PISDK.PIValues

        If ConnectToPI() Then
            Dim PIPnt As PISDK.PIPoint = PIServer.PIPoints(PITag)
            Ret = PIPnt.Data.RecordedValues(StartTime, EndTime)
            If Not Ret.Count > 0 Then Throw New Exception("No values retrieved for supplied time.")
        Else
            Throw New Exception("Cannot connect to PI!")
        End If

        Return Ret
    End Function

    Private Function RetrieveSummary(ByVal PITag As String, ByVal StartTime As String, ByVal EndTime As String, ByVal SummType As PISDK.ArchiveSummaryTypeConstants) As PISDK.PIValue
        Dim Ret As PISDK.PIValue

        If ConnectToPI() Then
            Dim PIPnt As PISDK.PIPoint = PIServer.PIPoints(PITag)
            Ret = PIPnt.Data.Summary(StartTime, EndTime, SummType)
            If Not Ret.IsGood Then Throw New Exception("No good value returned for summary.")
        Else
            Throw New Exception("Cannot connect to PI!")
        End If

        Return Ret
    End Function


And examples of how to implement them:

Code:
            Dim PIVals As PISDK.PIValues = Me.RetrievePIValues("sinusoid", "*-7d", "*-5d")
            Dim PIVal As PISDK.PIValue = Me.RetrieveSummary("sinusoid", "*-7d", "*-5d", PISDK.ArchiveSummaryTypeConstants.astAverage)
Principal Consultant
Real-Time Data Management @ Wipro Technologies
RJK Solutions
#4 Posted : Tuesday, November 11, 2008 10:12:17 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 617
Location: Cheshire, United Kingdom.
To find when your PI tag had 0 as a value you would need to use a filter on a date range search to find all archive events when your filter match is true.

So you could do:

Code:
    Private Function RetrievePIValuesWithFilter(ByVal PITag As String, ByVal StartTime As String, ByVal EndTime As String, [b]ByVal Filter As String[/b]) As PISDK.PIValues
        Dim Ret As PISDK.PIValues

        If ConnectToPI() Then
            Dim PIPnt As PISDK.PIPoint = PIServer.PIPoints(PITag)

            Ret = PIPnt.Data.RecordedValues(StartTime, EndTime, PISDK.BoundaryTypeConstants.btAuto, Filter)
            If Not Ret.Count > 0 Then Throw New Exception("No values retrieved for supplied time.")
        Else
            Throw New Exception("Cannot connect to PI!")
        End If

        Return Ret
    End Function


And to implement:

Code:
Dim PIVals As PISDK.PIValues = Me.RetrievePIValuesWithFilter("sinusoid", "*-7d", "*-5d", "'sinusoid'=0")
            For Each PIVal As PISDK.PIValue In PIVals
                Dim TheTime As String = PIVal.TimeStamp.LocalDate.ToString()
            Next


Hope this helps!

Rhys.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
jib2000
#5 Posted : Wednesday, November 12, 2008 10:14:12 PM
Rank: Newbie
Groups: Member

Joined: 11/11/2008
Posts: 4
Thanks. I'll try it out and let you know if it works.
sunflower
#6 Posted : Friday, July 01, 2011 8:10:39 AM
Rank: Newbie
Groups: Member

Joined: 6/28/2011
Posts: 3
Can u give the code to extract data from "PI system" using VB
picoder
#7 Posted : Thursday, August 04, 2011 9:11:34 AM
Rank: Newbie
Groups: Member

Joined: 8/2/2011
Posts: 1
Location: India
Sir, I am new to PI application.
I am developing a system in VB.net where I want to check a condition/expression at current time say TagVal('TagName')<480 and if this condition is true then a messagebox should pop up Message("Condition evaluated to true");
I have tried the codes provided here but Sad
Please Help!!

Thanks in advance
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.