Rank: Member Groups: Member
Joined: 5/24/2009 Posts: 11 Location: Wisconsin, USA
|
I am attempting to return the most recent time that a tag reached a certain value. To be specific, I have a tag that is 1 when a piece of equipment is loaded and 0 when it is unloaded and I want to pull in the last time it was 0 into Excel. I am able to do this with one problem: the server I am pulling from is in a different time zone and the return time stamp is coming back in client time.
I did some investigating and see there is a ServerTime method for the Server object but I am not sure how to use it. I tried adding it after connecting to the server but that did not work. Anyone know how to return timestamps in Server time rather than Client time?
|
|
|
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: Advanced Member Groups: Member
Joined: 12/3/2009 Posts: 71 Location: Germany/Pennsylvania
|
Can you provide the code snippet for the non-working TimeServer method?
Michael
|
Rank: Member Groups: Member
Joined: 5/24/2009 Posts: 11 Location: Wisconsin, USA
|
Sorry for the delay in replying...travel and vacation have kept me away. My code is below. As I said, I have no idea how to use the ServerTime Method so I tried calling it on my server object, but I am still getting the result in my time zone (client time) rather than the server's time zone (which is different by 1 hr). Code: Option Explicit Public bDebug_Mode As Boolean
Function DrBladeLife(sTagName As String, sStartTime As String, sEndTime As String) Dim PIVals As PISDK.PIValues Dim PIVal As PISDK.PIValue Dim sFilterExp As String bDebug_Mode = True ' Connect to sPIServer If Not modConnection.bConnectToPI("servername") Then Err.Raise 9999, , "Unable to connect to server" End If oPIServer.ServerTime 'oPIServer is a Public variable declared in a separate module containing the connection code sFilterExp = "'" & sTagName & "'=0" Set PIVals = RetrievePIValuesWithFilter(sTagName, sStartTime, sEndTime, sFilterExp) DrBladeLife = (CDate(sEndTime) - PIVals(PIVals.Count).TimeStamp.LocalDate) * 24 End Function
Private Function RetrievePIValuesWithFilter(ByVal PITag As String, ByVal StartTime As String, ByVal EndTime As String, ByVal Filter As String) As PISDK.PIValues Const csPROCNAME As String = "RetrivePIValuesWithFilter" Dim sErrMsg As String Dim Ret As PISDK.PIValues Dim PIPnt As PISDK.PIPoint On Error GoTo ErrorHandler Set PIPnt = oPIServer.PIPoints(PITag) Set Ret = PIPnt.Data.RecordedValues(StartTime, EndTime, PISDK.BoundaryTypeConstants.btOutside, Filter, fvRemoveFiltered) ExitPoint: On Error GoTo 0 ' Put things back the way they were ' Set objects to Nothing, quit applications, etc. (garbage collection) Set RetrievePIValuesWithFilter = Ret
Exit Function
ErrorHandler: ' Diplay error message; if not in debug mode go to ExitPoint, otherwise, debug. sErrMsg = Err.Number & ": " & Err.Description MsgBox Prompt:="Unexpected error occurred in:" & csPROCNAME & Chr(10) & sErrMsg, _ Buttons:=vbOKOnly + vbExclamation
If bDebug_Mode Then bDebug_Mode = False Stop Resume Else Resume ExitPoint End If End Function
|