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

Back to basics: Get Snapshot and Archive values Options · View
RJK Solutions
#1 Posted : Wednesday, August 06, 2008 2:16:27 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
So following on from the reusable function "ConnectToPI":
http://www.rjksolutionsl...nect-to-PI-routine.aspx

We will take a look at retrieving a value for the PI Point "SINUSOID" from the snapshot and the archive.

Previously we had the following code that we are going to expand:

Quote:
If ConnectToPI Then
' Perform activities here...
Else
' Handle bad connection...
End If


What we need to do is the following:
- Create a PI Point variable and assign the point "SINUSOID"
- Retrieve a snapshot PIValue and assign to a PISDK.PIValue variable
- Retrieve an archive PIValue and assign to a PISDK.PIValue variable
- Finally we will retrieve the "descriptor" PointAttribute value for "SINUSOID"

As we will be retrieving the timestamp associated with values, we will need to add a reference to the PI TimeServer Type Library.

Your code may look something like the following:
Quote:

Sub ReadSinusoid()

If ConnectToPI Then
Dim PITag As PISDK.PIPoint
Set PITag = PIServer.PIPoints("SINUSOID")

' Retrieve the current value (Snapshot) and timestamp
' Assign Value to PISDK.PIValue variable
Dim PITagVal As PISDK.PIValue
Set PITagVal = PITag.Data.Snapshot

' Write the value out to Immediate window
Debug.Print PITagVal.TimeStamp.LocalDate & " " & PITagVal.Value

' Retireve value from 1 day ago and write out to Immediate window
Set PITagVal = PITag.Data.ArcValue("*-1d", rtAuto)
Debug.Print PITagVal.TimeStamp.LocalDate & " " & PITagVal.Value

' Retire a PI tag Point Attribute, in this case the descriptor
Debug.Print PITag.PointAttributes("descriptor").Value

Set PITagVal = Nothing
Set PITag = Nothing
Else
' Handle bad connection...
End If

End Sub


Hopefully you can start to see how you can quickly and easily you can expand upon this to create your own specific applications.
As our series of "Back to basic" continues, feel free to let us know of any specific walk throughs that you want to see.

Principal Consultant
Real-Time Data Management @ Wipro Technologies
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 : Wednesday, September 03, 2008 10:55:33 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.

As part of our C# update, here is a simple data retrieval using PISDK and C#.

Code:
private void ReadSinusoid()
        {
            if (ConnectToPI())
            {
                PISDK.PIPoint PITag = PIServer.PIPoints["SINUSOID"];
                PISDK.PIValue PITagValue = PITag.Data.Snapshot;

                String SomeOutput = PITagValue.TimeStamp.LocalDate + " " + PITagValue.Value.ToString();

                PITagValue = PITag.Data.ArcValue("*", PISDK.RetrievalTypeConstants.rtAuto, null);

                SomeOutput = PITagValue.TimeStamp.LocalDate + " " + PITagValue.Value.ToString();

                String SomeAttribute = PITag.PointAttributes["descriptor"].Value.ToString();
            }
            else
            {

            }
        }

Principal Consultant
Real-Time Data Management @ Wipro Technologies
Dean
#3 Posted : Monday, February 22, 2010 4:51:35 AM
Rank: Newbie
Groups: Member

Joined: 2/22/2010
Posts: 1
Location: uk
Thanks for your series of walk throughs. A problem I'm trying to solve is how to retrieve a time stamp from a PI data series when something changes state.
For an example if a simple light switch is being recorded in PI what would be the easiest and quickest way of finding out when the light switch last changed state? I can go through the list of values and compare one with the next and flag up the transition but I was wondering if there is a slicker way of doing it? My particular problem would actually involve two switches in that I want to know when both tags go high or low.
Thanks in anticipation. Please keep up the excellent back to basic walk throughs It actually makes sense to me now (well some of it does)
RJK Solutions
#4 Posted : Tuesday, February 23, 2010 10:43:14 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Hi Dean, Welcome to the forum.

Unfortunately, all the methods for doing this like the "PISDK.IPICalculation.FirstTrue" method have not been implemented in the current version of PISDK. So OSI have thought about and put the empty method there so they can introduce in the future.

You could use the PISDK.IPICalculation.Calculate method to check when the values of the Digital tags are both "On".

Code:

Dim Calc As PISDK.IPICalculation = Server ' Server is a PISDK.Server object
Dim PIVals As PISDK.PIValues = Calc.Calculate("*", "*-1d", "('Switch1' = ""High"" And 'Switch2'=""High"")", stRecordedValues, "")


But you will still need to check for when the value is 1 (aka True) and the first occurence would be the timestamp you want. Alternatively, you could use a sample interval to find when it was true.

Principal Consultant
Real-Time Data Management @ Wipro Technologies
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.