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

Connect to PI AF using AFSDK v2 Options · View
RJK Solutions
#1 Posted : Wednesday, November 19, 2008 10:00:11 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Changes to AFSDK v2 meant that some objects previously used are now considered obselete, so code to connect to AF v2 is attached. This example follows on from connecting using AFSDK v.13: Connect using AFSDK v1.3

Add a reference to:

- OSISoft.AFSDK (v2.0.0.0)

Import the Namespace:

Code:
Imports OSIsoft.AF


Create 2 class level variables, note in version 2 the "AFModelFramework" object is obselete, simply use a "PISystem" object as you reference the AFDatabase object from a PISystem.

Code:
Dim AFDB As AFDatabase
Dim PISys As PISystems


Now we can create an example "ConnectToAF" method that accepts 2 parameters, 1 is the PISystem and 2 is the AF Database Name.

Code:
    Private Function ConnectToAF(ByVal WhichPISystem As String, ByVal WhichDatabase As String) As Boolean

        Dim ret As Boolean = False

        Try
            ' Check PISystems object, create if required
            If (PISys Is Nothing) Then PISys = New PISystems

            ' Check AFDatabase object, create if required
            If (AFDB Is Nothing) Then AFDB = PISys(WhichPISystem).Databases(WhichDatabase)
            ' If object already existed, check it is set to correct AF Database
            If Not AFDB.Name.ToLower.Equals(WhichDatabase.ToLower) Then AFDB = PISys(WhichPISystem).Databases(WhichDatabase)

            ' Final checks to see if AF is connected
            ret = (Not (AFDB Is Nothing))
        Catch ex As Exception
            ret = False
        End Try

        Return ret

    End Function


There you have it, you are now connected to AF v2 server.
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.
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.