Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 409 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:
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. OSIsoft PI System SpecialistsPI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!
|